|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { mkdirSync, rmSync } from 'fs';
|
|
|
|
|
import { join } from 'path';
|
|
|
|
|
import { join, resolve } from 'path';
|
|
|
|
|
import Database from 'bun:sqlite';
|
|
|
|
|
import { initializeDatabase } from '../../../src/db';
|
|
|
|
|
|
|
|
|
|
@ -7,11 +7,12 @@ 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);
|
|
|
|
|
const absPath = resolve(path);
|
|
|
|
|
const db = new Database(absPath);
|
|
|
|
|
initializeDatabase(db);
|
|
|
|
|
const cleanup = () => {
|
|
|
|
|
try { db.close(); } catch {}
|
|
|
|
|
try { rmSync(path); } catch {}
|
|
|
|
|
try { rmSync(absPath); } catch {}
|
|
|
|
|
};
|
|
|
|
|
return { path, db, cleanup };
|
|
|
|
|
return { path: absPath, db, cleanup };
|
|
|
|
|
}
|
|
|
|
|
|