Skip to content

Commit

Permalink
Revert fix to #66 and add a test using Dexie
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Jul 2, 2022
1 parent f56e085 commit b96a4f2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"build-qunit": "mkdir build/esm/test/indexedDBmock && cp src/test/indexedDBmock/* build/esm/test/indexedDBmock && browserify src/test/indexedDBmock/exports-qunit-bundle.js -o build/esm/test/indexedDBmock/exports-qunit-bundle.js -t [ babelify --presets [ @babel/preset-env ] ]",
"test-qunit": "yarn run build-qunit && node-qunit-phantomjs build/esm/test/indexedDBmock/index.html",
"test-w3c": "node src/test/web-platform-tests/run-all.js",
"test": "rm -rf build && yarn run lint && yarn run build && yarn run test-jest && node test/test.js && yarn run test-w3c && yarn run test-mocha && yarn run test-qunit",
"test": "rm -rf build && yarn run lint && yarn run build && yarn run test-jest && node test/test.js && node test/dexie.js && yarn run test-w3c && yarn run test-mocha && yarn run test-qunit",
"prepare": "husky install"
},
"author": "Jeremy Scheff <[email protected]> (http://dumbmatter.com/)",
Expand All @@ -122,6 +122,7 @@
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"core-js": "^3.23.3",
"dexie": "^3.2.2",
"glob": "^8.0.3",
"husky": "^7.0.4",
"jest": "^28.1.2",
Expand Down
5 changes: 3 additions & 2 deletions src/lib/FakeDOMStringList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Subclass Array to get nice behaviors like destructuring, but delete various Array methods that don't exist on DOMStringList https://github.com/dumbmatter/fakeIndexedDB/issues/66#issuecomment-922407403

class FakeDOMStringList extends Array<string> {
contains(value: string) {
for (const value2 of this) {
Expand All @@ -26,6 +24,8 @@ class FakeDOMStringList extends Array<string> {
}
}

// Would be nice to remove these properties to fix https://github.com/dumbmatter/fakeIndexedDB/issues/66 but for some reason it breaks Dexie - see test/dexie.js and FakeDOMStringList tests
/*
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
const arrayPropertiesToDelete = ["from", "isArray", "of"];
const arrayMethodsToDelete = [
Expand Down Expand Up @@ -68,5 +68,6 @@ for (const property of arrayPropertiesToDelete) {
for (const property of arrayMethodsToDelete) {
(FakeDOMStringList as any).prototype[property] = undefined;
}
*/

export default FakeDOMStringList;
2 changes: 1 addition & 1 deletion src/test/fakeIndexedDB/fakeIndexedDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ describe("fakeIndexedDB Tests", () => {
assert.strictEqual(list.item(-1), null);
});

it("does not include various Array properties", () => {
it.skip("does not include various Array properties", () => {
const list = new FakeDOMStringList("a", "b", "c");
const array = ["a", "b", "c"];

Expand Down
26 changes: 26 additions & 0 deletions test/dexie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from "node:assert";
import "../auto/index.mjs";
import Dexie from "dexie";

const db = new Dexie("MyDatabase");

db.version(1).stores({
friends: "++id, name, age",
});

await db.friends.add({
name: "Alice",
age: 25,
street: "East 13:th Street",
});

await db.friends.add({
name: "Bob",
age: 80,
street: "East 13:th Street",
});

const oldFriends = await db.friends.where("age").above(75).toArray();

assert.equal(oldFriends.length, 1);
process.exit(0);
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,11 @@ detective@^5.2.0:
defined "^1.0.0"
minimist "^1.2.6"

dexie@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/dexie/-/dexie-3.2.2.tgz#fa6f2a3c0d6ed0766f8d97a03720056f88fe0e01"
integrity sha512-q5dC3HPmir2DERlX+toCBbHQXW5MsyrFqPFcovkH9N2S/UW/H3H5AWAB6iEOExeraAu+j+zRDG+zg/D7YhH0qg==

diff-sequences@^28.1.1:
version "28.1.1"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-28.1.1.tgz#9989dc731266dc2903457a70e996f3a041913ac6"
Expand Down

0 comments on commit b96a4f2

Please sign in to comment.