From d682d8001ac16fc93e8edd3fe7e13aefbcb6663b Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Mon, 25 May 2026 13:39:00 +0200 Subject: [PATCH] test: split vitest into unit + integration projects tests/backend-new/specs/** are mock-heavy unit tests that need per-file isolation (vi.mock must apply before the SUT is loaded, and a shared module graph defeats it). tests/backend/specs/** share rustydb and need the old isolate:false sequential model. Split via test.projects (vitest 4): unit gets isolate:true + parallelism; integration keeps the existing serial config. Different sequence.groupOrder values (1 vs 2) are required by vitest when projects have different maxWorkers settings. Fixes 8 mock-related test failures in updateStatus, firstAuthorOf, and updateCheck-optout that came in from the develop merge. Co-Authored-By: Claude Sonnet 4.6 --- src/vitest.config.ts | 67 ++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 21 deletions(-) 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, }, });