Skip to content

Commit 3be3576

Browse files
lorenzorapettiiansu
authored andcommitted
Update to Jest 24 (#6278)
* Update to jest 24 * Add notice about pnpResolver.js * Formatting * Fix linting * Update to jest 24.1.0 * Update jest-pnp-resolver * Swap create-react-app params in e2e scripts * Add extraGlobals to supportedKeys * Bump jest to 24.3.1 * Bump jest to 24.4.0 * Bumb jest to 24.5.0 * Update template dependencies jest to 24.5.0 * Debug failing test * Remove jest-pnp-resolver * Remove console.log * Revert yarn.lock.cached
1 parent eee8491 commit 3be3576

File tree

11 files changed

+25
-32
lines changed

11 files changed

+25
-32
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"get-port": "^4.2.0",
2626
"globby": "^9.1.0",
2727
"husky": "^1.3.1",
28-
"jest": "^23.6.0",
28+
"jest": "^24.5.0",
2929
"lerna": "2.9.1",
3030
"lerna-changelog": "~0.8.2",
3131
"lint-staged": "^8.0.4",

packages/babel-plugin-named-asset-import/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"babel-plugin-tester": "^5.5.1",
19-
"jest": "^23.6.0"
19+
"jest": "^24.5.0"
2020
},
2121
"scripts": {
2222
"test": "jest"

packages/confusing-browser-globals/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"index.js"
1717
],
1818
"devDependencies": {
19-
"jest": "23.6.0"
19+
"jest": "24.5.0"
2020
}
2121
}

packages/react-dev-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"devDependencies": {
7676
"cross-env": "^5.2.0",
77-
"jest": "^23.6.0"
77+
"jest": "^24.5.0"
7878
},
7979
"scripts": {
8080
"test": "cross-env FORCE_COLOR=true jest"

packages/react-error-overlay/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"anser": "1.4.8",
3636
"babel-core": "7.0.0-bridge.0",
3737
"babel-eslint": "10.0.1",
38-
"babel-jest": "23.6.0",
38+
"babel-jest": "24.5.0",
3939
"babel-loader": "8.0.5",
4040
"babel-preset-react-app": "^7.0.2",
4141
"chalk": "^2.4.2",
@@ -49,8 +49,8 @@
4949
"eslint-plugin-react": "7.12.4",
5050
"flow-bin": "^0.63.1",
5151
"html-entities": "1.2.1",
52-
"jest": "23.6.0",
53-
"jest-fetch-mock": "1.6.6",
52+
"jest": "24.5.0",
53+
"jest-fetch-mock": "2.1.1",
5454
"object-assign": "4.1.1",
5555
"promise": "8.0.2",
5656
"raw-loader": "^1.0.0",

packages/react-scripts/fixtures/kitchensink/.template.dependencies.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"bootstrap": "4.1.1",
4-
"jest": "23.6.0",
4+
"jest": "24.5.0",
55
"node-sass": "4.8.3",
66
"normalize.css": "7.0.0",
77
"prop-types": "15.5.6",

packages/react-scripts/package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@typescript-eslint/parser": "1.4.1",
3131
"babel-core": "7.0.0-bridge.0",
3232
"babel-eslint": "10.0.1",
33-
"babel-jest": "23.6.0",
33+
"babel-jest": "24.5.0",
3434
"babel-loader": "8.0.5",
3535
"babel-plugin-named-asset-import": "^0.3.1",
3636
"babel-preset-react-app": "^7.0.2",
@@ -51,9 +51,8 @@
5151
"fs-extra": "7.0.1",
5252
"html-webpack-plugin": "4.0.0-beta.5",
5353
"identity-obj-proxy": "3.0.0",
54-
"jest": "23.6.0",
55-
"jest-pnp-resolver": "1.0.2",
56-
"jest-resolve": "23.6.0",
54+
"jest": "24.5.0",
55+
"jest-resolve": "24.5.0",
5756
"jest-watch-typeahead": "^0.2.1",
5857
"mini-css-extract-plugin": "0.5.0",
5958
"optimize-css-assets-webpack-plugin": "5.0.1",

packages/react-scripts/scripts/utils/createJestConfig.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ module.exports = (resolve, rootDir, isEjecting) => {
2424
const config = {
2525
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
2626

27-
// TODO: this breaks Yarn PnP on eject.
28-
// But we can't simply emit this because it'll be an absolute path.
29-
// The proper fix is to write jest.config.js on eject instead of a package.json key.
30-
// Then these can always stay as require.resolve()s.
31-
resolver: isEjecting
32-
? 'jest-pnp-resolver'
33-
: require.resolve('jest-pnp-resolver'),
3427
setupFiles: [
3528
isEjecting
3629
? 'react-app-polyfill/jsdom'
3730
: require.resolve('react-app-polyfill/jsdom'),
3831
],
3932

40-
setupTestFrameworkScriptFile: setupTestsFile,
33+
setupFilesAfterEnv: setupTestsFile ? [setupTestsFile] : [],
4134
testMatch: [
4235
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
4336
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}',
@@ -77,6 +70,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
7770
'collectCoverageFrom',
7871
'coverageReporters',
7972
'coverageThreshold',
73+
'extraGlobals',
8074
'globalSetup',
8175
'globalTeardown',
8276
'resetMocks',
@@ -94,13 +88,13 @@ module.exports = (resolve, rootDir, isEjecting) => {
9488
const unsupportedKeys = Object.keys(overrides);
9589
if (unsupportedKeys.length) {
9690
const isOverridingSetupFile =
97-
unsupportedKeys.indexOf('setupTestFrameworkScriptFile') > -1;
91+
unsupportedKeys.indexOf('setupFilesAfterEnv') > -1;
9892

9993
if (isOverridingSetupFile) {
10094
console.error(
10195
chalk.red(
10296
'We detected ' +
103-
chalk.bold('setupTestFrameworkScriptFile') +
97+
chalk.bold('setupFilesAfterEnv') +
10498
' in your package.json.\n\n' +
10599
'Remove it from Jest configuration, and put the initialization code in ' +
106100
chalk.bold('src/setupTests.js') +

tasks/e2e-installs.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ npx create-react-app --version
120120
# ******************************************************************************
121121

122122
cd "$temp_app_path"
123-
npx create-react-app --scripts-version=@latest test-app-dist-tag
123+
npx create-react-app test-app-dist-tag --scripts-version=@latest
124124
cd test-app-dist-tag
125125

126126
# Check corresponding scripts version is installed and no TypeScript is present.
@@ -135,7 +135,7 @@ checkDependencies
135135
# ******************************************************************************
136136

137137
cd "$temp_app_path"
138-
npx create-react-app --scripts-version=1.0.17 test-app-version-number
138+
npx create-react-app test-app-version-number --scripts-version=1.0.17
139139
cd test-app-version-number
140140

141141
# Check corresponding scripts version is installed.
@@ -148,7 +148,7 @@ checkDependencies
148148
# ******************************************************************************
149149

150150
cd "$temp_app_path"
151-
npx create-react-app --use-npm --scripts-version=1.0.17 test-use-npm-flag
151+
npx create-react-app test-use-npm-flag --use-npm --scripts-version=1.0.17
152152
cd test-use-npm-flag
153153

154154
# Check corresponding scripts version is installed.
@@ -196,7 +196,7 @@ CI=true yarn test
196196
# ******************************************************************************
197197

198198
cd "$temp_app_path"
199-
npx create-react-app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-1.0.17.tgz test-app-tarball-url
199+
npx create-react-app test-app-tarball-url --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-1.0.17.tgz
200200
cd test-app-tarball-url
201201

202202
# Check corresponding scripts version is installed.
@@ -209,7 +209,7 @@ checkDependencies
209209
# ******************************************************************************
210210

211211
cd "$temp_app_path"
212-
npx create-react-app --scripts-version=react-scripts-fork test-app-fork
212+
npx create-react-app test-app-fork --scripts-version=react-scripts-fork
213213
cd test-app-fork
214214

215215
# Check corresponding scripts version is installed.
@@ -221,7 +221,7 @@ exists node_modules/react-scripts-fork
221221

222222
cd "$temp_app_path"
223223
# we will install a non-existing package to simulate a failed installataion.
224-
npx create-react-app --scripts-version=`date +%s` test-app-should-not-exist || true
224+
npx create-react-app test-app-should-not-exist --scripts-version=`date +%s` || true
225225
# confirm that the project files were deleted
226226
test ! -e test-app-should-not-exist/package.json
227227
test ! -d test-app-should-not-exist/node_modules
@@ -234,7 +234,7 @@ cd "$temp_app_path"
234234
mkdir test-app-should-remain
235235
echo '## Hello' > ./test-app-should-remain/README.md
236236
# we will install a non-existing package to simulate a failed installataion.
237-
npx create-react-app --scripts-version=`date +%s` test-app-should-remain || true
237+
npx create-react-app test-app-should-remain --scripts-version=`date +%s` || true
238238
# confirm the file exist
239239
test -e test-app-should-remain/README.md
240240
# confirm only README.md and error log are the only files in the directory
@@ -248,7 +248,7 @@ fi
248248

249249
cd $temp_app_path
250250
curl "https://registry.npmjs.org/@enoah_netzach/react-scripts/-/react-scripts-0.9.0.tgz" -o enoah-scripts-0.9.0.tgz
251-
npx create-react-app --scripts-version=$temp_app_path/enoah-scripts-0.9.0.tgz test-app-scoped-fork-tgz
251+
npx create-react-app test-app-scoped-fork-tgz --scripts-version=$temp_app_path/enoah-scripts-0.9.0.tgz
252252
cd test-app-scoped-fork-tgz
253253

254254
# Check corresponding scripts version is installed.

tasks/e2e-kitchensink-eject.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ git clean -df
100100

101101
# Install the app in a temporary location
102102
cd $temp_app_path
103-
npx create-react-app --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink test-kitchensink
103+
npx create-react-app test-kitchensink --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink
104104

105105
# Install the test module
106106
cd "$temp_module_path"

tasks/e2e-kitchensink.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ git clean -df
100100

101101
# Install the app in a temporary location
102102
cd $temp_app_path
103-
npx create-react-app --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink test-kitchensink
103+
npx create-react-app test-kitchensink --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink
104104

105105
# Install the test module
106106
cd "$temp_module_path"

0 commit comments

Comments
 (0)