Skip to content

Re-enable Vitest file parallelism for web-api tests #280

@arlowhite

Description

@arlowhite

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions