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.
This commit is contained in:
@@ -15,9 +15,15 @@ import * as schema from '../../server/db/schema'
|
|||||||
// to a module namespace), so we sidestep the transform entirely.
|
// to a module namespace), so we sidestep the transform entirely.
|
||||||
const pg = createRequire(import.meta.url)('pg') as typeof pgType
|
const pg = createRequire(import.meta.url)('pg') as typeof pgType
|
||||||
|
|
||||||
const TEST_URL =
|
// Each Vitest worker gets its own database so specs that truncate between
|
||||||
process.env.TEST_DATABASE_URL ??
|
// tests can't clobber one another when files run in parallel.
|
||||||
'postgres://andon:andon@localhost:5432/andon_test'
|
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<typeof schema>
|
export type TestDb = NodePgDatabase<typeof schema>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user