Files
core/test/helper/register-app.helper.ts
2022-04-17 21:26:24 +08:00

24 lines
688 B
TypeScript

import { ValidationPipe } from '@nestjs/common'
import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { TestingModule } from '@nestjs/testing'
import { fastifyApp } from '~/common/adapters/fastify.adapter'
export const setupE2EApp = async (module: TestingModule) => {
const app = module.createNestApplication<NestFastifyApplication>(fastifyApp)
app.useGlobalPipes(
new ValidationPipe({
transform: true,
whitelist: true,
errorHttpStatusCode: 422,
forbidUnknownValues: true,
enableDebugMessages: isDev,
stopAtFirstError: true,
}),
)
await app.init()
await app.getHttpAdapter().getInstance().ready()
return app
}