mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-27 00:14:57 +08:00
Enhance Jest config error for setupTestFrameworkScriptFile (#3512)
* Enhance Jest config error for `setupTestFrameworkScriptFile` I wasn't aware of the fact that users of c-r-a could just define `src/setupTests.js` and it would be configured with Jest - I nearly ejected before I found a GitHub issue that confirmed this functionality. I thought it might be a nice idea to add it to the error about Jest config overrides to stop others ejecting when they don't need to. * Change the order of Jest config errors. * Show different error for `setupTestFrameworkScriptFile` * Tweak the message
This commit is contained in:
committed by
Dan Abramov
parent
a3d002e0b3
commit
7969b48cd0
@@ -75,25 +75,44 @@ module.exports = (resolve, rootDir, isEjecting) => {
|
||||
});
|
||||
const unsupportedKeys = Object.keys(overrides);
|
||||
if (unsupportedKeys.length) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
'Out of the box, Create React App only supports overriding ' +
|
||||
'these Jest options:\n\n' +
|
||||
supportedKeys.map(key => chalk.bold(' \u2022 ' + key)).join('\n') +
|
||||
'.\n\n' +
|
||||
'These 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 Jest options, you need to ' +
|
||||
'eject from the default setup. You can do so by running ' +
|
||||
chalk.bold('npm run eject') +
|
||||
' but remember that this is a one-way operation. ' +
|
||||
'You may also file an issue with Create React App to discuss ' +
|
||||
'supporting more options out of the box.\n'
|
||||
)
|
||||
);
|
||||
const isOverridingSetupFile =
|
||||
unsupportedKeys.indexOf('setupTestFrameworkScriptFile') > -1;
|
||||
|
||||
if (isOverridingSetupFile) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
'We detected ' +
|
||||
chalk.bold('setupTestFrameworkScriptFile') +
|
||||
' in your package.json.\n\n' +
|
||||
'Remove it from Jest configuration, and put the initialization code in ' +
|
||||
chalk.bold('src/setupTests.js') +
|
||||
'.\nThis file will be loaded automatically.\n'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
console.error(
|
||||
chalk.red(
|
||||
'\nOut of the box, Create React App only supports overriding ' +
|
||||
'these Jest options:\n\n' +
|
||||
supportedKeys
|
||||
.map(key => chalk.bold(' \u2022 ' + key))
|
||||
.join('\n') +
|
||||
'.\n\n' +
|
||||
'These 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 Jest options, you need to ' +
|
||||
'eject from the default setup. You can do so by running ' +
|
||||
chalk.bold('npm run eject') +
|
||||
' but remember that this is a one-way operation. ' +
|
||||
'You may also file an issue with Create React App to discuss ' +
|
||||
'supporting more options out of the box.\n'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user