File
Blob: tests/client/util/idb.ts
| 1 | import "fake-indexeddb/auto"; |
| 2 | import { createDb, type BlandDatabase } from "@/client/stores/db/bland-db"; |
| 3 | |
| 4 | let 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 | */ |
| 12 | export function createFreshDb(): BlandDatabase { |
| 13 | counter += 1; |
| 14 | return createDb(`bland-test-${process.pid}-${Date.now()}-${counter}`); |
| 15 | } |
| 16 | |
| 17 | export async function deleteDb(db: BlandDatabase): Promise<void> { |
| 18 | if (db.isOpen()) db.close(); |
| 19 | await db.delete(); |
| 20 | } |