remove deprecated promise-polyfill from tests#5210
Open
jantimon wants to merge 5 commits intofacebook:mainfrom
Open
remove deprecated promise-polyfill from tests#5210jantimon wants to merge 5 commits intofacebook:mainfrom
jantimon wants to merge 5 commits intofacebook:mainfrom
Conversation
634672a to
03cdea5
Compare
03cdea5 to
f274350
Compare
tyao1
reviewed
Apr 14, 2026
| TestRenderer.act(() => { | ||
| await TestRenderer.act(async () => { | ||
| GLOBAL_STORE.dispatch({type: 'INCREMENT'}); | ||
| await flushMicrotasks(); |
Contributor
There was a problem hiding this comment.
I have an impression that TestRenderer.act would flush everything. Is flushMicrotasks here necessary?
Contributor
Author
There was a problem hiding this comment.
Good catch!
You're right I could strip a lot of flushMicrotasks() and everything is still green without new act warnings
Early on I hit a few tests that passed alone but broke when running the suite and adding flushMicrotask helped fixing it but looks like it's not needed in many cases
I kept the explicitly added await TestRenderer.act(() => flushMicrotasks()); cases as I think that's easier to understand than await TestRenderer.act(() => {}) but I can also remove them there too if you prefer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test suite previously used
injectPromisePolyfill__DEPRECATEDto replaceglobal.Promisewithpromise-polyfill(a userland implementation). This polyfill scheduled.then()callbacks viasetImmediaterather than native microtasks, which conveniently meantjest.runAllImmediates()would flush promise chains automatically inact()However, this approach has significant downsides:
The polyfill's scheduling semantics differ from real promises. Tests could pass under the polyfill but mask bugs that surface with real Promise implementations
The polyfill (
promise-polyfill@6.1.0) is a stale dependency that all modern environments no longer need, and its presence makes the test infrastructure harder to reason aboutThe old approach silently coupled Relay's
resolveImmediate(which usesPromise.resolve().then(...)) to Jest's fake/mock timer queueThis commit replaces the polyfill with a lightweight
flushMicrotasks()helper that uses the real (not mocked)setImmediatefrom Node'stimersmodule to drain the microtask queue on demandThis will make it easier to add ESM builds for #4548 as it allows to remove outdated polyfills also in the compile flow