Performance: E2E testing with supertest
MEDIUM IMPACT
This affects the speed and resource usage of automated end-to-end tests, impacting test suite run time and developer feedback loops.
beforeAll(async () => { const moduleRef = await Test.createTestingModule({ imports: [AppModule] }).compile(); app = moduleRef.createNestApplication(); await app.init(); }); afterAll(async () => { await app.close(); }); test('GET /users returns 200', async () => { await request(app.getHttpServer()).get('/users').expect(200); });
beforeEach(async () => { const moduleRef = await Test.createTestingModule({ imports: [AppModule] }).compile(); app = moduleRef.createNestApplication(); await app.init(); }); test('GET /users returns 200', async () => { await request(app.getHttpServer()).get('/users').expect(200); });
| Pattern | Server Startups | Network Requests | Test Suite Runtime | Verdict |
|---|---|---|---|---|
| Start app before each test | N times | N requests | High (slow) | [X] Bad |
| Start app once before all tests | 1 time | N requests | Low (fast) | [OK] Good |