Comments (7)
@ath0mas I'm running into some test timeout issues too; I opened #69 with my findings so far.
from fakeindexeddb.
Thanks for the repo with a reproduction!
It does seem like it could be related to #64... but if I put jest.useRealTimers();
at the top of your test script, it still fails. So maybe it's something else jsdom is doing, not the timers? I dunno. I've never really used it before.
Anyone have any ideas? If it was as simple as using real timers, I could do it like suggested in #64 probably, but it doesn't seem to be that simple...
from fakeindexeddb.
The problem seems to be here:
fakeIndexedDB/src/FDBDatabase.ts
Line 220 in be0551e
This starts and completes the transaction per setImmediate
.
But setImmediate
executes the callback before process.nextTick
in jsdom
.
const tx = db.transaction('foo', 'readwrite')
await new Promise(r => process.nextTick(r))
// with node environment: { _state: 'active' }
// with jsdom environment { _state: 'finished' }
I've confirmed the following workaround in the repro:
global.setImmediate = cb => setTimeout(cb, 0)
Would it be feasible to use setTimeout
in the the Database.processTransactions()
implementation?
from fakeindexeddb.
In general it is difficult to switch between the timing functions as described in #64. It may be possible in this specific case, I'm not sure, but before I even get there... it doesn't seem to help here. You are correct that global.setImmediate = cb => setTimeout(cb, 0)
at the top of your test file makes it work. But changing the setImmediate
call to setTimeout
in repro-jest-jsdom-indexeddb/node_modules/fake-indexeddb/build/lib/Database.js does not get rid of the error. Not sure why, I guess the timer replacement is doing something sophisticated that I don't understand.
Like... any idea about why jest.useRealTimers();
doesn't seem to help? Is jest/jsdom still messing with the timers even after that?
from fakeindexeddb.
There are no fake timers in place. jest.useRealTimers()
has no effect.
(And I think if you use fake timers, you would just have to advance them.)
Replacing setImmediate
with setTimeout
in build/lib/Database
fixes test "transaction is active
on next tick".
Also replacing setImmediate
in build/FDBTransaction
then fixes the initial two tests.
The clean solution might be to configure the timer to be used per setup.
import { setNextMacroTask } from 'fake-indexeddb/auto'
setNextMacroTask(setTimeout)
from fakeindexeddb.
After update from v3.1.3 to v3.1.4 that contains only this fix, my Mocha tests started failing 😢
Error: Timeout of 2000ms exceeded. ...
I'll try to create a reproduction repo before opening corresponding issue
from fakeindexeddb.
@ath0mas Do you have fake timers in place that might need to be advanced so that the calls to setTimeout
in 17c1547 are resolved?
from fakeindexeddb.
Related Issues (20)
- FBDCursor broken in release/minimised build HOT 1
- FakeDOMStringList should not support array methods HOT 4
- setTimeout problems / questions HOT 4
- 3.1.6 regression: `ReferenceError: setImmediate is not defined` HOT 1
- orderBy support HOT 4
- initialize the DB before the use. HOT 2
- Add observation for Dexie users HOT 3
- [BUG] Context loosing for `FakeDOMStringList` members while wrapping IDB
- [BUG] Invalid behavior for concurrent insertion data HOT 1
- Ref of Observable from liveQuery is not reactive HOT 7
- fake-indexeddb fails when happy-dom is loaded prior to fake-indexeddb HOT 3
- Running this in Chrome throws "Cannot set property indexedDB of #<Window> which has only a getter" HOT 3
- Release new version to npm with latest types fix HOT 3
- DataCloneError: The data being stored could not be cloned by the internal structured cloning algorithm. HOT 2
- Problem storing and retrieving CryptoKeys HOT 2
- structuredClone and jsdom HOT 7
- `Uint8Array` keys don't respect offsets from underlying ArrayBuffers HOT 3
- Serializing (and restoring) the state of Fake IDB HOT 1
- Unable to use in tests that mock timers (e.g. overriding `globalThis.setImmediate`) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fakeindexeddb.