Skip to content

remove deprecated promise-polyfill from tests#5210

Open
jantimon wants to merge 5 commits intofacebook:mainfrom
jantimon:remove-promise-polyfill
Open

remove deprecated promise-polyfill from tests#5210
jantimon wants to merge 5 commits intofacebook:mainfrom
jantimon:remove-promise-polyfill

Conversation

@jantimon
Copy link
Copy Markdown
Contributor

@jantimon jantimon commented Mar 19, 2026

The test suite previously used injectPromisePolyfill__DEPRECATED to replace global.Promise with promise-polyfill (a userland implementation). This polyfill scheduled .then() callbacks via setImmediate rather than native microtasks, which conveniently meant jest.runAllImmediates() would flush promise chains automatically in act()

However, this approach has significant downsides:

  1. The polyfill's scheduling semantics differ from real promises. Tests could pass under the polyfill but mask bugs that surface with real Promise implementations

  2. 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 about

  3. The old approach silently coupled Relay's resolveImmediate (which uses Promise.resolve().then(...)) to Jest's fake/mock timer queue

This commit replaces the polyfill with a lightweight flushMicrotasks() helper that uses the real (not mocked) setImmediate from Node's timers module to drain the microtask queue on demand

This will make it easier to add ESM builds for #4548 as it allows to remove outdated polyfills also in the compile flow

@meta-cla meta-cla bot added the CLA Signed label Mar 19, 2026
@jantimon jantimon force-pushed the remove-promise-polyfill branch 2 times, most recently from 634672a to 03cdea5 Compare April 14, 2026 08:31
@jantimon jantimon force-pushed the remove-promise-polyfill branch from 03cdea5 to f274350 Compare April 14, 2026 08:34
TestRenderer.act(() => {
await TestRenderer.act(async () => {
GLOBAL_STORE.dispatch({type: 'INCREMENT'});
await flushMicrotasks();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an impression that TestRenderer.act would flush everything. Is flushMicrotasks here necessary?

Copy link
Copy Markdown
Contributor Author

@jantimon jantimon Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants