Skip to content

Commit 56e495d

Browse files
committed
Update Jest
1 parent 73c940a commit 56e495d

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
lines changed

config/jest/environment.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\"",
1616
"e2e": "tasks/e2e.sh",
1717
"start": "node scripts/start.js --debug-template",
18-
"test": "node scripts/test.js --debug-template"
18+
"test": "node scripts/test.js --debug-template --watch"
1919
},
2020
"files": [
2121
"PATENTS",
@@ -31,7 +31,7 @@
3131
"autoprefixer": "6.4.0",
3232
"babel-core": "6.14.0",
3333
"babel-eslint": "6.1.2",
34-
"babel-jest": "14.1.0",
34+
"babel-jest": "15.0.0",
3535
"babel-loader": "6.2.5",
3636
"babel-plugin-transform-class-properties": "6.11.5",
3737
"babel-plugin-transform-object-rest-spread": "6.8.0",
@@ -61,7 +61,7 @@
6161
"html-loader": "0.4.3",
6262
"html-webpack-plugin": "2.22.0",
6363
"http-proxy-middleware": "0.17.0",
64-
"jest": "14.1.0",
64+
"jest": "15.0.0",
6565
"json-loader": "0.5.4",
6666
"object-assign": "4.1.0",
6767
"opn": "4.0.2",

scripts/eject.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ prompt(
4141
path.join('config', 'webpack.config.prod.js'),
4242
path.join('config', 'jest', 'CSSStub.js'),
4343
path.join('config', 'jest', 'FileStub.js'),
44-
path.join('config', 'jest', 'environment.js'),
4544
path.join('config', 'jest', 'transform.js'),
4645
path.join('scripts', 'build.js'),
4746
path.join('scripts', 'start.js'),
@@ -99,17 +98,19 @@ prompt(
9998
});
10099

101100
console.log('Updating scripts');
101+
delete appPackage.scripts['eject'];
102102
Object.keys(appPackage.scripts).forEach(function (key) {
103-
appPackage.scripts[key] = 'node ./scripts/' + key + '.js'
103+
appPackage.scripts[key] = appPackage.scripts[key]
104+
.replace(/react-scripts test/g, 'jest')
105+
.replace(/react-scripts (\w+)/g, 'node scripts/$1.js');
104106
});
105-
delete appPackage.scripts['eject'];
106107

107-
appPackage.scripts.test = 'jest';
108+
// Add Jest config
108109
appPackage.jest = createJestConfig(
109110
filePath => path.join('<rootDir>', filePath)
110111
);
111112

112-
// explicitly specify ESLint config path for editor plugins
113+
// Explicitly specify ESLint config path for editor plugins
113114
appPackage.eslintConfig = {
114115
extends: './config/eslint.js',
115116
};

scripts/init.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
2323
appPackage.devDependencies = appPackage.devDependencies || {};
2424

2525
// Setup the script rules
26-
appPackage.scripts = {};
27-
['start', 'build', 'eject', 'test'].forEach(function(command) {
28-
appPackage.scripts[command] = 'react-scripts ' + command;
29-
});
26+
appPackage.scripts = {
27+
'start': 'react-scripts start',
28+
'build': 'react-scripts build',
29+
'test': 'react-scripts test --watch --env=jsdom',
30+
'eject': 'react-scripts eject'
31+
};
3032

3133
// explicitly specify ESLint config path for editor plugins
3234
appPackage.eslintConfig = {

scripts/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const argv = process.argv.slice(2);
1919
const index = argv.indexOf('--debug-template');
2020
if (index !== -1) {
2121
argv.splice(index, 1);
22+
// When running end-to-end test, disable the watcher
23+
var watchIndex = argv.indexOf('--watch');
24+
if (watchIndex !== -1) {
25+
argv.splice(watchIndex, 1);
26+
}
2227
}
2328

2429
argv.push('--config', JSON.stringify(createJestConfig(

scripts/utils/createJestConfig.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,21 @@
99

1010
module.exports = (resolve, rootDir) => {
1111
const config = {
12-
automock: false,
1312
moduleNameMapper: {
1413
'^[./a-zA-Z0-9$_-]+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'),
1514
'^[./a-zA-Z0-9$_-]+\\.css$': resolve('config/jest/CSSStub.js')
1615
},
17-
persistModuleRegistryBetweenSpecs: true,
1816
scriptPreprocessor: resolve('config/jest/transform.js'),
1917
setupFiles: [
2018
resolve('config/polyfills.js')
2119
],
22-
setupTestFrameworkScriptFile: resolve('config/jest/environment.js'),
23-
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/build/'],
24-
// Allow three popular conventions:
25-
// **/__tests__/*.js
26-
// **/*.test.js
27-
// **/*.spec.js
28-
testRegex: '(__tests__/.*|\\.(test|spec))\\.js$',
29-
testEnvironment: 'node',
30-
verbose: true
20+
testPathIgnorePatterns: [
21+
'<rootDir>/node_modules/',
22+
'<rootDir>/build/',
23+
// GitHub pages now use this directory so assume it's the build:
24+
'<rootDir>/docs/'
25+
],
26+
testEnvironment: 'node'
3127
};
3228
if (rootDir) {
3329
config.rootDir = rootDir;

0 commit comments

Comments
 (0)