Skip to content

Commit 27bace9

Browse files
jackfranklinakstuhl
authored andcommitted
Enhance Jest config error for setupTestFrameworkScriptFile (facebook#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
1 parent f622673 commit 27bace9

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

packages/react-scripts/scripts/utils/createJestConfig.js

+38-19
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,44 @@ module.exports = (resolve, rootDir, isEjecting) => {
7575
});
7676
const unsupportedKeys = Object.keys(overrides);
7777
if (unsupportedKeys.length) {
78-
console.error(
79-
chalk.red(
80-
'Out of the box, Create React App only supports overriding ' +
81-
'these Jest options:\n\n' +
82-
supportedKeys.map(key => chalk.bold(' \u2022 ' + key)).join('\n') +
83-
'.\n\n' +
84-
'These options in your package.json Jest configuration ' +
85-
'are not currently supported by Create React App:\n\n' +
86-
unsupportedKeys
87-
.map(key => chalk.bold(' \u2022 ' + key))
88-
.join('\n') +
89-
'\n\nIf you wish to override other Jest options, you need to ' +
90-
'eject from the default setup. You can do so by running ' +
91-
chalk.bold('npm run eject') +
92-
' but remember that this is a one-way operation. ' +
93-
'You may also file an issue with Create React App to discuss ' +
94-
'supporting more options out of the box.\n'
95-
)
96-
);
78+
const isOverridingSetupFile =
79+
unsupportedKeys.indexOf('setupTestFrameworkScriptFile') > -1;
80+
81+
if (isOverridingSetupFile) {
82+
console.error(
83+
chalk.red(
84+
'We detected ' +
85+
chalk.bold('setupTestFrameworkScriptFile') +
86+
' in your package.json.\n\n' +
87+
'Remove it from Jest configuration, and put the initialization code in ' +
88+
chalk.bold('src/setupTests.js') +
89+
'.\nThis file will be loaded automatically.\n'
90+
)
91+
);
92+
} else {
93+
console.error(
94+
chalk.red(
95+
'\nOut of the box, Create React App only supports overriding ' +
96+
'these Jest options:\n\n' +
97+
supportedKeys
98+
.map(key => chalk.bold(' \u2022 ' + key))
99+
.join('\n') +
100+
'.\n\n' +
101+
'These options in your package.json Jest configuration ' +
102+
'are not currently supported by Create React App:\n\n' +
103+
unsupportedKeys
104+
.map(key => chalk.bold(' \u2022 ' + key))
105+
.join('\n') +
106+
'\n\nIf you wish to override other Jest options, you need to ' +
107+
'eject from the default setup. You can do so by running ' +
108+
chalk.bold('npm run eject') +
109+
' but remember that this is a one-way operation. ' +
110+
'You may also file an issue with Create React App to discuss ' +
111+
'supporting more options out of the box.\n'
112+
)
113+
);
114+
}
115+
97116
process.exit(1);
98117
}
99118
}

0 commit comments

Comments
 (0)