Background
Vitest file-level parallelism was disabled in packages/web-api/vitest.config.ts (fileParallelism: false) to fix a race condition in integration tests.
Problem
Each test file independently calls clearDbs() then userSetup() in its beforeAll/beforeEach hooks. When files run in parallel, two workers can race to truncate and re-seed the shared test database simultaneously, causing Unique constraint failed on the fields: (email) errors (and potentially other flaky failures).
What needs to change to re-enable parallelism
- Isolate database state per worker — e.g. use a separate database schema or database name per Vitest worker (Vitest supports
VITEST_POOL_ID / VITEST_WORKER_ID env vars for this).
- Or centralise setup in a single global setup file (
globalSetup) that seeds the DB once before all tests, and use per-test transactions/rollbacks to keep tests isolated without repeated truncation.
- Or use an in-memory/SQLite database for unit-level tests and reserve the real DB for a dedicated integration suite run serially.
Restoring parallelism will significantly reduce CI test time as the suite grows.
References
Background
Vitest file-level parallelism was disabled in
packages/web-api/vitest.config.ts(fileParallelism: false) to fix a race condition in integration tests.Problem
Each test file independently calls
clearDbs()thenuserSetup()in itsbeforeAll/beforeEachhooks. When files run in parallel, two workers can race to truncate and re-seed the shared test database simultaneously, causingUnique constraint failed on the fields: (email)errors (and potentially other flaky failures).What needs to change to re-enable parallelism
VITEST_POOL_ID/VITEST_WORKER_IDenv vars for this).globalSetup) that seeds the DB once before all tests, and use per-test transactions/rollbacks to keep tests isolated without repeated truncation.Restoring parallelism will significantly reduce CI test time as the suite grows.
References
fileParallelismconfig option: https://vitest.dev/config/#fileparallelism