test) stabilize vitest db bootstrap in ci
Some checks failed
PR Checks / lint-test-and-docker-build (pull_request) Failing after 1m10s
Some checks failed
PR Checks / lint-test-and-docker-build (pull_request) Failing after 1m10s
This commit is contained in:
@@ -35,7 +35,7 @@ jobs:
|
|||||||
run: bun run lint
|
run: bun run lint
|
||||||
|
|
||||||
- name: Unit tests
|
- name: Unit tests
|
||||||
run: bun run test
|
run: bunx --bun svelte-kit sync && bunx --bun vitest run --maxWorkers=1
|
||||||
|
|
||||||
- name: Build app
|
- name: Build app
|
||||||
run: bun run build
|
run: bun run build
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import { createSqliteDb } from './sqlite.js';
|
|||||||
import { runMigrations } from './migrations.js';
|
import { runMigrations } from './migrations.js';
|
||||||
import type { Database } from './types.js';
|
import type { Database } from './types.js';
|
||||||
|
|
||||||
function createDb(): Database {
|
const isVitest = process.env.VITEST === 'true';
|
||||||
const url = env.DATABASE_URL ?? 'file:trips.db';
|
|
||||||
|
|
||||||
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);
|
return createSqliteDb(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +19,9 @@ function createDb(): Database {
|
|||||||
|
|
||||||
export let db: Database = createDb();
|
export let db: Database = createDb();
|
||||||
|
|
||||||
|
if (!isVitest) {
|
||||||
runMigrations(db);
|
runMigrations(db);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace the database singleton. For use in tests only — call this with an
|
* Replace the database singleton. For use in tests only — call this with an
|
||||||
|
|||||||
Reference in New Issue
Block a user