Skip to content

Update Jest #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions config/jest/environment.js

This file was deleted.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\"",
"e2e": "tasks/e2e.sh",
"start": "node scripts/start.js --debug-template",
"test": "node scripts/test.js --debug-template"
"test": "node scripts/test.js --debug-template --watch --env=jsdom"
},
"files": [
"PATENTS",
Expand All @@ -31,7 +31,7 @@
"autoprefixer": "6.4.0",
"babel-core": "6.14.0",
"babel-eslint": "6.1.2",
"babel-jest": "14.1.0",
"babel-jest": "15.0.0",
"babel-loader": "6.2.5",
"babel-plugin-transform-class-properties": "6.11.5",
"babel-plugin-transform-object-rest-spread": "6.8.0",
Expand Down Expand Up @@ -61,7 +61,7 @@
"html-loader": "0.4.3",
"html-webpack-plugin": "2.22.0",
"http-proxy-middleware": "0.17.0",
"jest": "14.1.0",
"jest": "15.0.0",
"json-loader": "0.5.4",
"object-assign": "4.1.0",
"opn": "4.0.2",
Expand All @@ -80,8 +80,7 @@
"devDependencies": {
"bundle-deps": "1.0.0",
"react": "^15.3.0",
"react-dom": "^15.3.0",
"react-test-renderer": "^15.3.0"
"react-dom": "^15.3.0"
},
"optionalDependencies": {
"fsevents": "1.0.14"
Expand Down
11 changes: 6 additions & 5 deletions scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ prompt(
path.join('config', 'webpack.config.prod.js'),
path.join('config', 'jest', 'CSSStub.js'),
path.join('config', 'jest', 'FileStub.js'),
path.join('config', 'jest', 'environment.js'),
path.join('config', 'jest', 'transform.js'),
path.join('scripts', 'build.js'),
path.join('scripts', 'start.js'),
Expand Down Expand Up @@ -99,17 +98,19 @@ prompt(
});

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

appPackage.scripts.test = 'jest';
// Add Jest config
appPackage.jest = createJestConfig(
filePath => path.join('<rootDir>', filePath)
);

// explicitly specify ESLint config path for editor plugins
// Explicitly specify ESLint config path for editor plugins
appPackage.eslintConfig = {
extends: './config/eslint.js',
};
Expand Down
11 changes: 6 additions & 5 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
appPackage.devDependencies = appPackage.devDependencies || {};

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

// explicitly specify ESLint config path for editor plugins
appPackage.eslintConfig = {
Expand Down Expand Up @@ -69,7 +71,6 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
'install',
'react',
'react-dom',
'react-test-renderer',
'--save',
verbose && '--verbose'
].filter(function(e) { return e; });
Expand Down
19 changes: 16 additions & 3 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ const paths = require('../config/paths');

const argv = process.argv.slice(2);

const index = argv.indexOf('--debug-template');
if (index !== -1) {
argv.splice(index, 1);
// Don't pass this option to Jest
const debugTemplateIndex = argv.indexOf('--debug-template');
if (debugTemplateIndex !== -1) {
argv.splice(debugTemplateIndex, 1);
}

// Don't pass this option to Jest either
const smokeTestIndex = argv.indexOf('--smoke-test');
if (smokeTestIndex !== -1) {
argv.splice(smokeTestIndex, 1);

// When running end-to-end test, disable watching
const watchIndex = argv.indexOf('--watch');
if (watchIndex !== -1) {
argv.splice(watchIndex, 1);
}
}

argv.push('--config', JSON.stringify(createJestConfig(
Expand Down
17 changes: 3 additions & 14 deletions scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,14 @@

module.exports = (resolve, rootDir) => {
const config = {
automock: false,
moduleNameMapper: {
'^[./a-zA-Z0-9$_-]+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'),
'^[./a-zA-Z0-9$_-]+\\.css$': resolve('config/jest/CSSStub.js')
},
persistModuleRegistryBetweenSpecs: true,
scriptPreprocessor: resolve('config/jest/transform.js'),
setupFiles: [
resolve('config/polyfills.js')
],
setupTestFrameworkScriptFile: resolve('config/jest/environment.js'),
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/build/'],
// Allow three popular conventions:
// **/__tests__/*.js
// **/*.test.js
// **/*.spec.js
testRegex: '(__tests__/.*|\\.(test|spec))\\.js$',
testEnvironment: 'node',
verbose: true
setupFiles: [resolve('config/polyfills.js')],
testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'],
testEnvironment: 'node'
};
if (rootDir) {
config.rootDir = rootDir;
Expand Down
10 changes: 6 additions & 4 deletions tasks/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ test -e build/static/media/*.svg
test -e build/favicon.ico

# Run tests
npm run test
test -e src/__tests__/__snapshots__/App-test.js.snap
npm test --smoke-test
# Uncomment when snapshot testing is enabled by default:
# test -e src/__tests__/__snapshots__/App-test.js.snap

# Test the server
npm start -- --smoke-test
Expand All @@ -118,8 +119,9 @@ test -e build/static/media/*.svg
test -e build/favicon.ico

# Run tests
npm run test
test -e src/__tests__/__snapshots__/App-test.js.snap
npm test -- --smoke-test
# Uncomment when snapshot testing is enabled by default:
# test -e src/__tests__/__snapshots__/App-test.js.snap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean App.spec.js here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's disabled this doesn't really matter—when we re-add it we can revisit naming and where we put it.


# Test the server
npm start -- --smoke-test
Expand Down
10 changes: 10 additions & 0 deletions template/src/App.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

describe('App', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
});
11 changes: 0 additions & 11 deletions template/src/__tests__/App-test.js

This file was deleted.