From fc958ba59f7b5a75fc2dd3233db9e9a4d8d085b7 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Thu, 28 May 2026 00:18:18 +0200 Subject: [PATCH] test: give each vitest worker its own Postgres database Specs truncate the test DB between tests; with multiple DB-backed spec files running in parallel workers they clobbered each other. Suffix the database name with VITEST_POOL_ID so each worker is isolated. --- tests/helpers/db.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/helpers/db.ts b/tests/helpers/db.ts index 883c9ae..a9a455d 100644 --- a/tests/helpers/db.ts +++ b/tests/helpers/db.ts @@ -15,9 +15,15 @@ import * as schema from '../../server/db/schema' // to a module namespace), so we sidestep the transform entirely. const pg = createRequire(import.meta.url)('pg') as typeof pgType -const TEST_URL = - process.env.TEST_DATABASE_URL ?? - 'postgres://andon:andon@localhost:5432/andon_test' +// Each Vitest worker gets its own database so specs that truncate between +// tests can't clobber one another when files run in parallel. +const TEST_URL = (() => { + const base = + process.env.TEST_DATABASE_URL ?? 'postgres://andon:andon@localhost:5432/andon_test' + const url = new URL(base) + url.pathname = `${url.pathname}_${process.env.VITEST_POOL_ID ?? '1'}` + return url.toString() +})() export type TestDb = NodePgDatabase