Skip to content
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

Stop polyfilling Promise in Jest tests #34659

Closed
wants to merge 3 commits into from

Conversation

robhogan
Copy link
Contributor

Summary:
We've used this Promise polyfill in Jest setup since at least 2015 (3ff3987), when native Promise implementations were either non-existent or new and unstable. We no longer need it.

It causes issues with "modern" timers in Jest, as documented in:

It can also obscure real issues due to its default silent handling of uncaught rejections, eg: D39418412.

Changelog:
[General][Changed] - Don't polyfill Promise in Jest setup

Differential Revision: D39417597

Differential Revision: D39418412

fbshipit-source-id: e2b76fa91df28ce1418a487f45dbeb590a66d184
Differential Revision: D39418413

fbshipit-source-id: 7b4c96c62ada4ef7cd5231b305c926068026df38
Summary:
We've used this Promise polyfill in Jest setup since at least 2015 ([`3ff3987`](facebook@3ff3987)), when native Promise implementations were either non-existent or new and unstable. We no longer need it.

It causes issues with "modern" timers in Jest, as documented in:
 - facebook#29303
 - jestjs/jest#10221

It can also obscure real issues due to its default silent handling of uncaught rejections, eg: D39418412.

Changelog:
[General][Changed] - Don't polyfill Promise in Jest setup

Differential Revision: D39417597

fbshipit-source-id: 1773032343f914a37789c7bc43760838f2d86d31
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Sep 11, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D39417597

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,643,504 +471
android hermes armeabi-v7a 7,055,602 +432
android hermes x86 7,945,085 +500
android hermes x86_64 7,917,120 +416
android jsc arm64-v8a 9,516,021 +0
android jsc armeabi-v7a 8,291,634 +0
android jsc x86 9,455,349 +0
android jsc x86_64 10,046,429 +0

Base commit: 4e70376
Branch: main

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 4e70376
Branch: main

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @robhogan in f1fdc8b.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Sep 12, 2022
facebook-github-bot pushed a commit that referenced this pull request Sep 12, 2022
Summary:
Jest 27 [flips defaults](https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults), making "modern" fake timers (ie, `sinonjs/fake-timers`) the default, over "legacy", which we currently use.

We're not quite ready for modern timers yet, partly due to Promise polyfills (#34659), and also some internal issues with specific tests.

This makes our use of legacy timers explicit in preparation for an update to Jest. A switch to modern timers may follow later.

Changelog:
[Internal][Changed] - Prepare for Jest 27+ by making legacy fake timer use explicit

Reviewed By: jacdebug

Differential Revision: D39383719

fbshipit-source-id: 6a3dc6f8547cc76f7702a5a39c9b30a184303f17
@robhogan robhogan deleted the export-D39417597 branch February 15, 2023 11:11
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
Pull Request resolved: facebook#34659

We've used this Promise polyfill in Jest setup since at least 2015 ([`3ff3987`](facebook@3ff3987)), when native Promise implementations were either non-existent or new and unstable. We no longer need it.

It causes issues with "modern" timers in Jest, as documented in:
 - facebook#29303
 - jestjs/jest#10221

It can also obscure real issues due to its default silent handling of uncaught rejections, eg: D39418412.

Changelog:
[General][Changed] - Don't polyfill Promise in Jest setup

Reviewed By: huntie

Differential Revision: D39417597

fbshipit-source-id: d12433ed66c06a402632c2e1d525aad112ef9b0c
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
Jest 27 [flips defaults](https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults), making "modern" fake timers (ie, `sinonjs/fake-timers`) the default, over "legacy", which we currently use.

We're not quite ready for modern timers yet, partly due to Promise polyfills (facebook#34659), and also some internal issues with specific tests.

This makes our use of legacy timers explicit in preparation for an update to Jest. A switch to modern timers may follow later.

Changelog:
[Internal][Changed] - Prepare for Jest 27+ by making legacy fake timer use explicit

Reviewed By: jacdebug

Differential Revision: D39383719

fbshipit-source-id: 6a3dc6f8547cc76f7702a5a39c9b30a184303f17
@professorkolik
Copy link

This is a breaking change, any hint how we should handle it now?

@nero2009
Copy link

nero2009 commented Aug 7, 2023

This is causing my tests that were passing with "jest": "^26.6.3" to error out with error.

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
TypeError: _reactNative.Alert.alert is not a function

Please is there a fix for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants