diff options
Diffstat (limited to 'packages/idb-bridge/src/backends.test.ts')
-rw-r--r-- | packages/idb-bridge/src/backends.test.ts | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/packages/idb-bridge/src/backends.test.ts b/packages/idb-bridge/src/backends.test.ts index 684358eac..64133a73b 100644 --- a/packages/idb-bridge/src/backends.test.ts +++ b/packages/idb-bridge/src/backends.test.ts @@ -23,24 +23,23 @@ * Imports. */ import test from "ava"; +import { MemoryBackend } from "./MemoryBackend.js"; import { BridgeIDBCursorWithValue, BridgeIDBDatabase, BridgeIDBFactory, BridgeIDBKeyRange, - BridgeIDBTransaction, } from "./bridge-idb.js"; +import { promiseFromRequest, promiseFromTransaction } from "./idbpromutil.js"; import { IDBCursorDirection, IDBCursorWithValue, IDBDatabase, IDBKeyRange, - IDBRequest, IDBValidKey, } from "./idbtypes.js"; import { initTestIndexedDB, useTestIndexedDb } from "./testingdb.js"; -import { MemoryBackend } from "./MemoryBackend.js"; -import { promiseFromRequest, promiseFromTransaction } from "./idbpromutil.js"; +import { promiseForTransaction } from "./idb-wpt-ported/wptsupport.js"; test.before("test DB initialization", initTestIndexedDB); @@ -464,8 +463,7 @@ test("export", async (t) => { const exportedData2 = backend2.exportDump(); t.assert( - exportedData.databases[dbname].objectStores["books"].records.length === - 3, + exportedData.databases[dbname].objectStores["books"].records.length === 3, ); t.deepEqual(exportedData, exportedData2); @@ -738,3 +736,44 @@ test("range queries", async (t) => { t.pass(); }); + +test("idb: multiple transactions", async (t) => { + const idb = useTestIndexedDb(); + const dbname = "mtx-" + new Date().getTime() + Math.random(); + + const request = idb.open(dbname); + request.onupgradeneeded = () => { + const db = request.result as BridgeIDBDatabase; + const store = db.createObjectStore("books", { keyPath: "isbn" }); + const titleIndex = store.createIndex("by_title", "title", { unique: true }); + const authorIndex = store.createIndex("by_author", "author"); + + // Populate with initial data. + store.put({ title: "Quarry Memories", author: "Fred", isbn: 123456 }); + store.put({ title: "Water Buffaloes", author: "Fred", isbn: 234567 }); + store.put({ title: "Bedrock Nights", author: "Barney", isbn: 345678 }); + }; + + const db: BridgeIDBDatabase = await promiseFromRequest(request); + + const tx1 = db.transaction(["books"], "readwrite"); + + tx1.oncomplete = () => { + t.log("first tx completed"); + }; + + tx1.onerror = () => { + t.log("first tx errored"); + }; + + tx1.abort(); + + const tx2 = db.transaction(["books"], "readwrite"); + tx2.commit(); + + const tx3 = db.transaction(["books"], "readwrite"); + + await promiseForTransaction(t, tx3); + + t.pass(); +}); |