Coder Social home page Coder Social logo

Comments (5)

benjamingr avatar benjamingr commented on August 16, 2024

Jest can do it because it transpiles (probably)

We can't do it because queueMicrotask isn't hookable from JS like nextTick, we can use an internal Node API but without connecting a debugger it'd be hard to write it in a stable way

from fake-timers.

fatso83 avatar fatso83 commented on August 16, 2024

We can't do it because queueMicrotask isn't hookable from JS like nextTick, we can use an internal Node API but without connecting a debugger it'd be hard to write it in a stable way

@benjamingr Could you elaborate on this a bit? I am not sure I understand at all. We do take control over queueMicrotask, delegating to clock.nextTick(), so after looking a bit at the code and throwing in some debugging I thought this was just about some bug in our implementation.

I see the clock.jobs array is not cleared. Rather it is doubled up before exiting:

after [
  { func: [Function (anonymous)], args: [], error: null },
  { func: [Function: afterWriteTick], args: [ [Object] ], error: null }
]

I am not quite sure why that second job is there, but you say there is something about the async versions we cannot control?

from fake-timers.

fatso83 avatar fatso83 commented on August 16, 2024

I made a go and I think I found the bug, unless I am missing something substantial. This little diff should be sufficient to get the runAllAsync test working (at least when I tried):

@@ -1578,6 +1578,8 @@ function withGlobal(_global) {
                     function doRun() {
                         originalSetTimeout(function () {
                             try {
+                                runJobs(clock);
+
                                 let numTimers;
                                 if (i < clock.loopLimit) {
                                     if (!clock.timers) {

I cannot claim that I understand all the minute details of fake-timers, but I did see that runJobs, which runs the micro tasks, were missing from the runAllAsync method.

I still see that the clock.jobs array is non-empty (containing that { func: [Function: afterWriteTick] ..} job after the test has completed), but functionally everything seems to be working. Could you explain what this is, @benjamingr ?

from fake-timers.

fatso83 avatar fatso83 commented on August 16, 2024

Fix in #485. I'll move the tests into the right places if I got it right 😄

from fake-timers.

SimenB avatar SimenB commented on August 16, 2024

Closed by ^

from fake-timers.

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.