Giter VIP home page Giter VIP logo

Comments (7)

joshkel avatar joshkel commented on May 31, 2024 1

@ath0mas I'm running into some test timeout issues too; I opened #69 with my findings so far.

from fakeindexeddb.

dumbmatter avatar dumbmatter commented on May 31, 2024

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.

ph-fritsche avatar ph-fritsche commented on May 31, 2024

The problem seems to be here:

this._rawDatabase.processTransactions(); // See if can start right away (async)

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.

dumbmatter avatar dumbmatter commented on May 31, 2024

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.

ph-fritsche avatar ph-fritsche commented on May 31, 2024

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.

ath0mas avatar ath0mas commented on May 31, 2024

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.

ph-fritsche avatar ph-fritsche commented on May 31, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.