Description
Goal
I use fake-indexeddb for testing, which works great with Dexie except for problems with liveQuery's apparent* dependence on a global (*I may have misunderstood something!).
I believe it'll be fixed by being able to give liveQuery a reference to a specific indexedDb instance (like new Dexie
can with DexieOptions).
How my FakeIndexedDb tests work
I create a new FakeIndexedDb instance per test, and pass it to Dexie.
import { IDBFactory, IDBKeyRange } from "fake-indexeddb";
const _indexedDB = new IDBFactory();
const db = new Dexie('name', {indexedDB: _indexedDB, IDBKeyRange})
I then use live query as normal on db
.
What goes wrong
As I add more tests, FakeIndexedDb/Dexie run slower and slower. E.g. several seconds to run 'toArray' on an empty table - but that same test runs in 400ms when run in isolation.
To prove it's some kind of leak somewhere:
- I'm forced to use
import "fake-indexeddb/auto"
at the top of the test file, or liveQuery won't work. This is FakeIndexedDb's global. Only liveQuery needs it, as Dexie itself it passed an individual FakeIndexedDb instance. I suspect that global is being marshalled across tests by the test runner, causing the slow down. - If I split the tests across separate test files, the Dexie/IDB performance is fine.
Request
I want to pass liveQuery something equivalent to DexieOptions
, to give it the FakeIndexedDb instance.
I'd happily make a fork/PR myself, but some pointers of where to start from in ./src/live-query would help enormously (I've not succeeded at even finding any reference to the global indexedDb so far).