diff --git a/src/mlpccg/database.ts b/src/mlpccg/database.ts index 088f5ab..a9dd537 100644 --- a/src/mlpccg/database.ts +++ b/src/mlpccg/database.ts @@ -20,7 +20,9 @@ class CardDatabase extends Dexie { export let Database: CardDatabase | null = null; export function initDB() { - Database = new CardDatabase(); + if (Database == null) { + Database = new CardDatabase(); + } } export async function getCards(filter: CardFilter) { diff --git a/src/testing/IDBShim.ts b/src/testing/IDBShim.ts new file mode 100644 index 0000000..59fdb2c --- /dev/null +++ b/src/testing/IDBShim.ts @@ -0,0 +1,11 @@ +import Dexie from "dexie"; + +let init = false; + +export function setupIDBShim() { + if (!init) { + const setGlobalVars = require("indexeddbshim"); + setGlobalVars(Dexie.dependencies); + init = true; + } +} diff --git a/src/tests/unit/database.spec.ts b/src/tests/unit/database.spec.ts index b87cf75..1bb70a5 100644 --- a/src/tests/unit/database.spec.ts +++ b/src/tests/unit/database.spec.ts @@ -1,7 +1,7 @@ import { loadSets, getCards, Database, initDB, cardFullName } from "@/mlpccg"; -import Dexie from "dexie"; -const setGlobalVars = require("indexeddbshim"); -setGlobalVars(Dexie.dependencies); +import { setupIDBShim } from "@/testing/IDBShim"; + +setupIDBShim(); describe("mlpccg/Database", () => { beforeAll(async () => {