diff options
author | Florian Dold <florian@dold.me> | 2022-02-10 19:52:45 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-02-10 19:53:44 +0100 |
commit | 5ff3b44550d4f5ab9a20d85dbf4387d455ebb862 (patch) | |
tree | 7db62fdc0a87338a4e7fc8dcb51f80fb00d789e4 /packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts | |
parent | 1de423834d0a9ca34b10de39e7e51570415f1ed5 (diff) | |
download | wallet-core-5ff3b44550d4f5ab9a20d85dbf4387d455ebb862.tar.xz |
idb-bridge: update tests for ava 4.x
Diffstat (limited to 'packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts')
-rw-r--r-- | packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts | 439 |
1 files changed, 230 insertions, 209 deletions
diff --git a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts index 4843b13ab..e3169195f 100644 --- a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts +++ b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts @@ -1,243 +1,264 @@ import test from "ava"; -import { BridgeIDBCursor } from ".."; -import { BridgeIDBCursorWithValue } from "../bridge-idb"; -import { IDBDatabase } from "../idbtypes"; -import { createdb } from "./wptsupport"; +import { BridgeIDBCursor } from "../bridge-idb.js"; +import { IDBDatabase } from "../idbtypes.js"; +import { createdb } from "./wptsupport.js"; // IDBCursor.continue() - object store - iterate to the next record -test.cb("WPT test idbcursor_continue_objectstore.htm", (t) => { - var db: any; - let count = 0; - const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; - - var open_rq = createdb(t); - open_rq.onupgradeneeded = function (e: any) { - db = e.target.result; - var objStore = db.createObjectStore("test", { - autoIncrement: true, - keyPath: "pKey", - }); - - for (var i = 0; i < records.length; i++) objStore.add(records[i]); - }; - - open_rq.onsuccess = function (e: any) { - var store = db.transaction("test").objectStore("test"); - - var cursor_rq = store.openCursor(); - cursor_rq.onsuccess = function (e: any) { - var cursor = e.target.result; - if (!cursor) { - t.deepEqual(count, records.length, "cursor run count"); - t.end(); - } - - var record = cursor.value; - t.deepEqual(record.pKey, records[count].pKey, "primary key"); - - cursor.continue(); - count++; +test("WPT test idbcursor_continue_objectstore.htm", (t) => { + return new Promise((resolve, reject) => { + var db: any; + let count = 0; + const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; + + var open_rq = createdb(t); + open_rq.onupgradeneeded = function (e: any) { + db = e.target.result; + var objStore = db.createObjectStore("test", { + autoIncrement: true, + keyPath: "pKey", + }); + + for (var i = 0; i < records.length; i++) objStore.add(records[i]); }; - }; + + open_rq.onsuccess = function (e: any) { + var store = db.transaction("test").objectStore("test"); + + var cursor_rq = store.openCursor(); + cursor_rq.onsuccess = function (e: any) { + var cursor = e.target.result; + if (!cursor) { + t.deepEqual(count, records.length, "cursor run count"); + resolve(); + return; + } + + var record = cursor.value; + t.deepEqual(record.pKey, records[count].pKey, "primary key"); + + cursor.continue(); + count++; + }; + }; + }); }); // IDBCursor.continue() - index - attempt to pass a // key parameter that is not a valid key -test.cb("WPT test idbcursor_continue_objectstore2.htm", (t) => { - var db: any; - const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; +test("WPT test idbcursor_continue_objectstore2.htm", (t) => { + return new Promise((resolve, reject) => { + var db: any; + const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; - var open_rq = createdb(t); - open_rq.onupgradeneeded = function (e: any) { - db = e.target.result; - var objStore = db.createObjectStore("test", { keyPath: "pKey" }); + var open_rq = createdb(t); + open_rq.onupgradeneeded = function (e: any) { + db = e.target.result; + var objStore = db.createObjectStore("test", { keyPath: "pKey" }); - for (var i = 0; i < records.length; i++) objStore.add(records[i]); - }; + for (var i = 0; i < records.length; i++) objStore.add(records[i]); + }; - open_rq.onsuccess = function (e: any) { - var cursor_rq = db.transaction("test").objectStore("test").openCursor(); + open_rq.onsuccess = function (e: any) { + var cursor_rq = db.transaction("test").objectStore("test").openCursor(); - cursor_rq.onsuccess = function (e: any) { - var cursor = e.target.result; + cursor_rq.onsuccess = function (e: any) { + var cursor = e.target.result; - t.true(cursor instanceof BridgeIDBCursor, "cursor exists"); - t.throws( - () => { - cursor.continue({ foo: "42" }); - }, - { name: "DataError" }, - ); + t.true(cursor instanceof BridgeIDBCursor, "cursor exists"); + t.throws( + () => { + cursor.continue({ foo: "42" }); + }, + { name: "DataError" }, + ); - t.end(); + resolve(); + }; }; - }; + }); }); // IDBCursor.continue() - object store - attempt to iterate to the // previous record when the direction is set for the next record -test.cb("WPT test idbcursor_continue_objectstore3.htm", (t) => { - var db: IDBDatabase; - const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; - - var open_rq = createdb(t); - open_rq.onupgradeneeded = function (e: any) { - db = e.target.result; - var objStore = db.createObjectStore("test", { keyPath: "pKey" }); - - for (var i = 0; i < records.length; i++) objStore.add(records[i]); - }; - - open_rq.onsuccess = function (e: any) { - var cursor_rq = db - .transaction("test") - .objectStore("test") - .openCursor(undefined, "next"); - - cursor_rq.onsuccess = function (e: any) { - var cursor = e.target.result; - - t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); - t.throws( - () => { - cursor.continue(records[0].pKey); - }, - { - name: "DataError", - }, - ); - - t.end(); +test("WPT test idbcursor_continue_objectstore3.htm", (t) => { + return new Promise((resolve, reject) => { + var db: IDBDatabase; + const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; + + var open_rq = createdb(t); + open_rq.onupgradeneeded = function (e: any) { + db = e.target.result; + var objStore = db.createObjectStore("test", { keyPath: "pKey" }); + + for (var i = 0; i < records.length; i++) objStore.add(records[i]); + }; + + open_rq.onsuccess = function (e: any) { + var cursor_rq = db + .transaction("test") + .objectStore("test") + .openCursor(undefined, "next"); + + cursor_rq.onsuccess = function (e: any) { + var cursor = e.target.result; + + t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); + t.throws( + () => { + cursor.continue(records[0].pKey); + }, + { + name: "DataError", + }, + ); + + resolve(); + }; }; - }; + }); }); // IDBCursor.continue() - object store - attempt to iterate to the // next record when the direction is set for the previous record -test.cb("WPT test idbcursor_continue_objectstore4.htm", (t) => { - var db: any; - const records = [ - { pKey: "primaryKey_0" }, - { pKey: "primaryKey_1" }, - { pKey: "primaryKey_2" }, - ]; - - var open_rq = createdb(t); - open_rq.onupgradeneeded = function (e: any) { - db = e.target.result; - var objStore = db.createObjectStore("test", { keyPath: "pKey" }); - - for (var i = 0; i < records.length; i++) objStore.add(records[i]); - }; - - open_rq.onsuccess = function (e: any) { - var count = 0, - cursor_rq = db - .transaction("test") - .objectStore("test") - .openCursor(null, "prev"); - - cursor_rq.onsuccess = function (e: any) { - var cursor = e.target.result; - - t.true(cursor != null, "cursor exist"); - - switch (count) { - case 0: - t.deepEqual(cursor.value.pKey, records[2].pKey, "first cursor pkey"); - cursor.continue(records[1].pKey); - break; - - case 1: - t.deepEqual(cursor.value.pKey, records[1].pKey, "second cursor pkey"); - t.throws( - () => { - console.log("**** continuing cursor"); - cursor.continue(records[2].pKey); - console.log("**** this should not happen"); - }, - { - name: "DataError", - }, - ); - t.end(); - break; - - default: - t.fail("Unexpected count value: " + count); - } - - count++; +test("WPT test idbcursor_continue_objectstore4.htm", (t) => { + return new Promise((resolve, reject) => { + var db: any; + const records = [ + { pKey: "primaryKey_0" }, + { pKey: "primaryKey_1" }, + { pKey: "primaryKey_2" }, + ]; + + var open_rq = createdb(t); + open_rq.onupgradeneeded = function (e: any) { + db = e.target.result; + var objStore = db.createObjectStore("test", { keyPath: "pKey" }); + + for (var i = 0; i < records.length; i++) objStore.add(records[i]); + }; + + open_rq.onsuccess = function (e: any) { + var count = 0, + cursor_rq = db + .transaction("test") + .objectStore("test") + .openCursor(null, "prev"); + + cursor_rq.onsuccess = function (e: any) { + var cursor = e.target.result; + + t.true(cursor != null, "cursor exist"); + + switch (count) { + case 0: + t.deepEqual( + cursor.value.pKey, + records[2].pKey, + "first cursor pkey", + ); + cursor.continue(records[1].pKey); + break; + + case 1: + t.deepEqual( + cursor.value.pKey, + records[1].pKey, + "second cursor pkey", + ); + t.throws( + () => { + console.log("**** continuing cursor"); + cursor.continue(records[2].pKey); + console.log("**** this should not happen"); + }, + { + name: "DataError", + }, + ); + resolve(); + return; + + default: + t.fail("Unexpected count value: " + count); + } + + count++; + }; }; - }; + }); }); // IDBCursor.continue() - object store - throw TransactionInactiveError -test.cb("WPT test idbcursor_continue_objectstore5.htm", (t) => { - var db: any; - const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; - - var open_rq = createdb(t); - open_rq.onupgradeneeded = function (e: any) { - db = e.target.result; - var objStore = db.createObjectStore("test", { keyPath: "pKey" }); - - for (var i = 0; i < records.length; i++) objStore.add(records[i]); - }; - - open_rq.onsuccess = function (e: any) { - var cursor_rq = db.transaction("test").objectStore("test").openCursor(); - - cursor_rq.onsuccess = function (e: any) { - var cursor = e.target.result; - t.true(cursor instanceof BridgeIDBCursor, "cursor exists"); - - e.target.transaction.abort(); - t.throws( - () => { - cursor.continue(); - }, - { - name: "TransactionInactiveError", - }, - "Calling continue() should throw an exception TransactionInactiveError when the transaction is not active.", - ); - - t.end(); +test("WPT test idbcursor_continue_objectstore5.htm", (t) => { + return new Promise((resolve, reject) => { + var db: any; + const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; + + var open_rq = createdb(t); + open_rq.onupgradeneeded = function (e: any) { + db = e.target.result; + var objStore = db.createObjectStore("test", { keyPath: "pKey" }); + + for (var i = 0; i < records.length; i++) objStore.add(records[i]); + }; + + open_rq.onsuccess = function (e: any) { + var cursor_rq = db.transaction("test").objectStore("test").openCursor(); + + cursor_rq.onsuccess = function (e: any) { + var cursor = e.target.result; + t.true(cursor instanceof BridgeIDBCursor, "cursor exists"); + + e.target.transaction.abort(); + t.throws( + () => { + cursor.continue(); + }, + { + name: "TransactionInactiveError", + }, + "Calling continue() should throw an exception TransactionInactiveError when the transaction is not active.", + ); + + resolve(); + return; + }; }; - }; + }); }); // IDBCursor.continue() - object store - throw InvalidStateError caused by object store been deleted -test.cb("WPT test idbcursor_continue_objectstore6.htm", (t) => { - var db: any; - const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; - - var open_rq = createdb(t); - open_rq.onupgradeneeded = function (e: any) { - db = e.target.result; - var objStore = db.createObjectStore("test", { keyPath: "pKey" }); - - for (var i = 0; i < records.length; i++) objStore.add(records[i]); - - var cursor_rq = objStore.openCursor(); - - cursor_rq.onsuccess = function (e: any) { - var cursor = e.target.result; - t.true(cursor instanceof BridgeIDBCursor, "cursor exists"); - - db.deleteObjectStore("test"); - t.throws( - () => { - cursor.continue(); - }, - { - name: "InvalidStateError", - }, - "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError", - ); - - t.end(); +test("WPT test idbcursor_continue_objectstore6.htm", (t) => { + return new Promise((resolve, reject) => { + var db: any; + const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; + + var open_rq = createdb(t); + open_rq.onupgradeneeded = function (e: any) { + db = e.target.result; + var objStore = db.createObjectStore("test", { keyPath: "pKey" }); + + for (var i = 0; i < records.length; i++) objStore.add(records[i]); + + var cursor_rq = objStore.openCursor(); + + cursor_rq.onsuccess = function (e: any) { + var cursor = e.target.result; + t.true(cursor instanceof BridgeIDBCursor, "cursor exists"); + + db.deleteObjectStore("test"); + t.throws( + () => { + cursor.continue(); + }, + { + name: "InvalidStateError", + }, + "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError", + ); + + resolve(); + }; }; - }; + }); }); |