-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Unify serverAct helpers #33327
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
Unify serverAct helpers #33327
Conversation
Jest prints these as diffs otherwise which makes it harder to debug.
Patch using timer instead
// those will also fire now, too, which is not ideal. (The public | ||
// version of `act` doesn't do this.) For this reason, we should try | ||
// to avoid using timers in our internal tests. | ||
j.runAllTicks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getTimerCount()
includes process.nextTick
mocks but runOnlyPendingTimers()
alone doesn't run them. We don't use it ourselves but JSDOM uses it internally. This was driving me insane debugging this infinite loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we waitForMicrotasks
here before running timers. that probably more closely approximates a real loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could continue the loop if runAllTicks changes the timer count. It's unfortunate you can't know if ticks ran. unless there isa. getTickCount or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically yes, but we also don't wait between multiple timers or multiple ticks.
What we really want is the runAllTimersAsync()
but for whatever reason that's not available on the legacy mocks. I guess we'd have to upgrade to newer mock timers.
Comparing: 3710c4d...30dafe0 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
These are not flushed by runOnlyPendingTimers but are included in the fake timer count so this would infinite loop as soon as you had a tick.
// those will also fire now, too, which is not ideal. (The public | ||
// version of `act` doesn't do this.) For this reason, we should try | ||
// to avoid using timers in our internal tests. | ||
j.runAllTicks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we waitForMicrotasks
here before running timers. that probably more closely approximates a real loop
// those will also fire now, too, which is not ideal. (The public | ||
// version of `act` doesn't do this.) For this reason, we should try | ||
// to avoid using timers in our internal tests. | ||
j.runAllTicks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could continue the loop if runAllTicks changes the timer count. It's unfortunate you can't know if ticks ran. unless there isa. getTickCount or something
This uses the richer
serverAct
helper that we already use in other tests.This avoids using the
Scheduler
. We don't use that package on the server so it doesn't make sense to simulate going through it. Additionally, we really should be getting rid of it on the client too to favorpostTask
polyfills.