Skip to content

Update idb code to be testable, awaitable, error handleable...

Brian Kockritz requested to merge improve-idb into master

Links to relevant issues

Description of changes, providing context that may help others understand the changes

I was trying to write some tests for submissions.store.js that exercised idb logic. It wasn't possible to use our idb code to assert on the state of idb within a test because it didn't return a promise. So, I gave mocking it a shot, but the nested callbacks made mocking require a lot of effort and required coupling the mocks to implementation details. This MR uses the https://github.com/jakearchibald/idb library to simplify our idb code significantly, so it's easy to handle its asynchronicity, catch errors, etc.

Commit Message:

Update idb code to be testable, awaitable, error handleable. Fix upgrade logic to not produce errors by only running things on certain database versions. Add handling of blocked and blocking scenarios so that multiple browser tabs don't interfere with each other in the event of a database version upgrade.

Some tests in File.spec.js started failing due to issues with structuredClone. They used to pass because the idb code would fail immediately and the error was swallowed, ever getting to the actual idb operation that raises the structuredClone error. To workaround the failing tests, the store/db.js file was mocked in the File.spec.js tests. To resolve the structuredClone error we need to upgrade to jest 28, fake-indexeddb 4, and node 17. We should wait for the vue 3 branch to address that, as it will upgrade node and jest at least. Once those dependencies are upgraded, we should be able to remove the db mock from File.spec.js and the idb code thats exercised as part of the tests should run without error.

Merge request reports