diff --git a/apps/server/test/app.e2e-spec.ts b/apps/server/test/app.e2e-spec.ts index 0012dcd2..2365dd6e 100644 --- a/apps/server/test/app.e2e-spec.ts +++ b/apps/server/test/app.e2e-spec.ts @@ -1,18 +1,34 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; +import { + FastifyAdapter, + NestFastifyApplication, +} from '@nestjs/platform-fastify'; import * as request from 'supertest'; import { AppModule } from '../src/app.module'; describe('AppController (e2e)', () => { - let app: INestApplication; + let app: NestFastifyApplication; beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); - app = moduleFixture.createNestApplication(); + // Docmost runs on Fastify (see src/main.ts). The default + // createNestApplication() would load @nestjs/platform-express, which is not + // a dependency of this project, so an explicit FastifyAdapter is required. + app = moduleFixture.createNestApplication( + new FastifyAdapter(), + ); await app.init(); + // Fastify must finish booting before its HTTP server can serve requests. + await app.getHttpAdapter().getInstance().ready(); + }); + + afterEach(async () => { + // Guard with optional chaining: if beforeEach throws before `app` is + // assigned, closing undefined would mask the original failure. + await app?.close(); }); it('/ (GET)', () => { diff --git a/apps/server/test/jest-e2e.json b/apps/server/test/jest-e2e.json index ae4cf8e3..b8532df0 100644 --- a/apps/server/test/jest-e2e.json +++ b/apps/server/test/jest-e2e.json @@ -7,7 +7,7 @@ "^.+\\.(t|j)sx?$": "ts-jest" }, "transformIgnorePatterns": [ - "/node_modules/(?!(\\.pnpm/)?(nanoid|uuid|image-dimensions|marked|happy-dom|lib0)(@|/))" + "/node_modules/(?!(\\.pnpm/)?(nanoid|uuid|image-dimensions|marked|happy-dom|lib0|@sindresorhus[+/][a-z0-9-]+|escape-string-regexp|p-limit|yocto-queue)(@|/))" ], "moduleNameMapper": { "^@docmost/db/(.*)$": "/../src/database/$1",