import { randomUUID } from 'node:crypto'; import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import { NestExpressApplication } from '@nestjs/platform-express'; import { App } from 'supertest/types'; import { AppModule } from '../../src/app.module'; import { configureApp } from '../../src/app.config'; import { THROTTLER_NAMESPACE } from '../../src/common/throttler/prisma-throttler.storage'; export interface CreateTestAppOptions { /** * Rate-limit counter namespace. Defaults to a fresh random one so parallel * e2e files never throttle each other; pass the same value to two apps to * simulate two pods sharing one counter set. */ throttlerNamespace?: string; } export async function createTestApp( options: CreateTestAppOptions = {}, ): Promise> { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }) .overrideProvider(THROTTLER_NAMESPACE) .useValue(options.throttlerNamespace ?? randomUUID()) .compile(); const app = moduleFixture.createNestApplication(); configureApp(app); await app.init(); return app; }