diff --git a/src/vitest.config.ts b/src/vitest.config.ts index 74779798c..7f285414b 100644 --- a/src/vitest.config.ts +++ b/src/vitest.config.ts @@ -13,27 +13,52 @@ export default defineConfig({ ], }, test: { - globals: true, - setupFiles: ['./tests/backend/vitest.setup.ts'], - include: [ - 'tests/backend-new/specs/**/*.ts', - 'tests/backend/specs/**/*.ts', + projects: [ + { + extends: true, + test: { + name: 'unit', + globals: true, + setupFiles: ['./tests/backend/vitest.setup.ts'], + include: ['tests/backend-new/specs/**/*.ts'], + hookTimeout: 60000, + testTimeout: 60000, + // Unit tests use vi.mock heavily — they NEED isolation. Each + // file gets a fresh module graph so mocks declared at the top + // of the file actually apply. + isolate: true, + fileParallelism: true, + pool: 'forks', + sequence: { + // Run unit project first (group 1), then integration (group 2). + // Different groupOrder is required when projects have different maxWorkers. + groupOrder: 1, + }, + }, + }, + { + extends: true, + test: { + name: 'integration', + globals: true, + setupFiles: ['./tests/backend/vitest.setup.ts'], + include: ['tests/backend/specs/**/*.ts'], + hookTimeout: 60000, + testTimeout: 120000, + // Backend tests share a single Etherpad server instance + rustydb file. + // Vitest's default parallel/isolated workers each boot their own server + // and crash the second-to-open with `Error: DatabaseAlreadyOpen`. Force + // one fork, sequential file execution, no per-file isolation — same + // effective model as the old mocha runner. + pool: 'forks', + fileParallelism: false, + isolate: false, + sequence: { + // Run after the unit project (group 2 runs after group 1). + groupOrder: 2, + }, + }, + }, ], - // Container tests (tests/container/specs/**/*.ts) are excluded from - // the default include because they target a separately-booted Etherpad - // process (the docker image, port 9001) and ECONNREFUSED locally. They - // are invoked explicitly by the `test-container` script which passes - // its own include via --include. - hookTimeout: 60000, - testTimeout: 120000, - // Backend tests share a single Etherpad server instance + rustydb file. - // Vitest's default parallel/isolated workers each boot their own server - // and crash the second-to-open with `Error: DatabaseAlreadyOpen`. Mocha - // never hit this because everything ran in one process. Force one fork, - // sequential file execution, no per-file isolation — same effective - // model as the old mocha runner. - pool: 'forks', - fileParallelism: false, - isolate: false, }, });