forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest: Fix jestjs/jest#10221 locally.
This is much easier and less invasive than forking React Native, as we considered in zulip/react-native#5. The idea comes from Greg on a video call, with a code example provided by a @testing-library/react-native contributor [1]. Follow that example, with tweaks for our project -- using camelCase for the file names, putting the new files in our `jest` directory, and adding a TODO mentioning that we'd maybe like to get back to using jest-expo, which wraps React Native's preset. [1] jestjs/jest#10221 (comment), which links to sbalay/without_await@64a76486f.
- Loading branch information
1 parent
cfe3314
commit ac4bb3f
Showing
4 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* The preset we're making tweaks to. | ||
*/ | ||
// TODO: Switch back to jest-expo (i.e., use 'jest-expo/jest-preset') | ||
// when it has a version that depends on Jest 26, not Jest 25. | ||
const basePreset = require('react-native/jest-preset'); | ||
|
||
module.exports = { | ||
...basePreset, | ||
setupFiles: [ | ||
// Until facebook/jest#10221 is resolved, sandwich the faulty | ||
// logic in react-native's preset (in which `global.Promise` is | ||
// harmfully replaced) with a fix. See | ||
// https://github.com/facebook/jest/issues/10221#issuecomment-714335771. | ||
require.resolve('./savePromise.js'), | ||
...basePreset.setupFiles, | ||
require.resolve('./restorePromise.js'), | ||
], | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// For facebook/jest#10221. After savePromise.js and Jest's setup | ||
// files have run, restore the natural value of `global.Promise`. | ||
global.Promise = global.originalPromise; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// For facebook/jest#10221. Before Jest's setup files have run, take | ||
// note of what the natural value of `global.Promise` is, so we can | ||
// restore it in restorePromise.js. | ||
global.originalPromise = Promise; |