You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
620 B
TypeScript
18 lines
620 B
TypeScript
import { mkdirSync, rmSync } from 'fs';
|
|
import { join } from 'path';
|
|
import Database from 'bun:sqlite';
|
|
import { initializeDatabase } from '../../../src/db';
|
|
|
|
export function createTempDb(): { path: string; db: any; cleanup: () => void } {
|
|
const dir = join('tmp', 'web-tests');
|
|
try { mkdirSync(dir, { recursive: true }); } catch {}
|
|
const path = join(dir, `db-${Date.now()}-${Math.random().toString(16).slice(2)}.sqlite`);
|
|
const db = new Database(path);
|
|
initializeDatabase(db);
|
|
const cleanup = () => {
|
|
try { db.close(); } catch {}
|
|
try { rmSync(path); } catch {}
|
|
};
|
|
return { path, db, cleanup };
|
|
}
|