Skip to content
File

Blob: tests/client/util/idb.ts

typescript21 lines
1import "fake-indexeddb/auto";
2import { createDb, type BlandDatabase } from "@/client/stores/db/bland-db";
3 
4let counter = 0;
5 
6/**
7 * Create a fresh Dexie database with a unique name per test so parallel
8 * test cases do not share IndexedDB state. Returns the db handle; the
9 * caller is responsible for calling `deleteDb(db)` in `afterEach` so the
10 * fake-indexeddb instance does not accumulate.
11 */
12export function createFreshDb(): BlandDatabase {
13 counter += 1;
14 return createDb(`bland-test-${process.pid}-${Date.now()}-${counter}`);
15}
16 
17export async function deleteDb(db: BlandDatabase): Promise<void> {
18 if (db.isOpen()) db.close();
19 await db.delete();
20}