From e4b46ddbfca0abd0aa56911f068c284a2e7a4154 Mon Sep 17 00:00:00 2001 From: claude_code Date: Fri, 26 Jun 2026 19:13:22 +0300 Subject: [PATCH] test(e2e): make server e2e actually boot (ESM chain + Fastify adapter) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous jest-config fix let the module graph load further and exposed two more reasons the server e2e never passed since it was added: 1. ESM transform chain: AppModule pulls in editor-ext -> @tiptap -> @sindresorhus/slugify -> @sindresorhus/transliterate / escape-string-regexp, plus p-limit -> yocto-queue — all ESM-only. Extend the e2e transformIgnorePatterns whitelist to transform them (scoped packages need both the pnpm `@scope+name` and nested `@scope/name` path forms, hence `@sindresorhus[+/][a-z0-9-]+`). Verified locally: the graph now fully transforms and resolves. 2. Wrong HTTP adapter: Docmost runs on Fastify (main.ts uses FastifyAdapter) and does not depend on @nestjs/platform-express, but the scaffold test used the default createNestApplication() (Express) and died with "@nestjs/platform-express package is missing". Switch the test to FastifyAdapter + getInstance().ready(), close in afterEach. Verified locally: createNestApplication + app.init() now proceed to the live Redis/Postgres connection (the infra CI provides via services + migrations). Co-Authored-By: Claude Opus 4.8 --- apps/server/test/app.e2e-spec.ts | 22 +++++++++++++++++++--- apps/server/test/jest-e2e.json | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) 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",