Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
The E2E template generated by the NestJS CLI initializes the application in a beforeEach hook but never closes it. The missing app.close() call in an afterEach / afterAll hook prevents Jest from exiting cleanly, causing the test suite to hang indefinitely on CI.
Upstream reference: #1777 (closed without fixing the template — the maintainer's response states that adding app.close() in afterAll is "a personal choice", yet initializing in beforeEach is already an opinionated choice. The asymmetry leaves generated projects with a broken CI pipeline out of the box.)
Describe the solution you'd like
Add an afterAll or afterEach hook calling await app.close() to the generated E2E test template.
describe("AppController (e2e)", () => {
let app: INestApplication<App>;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
afterEach(async () => {
await app.close();
});
it("/ (GET)", () => {
return request(app.getHttpServer()).get("/").expect(200).expect("Hello World!");
});
});
Teachability, documentation, adoption, migration strategy
Non-breaking change
What is the motivation / use case for changing the behavior?
The generated template is the first thing a developer runs when starting a new NestJS project. If the E2E test suite never terminates, the CI pipeline hangs indefinitely on the very first run, blocking any automated workflow built on top of the template (starter kits, monorepo generators, etc.).
Using --forceExit as a workaround is not acceptable in a generated template.
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
The E2E template generated by the NestJS CLI initializes the application in a beforeEach hook but never closes it. The missing
app.close()call in anafterEach/afterAllhook prevents Jest from exiting cleanly, causing the test suite to hang indefinitely on CI.Upstream reference: #1777 (closed without fixing the template — the maintainer's response states that adding
app.close()inafterAllis "a personal choice", yet initializing in beforeEach is already an opinionated choice. The asymmetry leaves generated projects with a broken CI pipeline out of the box.)Describe the solution you'd like
Add an
afterAllorafterEachhook calling awaitapp.close()to the generated E2E test template.Teachability, documentation, adoption, migration strategy
Non-breaking change
What is the motivation / use case for changing the behavior?
The generated template is the first thing a developer runs when starting a new NestJS project. If the E2E test suite never terminates, the CI pipeline hangs indefinitely on the very first run, blocking any automated workflow built on top of the template (starter kits, monorepo generators, etc.).
Using
--forceExitas a workaround is not acceptable in a generated template.