-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose way to run just microtasks #147
Comments
We also have the inverse in Jest - just running macrotasks. Another diff in this regard is that our See Jests docs (from the linked paragraph and down) for a rundown of what we do today. http://facebook.github.io/jest/docs/en/jest-object.html#jestrunallticks |
I don't understand why running just macroticks and not microticks makes sense. (Since it would never be regular execution flow). Any motivation on why this is required? |
@cpojer (who's on vacation, so might be a bit before we get an answer) any particular use cases for this? |
I think running both in one call works fine with me, but I cannot confirm without testing this on the FB codebase. I can check usage of advanceTimersByTime at FB in early January to confirm. |
Taking a look Update: PR |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not really stale, waiting for review on PR still |
@benjamingr I haven't noticed the PR at all: do you have all required privileges to merge now, btw? |
@benjamingr You had been added to the Don't be a stranger to pestering me on email, btw, if I should be blocking something. |
@fatso83 congratulations! Really no rush here or sense of urgency - family first and thanks :) |
@benjamingr I think I've found an issue with the implementation - it doesn't guard against recursion in the same way the timers do. Jest has the following test, which never completes when using this new function: it('throws before allowing infinite recursion', () => {
const global = {
Date,
clearTimeout,
process: {
nextTick: () => {},
},
setTimeout,
};
const timers = new FakeTimers({
global,
maxLoops: 100,
moduleMocker,
timerConfig,
});
timers.useFakeTimers();
global.process.nextTick(function infinitelyRecursingCallback() {
global.process.nextTick(infinitelyRecursingCallback);
});
expect(() => {
timers.runAllTicks();
}).toThrow(
new Error(
"Ran 100 ticks, and there are still more! Assuming we've hit an " +
'infinite recursion and bailing out...',
),
);
}) I think |
process.nextTick(function foo() { process.nextTick(foo); }); // freezes Node Since Note that I'm not disagreeing with the idea of adding this - We can add bailout logic if you think it's important (or use loopLimit). I was just explaining why it wasn't the case for #156 - runJobs could certainly handle this case. |
Going to reopen since it's being discussed |
Interesting, didn't know that! A bail seems more useful than a freeze, especially in a testing situation (as it prevents tests from timing out), but matching real behavior (beyond manipulating time) is really compelling as well. @cpojer thoughts on this? |
Regardless of what's better, we cannot change behavior for existing Jest tests at this time. If we want to use lolex for Jest, the initial version must 100% match what Jest has right now. We can make incremental breaking changes later. |
This is fixed in #172 |
For
jest
integration - we should consider exposing a way to run only microtasks (nextTick) - this effectively means exportingrunJobs
.There are no other things currently shimmed in lolex with microtask semantics (promises - no because of async functions,
MutationObserver
s no). Since everything defers based on nextTick semantics that should be fine for jest inside jsdom.CC @SimenB
The text was updated successfully, but these errors were encountered: