Skip to content

Commit

Permalink
fix(common): remove PlatformBuilder.addComponents() method which isn'…
Browse files Browse the repository at this point in the history
…t used method

BREAKING CHANGE: remove PlatformBuilder.addComponents() method which isn't used method
  • Loading branch information
Romakita committed Sep 8, 2024
1 parent b905d78 commit 5cd2e3c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 40 deletions.
14 changes: 0 additions & 14 deletions packages/platform/common/src/builder/PlatformBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,6 @@ describe("PlatformBuilder", () => {
expect(server.injector.get(Token)).toBeInstanceOf(Token);
});
});
describe("addComponents", () => {
it("should add components", async () => {
// GIVEN
const server = await PlatformCustom.bootstrap(ServerModule, {});

class MyClass {}

// WHEN
server.addComponents(MyClass);

// THEN
expect(server.injector.settings.get("imports")).toEqual([HealthModule, MyClass]);
});
});
describe("addControllers", () => {
it("should add controllers", async () => {
// GIVEN
Expand Down
12 changes: 1 addition & 11 deletions packages/platform/common/src/builder/PlatformBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ export class PlatformBuilder<App = TsED.Application> {
return !this.disableBootstrapLog && this.logger.info(...data, this.diff());
}

/**
* Add classes to the components list
* @param classes
*/
public addComponents(classes: Type | Type[]) {
this.settings.set("imports", this.settings.get<any[]>("imports", []).concat(classes));

return this;
}

/**
* Add classes decorated by @@Controller@@ to components container.
*
Expand All @@ -172,7 +162,7 @@ export class PlatformBuilder<App = TsED.Application> {
* @param {any[]} controllers
*/
public addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]) {
[].concat(controllers).forEach((token) => {
[].concat(controllers as never[]).forEach((token: TokenProvider) => {
this.settings.routes.push({token, route: endpoint});
});
}
Expand Down
10 changes: 5 additions & 5 deletions packages/platform/common/src/utils/createHttpServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ describe("createHttpServer", () => {

expect(listener).toBeInstanceOf(Function);

const server = injector.get(Http.Server);
const server = injector.get(Http.Server)!;

vi.spyOn(injector.logger, "info").mockReturnValue(undefined);
vi.spyOn(injector.logger, "debug").mockReturnValue(undefined);
vi.spyOn(server, "listen").mockReturnValue(undefined);
vi.spyOn(server, "address").mockReturnValue({port: 8089, address: "0.0.0.0"});
vi.spyOn(server, "on").mockImplementation((event: string, cb: any) => {
vi.spyOn(server, "listen").mockReturnValue(undefined as never);
vi.spyOn(server, "address").mockReturnValue({port: 8089, address: "0.0.0.0"} as never);
vi.spyOn(server, "on").mockImplementation(((event: string, cb: any) => {
if (event === "listening") {
cb();
}
});
}) as never);

await listener();

Expand Down
10 changes: 5 additions & 5 deletions packages/platform/common/src/utils/createHttpsServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ describe("createHttpsServer", () => {
expect(!!injector.get(Https.Server)).toEqual(true);
expect(listener).toBeInstanceOf(Function);

const server = injector.get(Https.Server);
const server = injector.get(Https.Server)!;

vi.spyOn(injector.logger, "info").mockReturnValue(undefined);
vi.spyOn(injector.logger, "debug").mockReturnValue(undefined);
vi.spyOn(server, "listen").mockReturnValue(undefined);
vi.spyOn(server, "address").mockReturnValue({port: 8089, address: "0.0.0.0"});
vi.spyOn(server, "on").mockImplementation((event: string, cb: any) => {
vi.spyOn(server, "listen").mockReturnValue(undefined as never);
vi.spyOn(server, "address").mockReturnValue({port: 8089, address: "0.0.0.0"} as never);
vi.spyOn(server, "on").mockImplementation(((event: string, cb: any) => {
if (event === "listening") {
cb();
}
});
}) as never);

await listener();

Expand Down
10 changes: 5 additions & 5 deletions packages/platform/common/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export default defineConfig(
coverage: {
...presets.test.coverage,
thresholds: {
statements: 97.04,
branches: 90.76,
functions: 94.91,
lines: 97.04
statements: 97.03,
branches: 90.74,
functions: 94.89,
lines: 97.03
}
}
}
}
);
);

0 comments on commit 5cd2e3c

Please sign in to comment.