Only initialize IDBShim and database once

This commit is contained in:
Hamcha 2019-09-12 11:20:06 +02:00
parent e238485b21
commit cf47d5db4a
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
3 changed files with 17 additions and 4 deletions

View file

@ -20,7 +20,9 @@ class CardDatabase extends Dexie {
export let Database: CardDatabase | null = null;
export function initDB() {
if (Database == null) {
Database = new CardDatabase();
}
}
export async function getCards(filter: CardFilter) {

11
src/testing/IDBShim.ts Normal file
View file

@ -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;
}
}

View file

@ -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 () => {