Skip to content

Commit

Permalink
fix(platform-express): Fix hook called twice when using platform-expr…
Browse files Browse the repository at this point in the history
…ess builder
  • Loading branch information
Travis committed Apr 27, 2020
1 parent e1b8b2c commit 7ca0ade
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
@@ -1,4 +1,4 @@
import {constructorOf, Type} from "@tsed/core";
import {classOf, constructorOf, Type} from "@tsed/core";
import {IDIConfigurationOptions, InjectorService} from "@tsed/di";
import {IRoute, Platform, PlatformApplication} from "../../platform";
import {ContextMiddleware} from "../middlewares/ContextMiddleware";
Expand Down Expand Up @@ -204,5 +204,8 @@ export abstract class PlatformBuilder {
this._rootModule = this.injector.invoke(module, undefined, {
imports: this.settings.imports
});

this.injector.delete(constructorOf(this._rootModule));
this.injector.delete(classOf(this._rootModule));
}
}
32 changes: 32 additions & 0 deletions packages/platform-express/test/server.spec.ts
@@ -0,0 +1,32 @@
import {Configuration} from "@tsed/di";
import {PlatformExpress} from "@tsed/platform-express";
import * as Sinon from "sinon";
import { nameOf } from '@tsed/core/src';

@Configuration({
logger: {
level: "off"
}
})
class Server {
$beforeRoutesInit() {

}
}

const sandbox = Sinon.createSandbox();
describe("bootstrap", () => {
beforeEach(() => {
sandbox.stub(Server.prototype, "$beforeRoutesInit");
});
afterEach(() => {
sandbox.restore();
});
it("should call once the $beforeRouteInits hooks", async () => {
const server = await PlatformExpress.bootstrap(Server);

console.log(Array.from(server.injector.keys()).map(nameOf));

return Server.prototype.$beforeRoutesInit.should.have.been.calledOnce;
});
});

0 comments on commit 7ca0ade

Please sign in to comment.