Skip to content

Commit

Permalink
Update to Jest 24 (#6278)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lorenzorapetti authored and iansu committed Mar 15, 2019
1 parent eee8491 commit 3be3576
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"get-port": "^4.2.0",
"globby": "^9.1.0",
"husky": "^1.3.1",
"jest": "^23.6.0",
"jest": "^24.5.0",
"lerna": "2.9.1",
"lerna-changelog": "~0.8.2",
"lint-staged": "^8.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-named-asset-import/package.json
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"babel-plugin-tester": "^5.5.1",
"jest": "^23.6.0"
"jest": "^24.5.0"
},
"scripts": {
"test": "jest"
Expand Down
2 changes: 1 addition & 1 deletion packages/confusing-browser-globals/package.json
Expand Up @@ -16,6 +16,6 @@
"index.js"
],
"devDependencies": {
"jest": "23.6.0"
"jest": "24.5.0"
}
}
2 changes: 1 addition & 1 deletion packages/react-dev-utils/package.json
Expand Up @@ -74,7 +74,7 @@
},
"devDependencies": {
"cross-env": "^5.2.0",
"jest": "^23.6.0"
"jest": "^24.5.0"
},
"scripts": {
"test": "cross-env FORCE_COLOR=true jest"
Expand Down
6 changes: 3 additions & 3 deletions packages/react-error-overlay/package.json
Expand Up @@ -35,7 +35,7 @@
"anser": "1.4.8",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"babel-jest": "23.6.0",
"babel-jest": "24.5.0",
"babel-loader": "8.0.5",
"babel-preset-react-app": "^7.0.2",
"chalk": "^2.4.2",
Expand All @@ -49,8 +49,8 @@
"eslint-plugin-react": "7.12.4",
"flow-bin": "^0.63.1",
"html-entities": "1.2.1",
"jest": "23.6.0",
"jest-fetch-mock": "1.6.6",
"jest": "24.5.0",
"jest-fetch-mock": "2.1.1",
"object-assign": "4.1.1",
"promise": "8.0.2",
"raw-loader": "^1.0.0",
Expand Down
@@ -1,7 +1,7 @@
{
"dependencies": {
"bootstrap": "4.1.1",
"jest": "23.6.0",
"jest": "24.5.0",
"node-sass": "4.8.3",
"normalize.css": "7.0.0",
"prop-types": "15.5.6",
Expand Down
7 changes: 3 additions & 4 deletions packages/react-scripts/package.json
Expand Up @@ -30,7 +30,7 @@
"@typescript-eslint/parser": "1.4.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"babel-jest": "23.6.0",
"babel-jest": "24.5.0",
"babel-loader": "8.0.5",
"babel-plugin-named-asset-import": "^0.3.1",
"babel-preset-react-app": "^7.0.2",
Expand All @@ -51,9 +51,8 @@
"fs-extra": "7.0.1",
"html-webpack-plugin": "4.0.0-beta.5",
"identity-obj-proxy": "3.0.0",
"jest": "23.6.0",
"jest-pnp-resolver": "1.0.2",
"jest-resolve": "23.6.0",
"jest": "24.5.0",
"jest-resolve": "24.5.0",
"jest-watch-typeahead": "^0.2.1",
"mini-css-extract-plugin": "0.5.0",
"optimize-css-assets-webpack-plugin": "5.0.1",
Expand Down
14 changes: 4 additions & 10 deletions packages/react-scripts/scripts/utils/createJestConfig.js
Expand Up @@ -24,20 +24,13 @@ module.exports = (resolve, rootDir, isEjecting) => {
const config = {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],

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

setupTestFrameworkScriptFile: setupTestsFile,
setupFilesAfterEnv: setupTestsFile ? [setupTestsFile] : [],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}',
Expand Down Expand Up @@ -77,6 +70,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
'collectCoverageFrom',
'coverageReporters',
'coverageThreshold',
'extraGlobals',
'globalSetup',
'globalTeardown',
'resetMocks',
Expand All @@ -94,13 +88,13 @@ module.exports = (resolve, rootDir, isEjecting) => {
const unsupportedKeys = Object.keys(overrides);
if (unsupportedKeys.length) {
const isOverridingSetupFile =
unsupportedKeys.indexOf('setupTestFrameworkScriptFile') > -1;
unsupportedKeys.indexOf('setupFilesAfterEnv') > -1;

if (isOverridingSetupFile) {
console.error(
chalk.red(
'We detected ' +
chalk.bold('setupTestFrameworkScriptFile') +
chalk.bold('setupFilesAfterEnv') +
' in your package.json.\n\n' +
'Remove it from Jest configuration, and put the initialization code in ' +
chalk.bold('src/setupTests.js') +
Expand Down
16 changes: 8 additions & 8 deletions tasks/e2e-installs.sh
Expand Up @@ -120,7 +120,7 @@ npx create-react-app --version
# ******************************************************************************

cd "$temp_app_path"
npx create-react-app --scripts-version=@latest test-app-dist-tag
npx create-react-app test-app-dist-tag --scripts-version=@latest
cd test-app-dist-tag

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

cd "$temp_app_path"
npx create-react-app --scripts-version=1.0.17 test-app-version-number
npx create-react-app test-app-version-number --scripts-version=1.0.17
cd test-app-version-number

# Check corresponding scripts version is installed.
Expand All @@ -148,7 +148,7 @@ checkDependencies
# ******************************************************************************

cd "$temp_app_path"
npx create-react-app --use-npm --scripts-version=1.0.17 test-use-npm-flag
npx create-react-app test-use-npm-flag --use-npm --scripts-version=1.0.17
cd test-use-npm-flag

# Check corresponding scripts version is installed.
Expand Down Expand Up @@ -196,7 +196,7 @@ CI=true yarn test
# ******************************************************************************

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

# Check corresponding scripts version is installed.
Expand All @@ -209,7 +209,7 @@ checkDependencies
# ******************************************************************************

cd "$temp_app_path"
npx create-react-app --scripts-version=react-scripts-fork test-app-fork
npx create-react-app test-app-fork --scripts-version=react-scripts-fork
cd test-app-fork

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

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

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

# Check corresponding scripts version is installed.
Expand Down
2 changes: 1 addition & 1 deletion tasks/e2e-kitchensink-eject.sh
Expand Up @@ -100,7 +100,7 @@ git clean -df

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

# Install the test module
cd "$temp_module_path"
Expand Down
2 changes: 1 addition & 1 deletion tasks/e2e-kitchensink.sh
Expand Up @@ -100,7 +100,7 @@ git clean -df

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

# Install the test module
cd "$temp_module_path"
Expand Down

0 comments on commit 3be3576

Please sign in to comment.