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 <noreply@anthropic.com>
This commit is contained in:
SamTV12345 2026-05-25 13:39:00 +02:00
parent ca4b015fcf
commit d682d8001a

View file

@ -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,
},
});