From e5c4cbc331eb2051664032282c8686198a78eeca Mon Sep 17 00:00:00 2001 From: Shaun Campbell Date: Fri, 20 Feb 2026 23:21:41 -0500 Subject: [PATCH] test) stabilize vitest db bootstrap in ci --- .gitea/workflows/pr-checks.yml | 2 +- src/lib/server/db/index.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/pr-checks.yml b/.gitea/workflows/pr-checks.yml index b04af5c..70159ae 100644 --- a/.gitea/workflows/pr-checks.yml +++ b/.gitea/workflows/pr-checks.yml @@ -35,7 +35,7 @@ jobs: run: bun run lint - name: Unit tests - run: bun run test + run: bunx --bun svelte-kit sync && bunx --bun vitest run --maxWorkers=1 - name: Build app run: bun run build diff --git a/src/lib/server/db/index.ts b/src/lib/server/db/index.ts index 50e9add..db38cd4 100644 --- a/src/lib/server/db/index.ts +++ b/src/lib/server/db/index.ts @@ -3,10 +3,12 @@ import { createSqliteDb } from './sqlite.js'; import { runMigrations } from './migrations.js'; import type { Database } from './types.js'; -function createDb(): Database { - const url = env.DATABASE_URL ?? 'file:trips.db'; +const isVitest = process.env.VITEST === 'true'; - if (url.startsWith('file:') || url.endsWith('.db')) { +function createDb(): Database { + const url = isVitest ? ':memory:' : (env.DATABASE_URL ?? 'file:trips.db'); + + if (url === ':memory:' || url.startsWith('file:') || url.endsWith('.db')) { return createSqliteDb(url); } @@ -17,7 +19,9 @@ function createDb(): Database { export let db: Database = createDb(); -runMigrations(db); +if (!isVitest) { + runMigrations(db); +} /** * Replace the database singleton. For use in tests only — call this with an