Skip to content

Commit cb2dcd3

Browse files
kelsetfacebook-github-bot
authored andcommitted
feat(jest): move Jest config to use a custom react-native Jest env (#34971)
Summary: This PR is the follow up to the conversation started here by SimenB: react-native-community/discussions-and-proposals#509 Basically, we want to move RN to use its own custom environment so that we can tweak it going forward - this PR in fact only sets up the groundwork for that; robhogan mentioned that with this in place, Meta engineers can > iterate on it (with jest-environment-node as a starting point) against our internal product tests This is also connected to Rob's work to bring Jest 29 into the codebase #34724 and my "mirror" PR to bring template in main up to the same version (#34972) ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [General] [Changed] - move Jest config to use a custom react-native Jest env Pull Request resolved: #34971 Test Plan: Tested that `yarn test` in main works fine after the changes; CI and Meta's internal CI will also serve the purpose of verifying that it works (but there's no reason not to since it's still pretty much just relying on `node`). Reviewed By: huntie Differential Revision: D40379760 Pulled By: robhogan fbshipit-source-id: 2c6d0bc86d337fda9befce0799bda2f56cc4466c
1 parent 633498f commit cb2dcd3

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

jest-preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ module.exports = {
2424
'node_modules/(?!((jest-)?react-native|@react-native(-community)?)/)',
2525
],
2626
setupFiles: [require.resolve('./jest/setup.js')],
27-
testEnvironment: 'node',
27+
testEnvironment: require.resolve('./jest/react-native-env.js'),
2828
};

jest/react-native-env.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const NodeEnv = require('jest-environment-node').TestEnvironment;
13+
14+
module.exports = class ReactNativeEnv extends NodeEnv {
15+
// this is where we'll add our custom logic
16+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"base64-js": "^1.1.2",
121121
"event-target-shim": "^5.0.1",
122122
"invariant": "^2.2.4",
123+
"jest-environment-node": "^29.0.3",
123124
"jsc-android": "^250230.2.1",
124125
"memoize-one": "^5.0.0",
125126
"metro-react-native-babel-transformer": "0.72.3",

0 commit comments

Comments
 (0)