Skip to content
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

Make coverage and snapshot Jest options overridable in package.json #1830

Merged
merged 7 commits into from
May 16, 2017
Merged
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
47 changes: 46 additions & 1 deletion packages/react-scripts/scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

const fs = require('fs');
const chalk = require('chalk');
const paths = require('../../config/paths');

module.exports = (resolve, rootDir, isEjecting) => {
Expand All @@ -27,7 +28,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
setupTestFrameworkScriptFile: setupTestsFile,
testMatch: [
'<rootDir>/src/**/__tests__/**/*.js?(x)',
'<rootDir>/src/**/?(*.)(spec|test).js?(x)'
'<rootDir>/src/**/?(*.)(spec|test).js?(x)',
],
testEnvironment: 'node',
testURL: 'http://localhost',
Expand All @@ -46,5 +47,49 @@ module.exports = (resolve, rootDir, isEjecting) => {
if (rootDir) {
config.rootDir = rootDir;
}
const overrides = Object.assign({}, require(paths.appPackageJson).jest);
if (overrides) {
if (overrides.collectCoverageFrom) {
config.collectCoverageFrom = overrides.collectCoverageFrom;
delete overrides.collectCoverageFrom;
}
if (overrides.coverageReporters) {
config.coverageReporters = overrides.coverageReporters;
delete overrides.coverageReporters;
}
if (overrides.coverageThreshold) {
config.coverageThreshold = overrides.coverageThreshold;
delete overrides.coverageThreshold;
}
if (overrides.snapshotSerializers) {
config.snapshotSerializers = overrides.snapshotSerializers;
delete overrides.snapshotSerializers;
}
const unsupportedKeys = Object.keys(overrides);
if (unsupportedKeys.length) {
console.error(
chalk.red(
'By default, Create React App only supports overriding the following Jest options: ' +
chalk.bold('collectCoverageFrom') +
', ' +
chalk.bold('coverageReporters') +
', ' +
chalk.bold('coverageThreshold') +
', and ' +
chalk.bold('snapshotSerializers') +
'.' +
'\n\nThe following options in your package.json Jest configuration are not currently supported by Create React App:\n\n' +
unsupportedKeys
.map(key => chalk.bold(' \u2022 ' + key))
.join('\n') +
'\n\nIf you wish to override other options, you need to eject from the default setup. ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe suggest opening an issue if there's a compelling enough reason to allow overriding?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure people will do it regardless 😛

'You can do so by running ' +
chalk.bold('npm run eject') +
' but remember that this is a one-way operation.\n'
)
);
process.exit(1);
}
}
return config;
};