UNPKG

@tsed/platform-test-sdk

Version:
48 lines (47 loc) 1.64 kB
import { __decorate, __metadata } from "tslib"; import { Controller } from "@tsed/di"; import { PlatformTest } from "@tsed/platform-http/testing"; import { Get } from "@tsed/schema"; import SuperTest from "supertest"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { FeatureModule } from "../modules/feature/FeatureModule.js"; let TestRootCtrl = class TestRootCtrl { testScenario1() { return "From root"; } }; __decorate([ Get("/"), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], TestRootCtrl.prototype, "testScenario1", null); TestRootCtrl = __decorate([ Controller("/root") ], TestRootCtrl); export function testModule(options) { let request; beforeAll(PlatformTest.bootstrap(options.server, { ...options, mount: { "/rest": [TestRootCtrl] }, imports: [FeatureModule] })); beforeAll(() => { request = SuperTest(PlatformTest.callback()); }); afterAll(PlatformTest.reset); describe("Scenario1: GET /rest/root", () => { it("should get content from root controller", async () => { const response = await request.get("/rest/root").expect(200); expect(response.text).toEqual("From root"); }); }); describe("Scenario2: GET /rest/features", () => { it("should get content from a module with his controller", async () => { const response = await request.get("/rest/features").expect(200); expect(response.text).toEqual("From feature"); }); }); }