From 003f9b07309f0f9f8eff9e260e19f34a229970d5 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Tue, 28 Nov 2017 07:08:01 +0000 Subject: [PATCH 1/4] 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. --- .../react-scripts/scripts/utils/createJestConfig.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index b4c2cfa5ea9..84102eeef5e 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -72,6 +72,15 @@ module.exports = (resolve, rootDir, isEjecting) => { }); const unsupportedKeys = Object.keys(overrides); if (unsupportedKeys.length) { + const isOverridingSetupFile = + unsupportedKeys.indexOf('setupTestFrameworkScriptFile') >= -1; + + const setupFileError = isOverridingSetupFile + ? '\nTo add a setupTestFrameworkScriptFile, create the file in ' + + chalk.bold('src/setupTests.js') + + ' and create-react-app will automatically load it for you.\n' + : ''; + console.error( chalk.red( 'Out of the box, Create React App only supports overriding ' + @@ -88,7 +97,8 @@ module.exports = (resolve, rootDir, isEjecting) => { 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' + 'supporting more options out of the box.\n' + + setupFileError ) ); process.exit(1); From a308764370015c821d598df11c61e7434b4b1e03 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Thu, 11 Jan 2018 18:29:09 +0000 Subject: [PATCH 2/4] Change the order of Jest config errors. --- packages/react-scripts/scripts/utils/createJestConfig.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 84102eeef5e..07e265b2de1 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -76,14 +76,16 @@ module.exports = (resolve, rootDir, isEjecting) => { unsupportedKeys.indexOf('setupTestFrameworkScriptFile') >= -1; const setupFileError = isOverridingSetupFile - ? '\nTo add a setupTestFrameworkScriptFile, create the file in ' + + ? 'We detected `setupTestFrameworkScriptFile` in your package.json.\n' + + 'To add a setupTestFrameworkScriptFile, create the file in ' + chalk.bold('src/setupTests.js') + ' and create-react-app will automatically load it for you.\n' : ''; console.error( chalk.red( - 'Out of the box, Create React App only supports overriding ' + + setupFileError + + '\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' + @@ -97,8 +99,7 @@ module.exports = (resolve, rootDir, isEjecting) => { 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' + - setupFileError + 'supporting more options out of the box.\n' ) ); process.exit(1); From f01ec336c3efc23cbda183a2b661f5d43b2a171f Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 17 Jan 2018 12:55:41 +0000 Subject: [PATCH 3/4] Show different error for `setupTestFrameworkScriptFile` --- .../scripts/utils/createJestConfig.js | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 07e265b2de1..ea87ca3a1b8 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -73,35 +73,43 @@ module.exports = (resolve, rootDir, isEjecting) => { const unsupportedKeys = Object.keys(overrides); if (unsupportedKeys.length) { const isOverridingSetupFile = - unsupportedKeys.indexOf('setupTestFrameworkScriptFile') >= -1; + unsupportedKeys.indexOf('setupTestFrameworkScriptFile') > -1; - const setupFileError = isOverridingSetupFile - ? 'We detected `setupTestFrameworkScriptFile` in your package.json.\n' + - 'To add a setupTestFrameworkScriptFile, create the file in ' + - chalk.bold('src/setupTests.js') + - ' and create-react-app will automatically load it for you.\n' - : ''; - - console.error( - chalk.red( - setupFileError + + if (isOverridingSetupFile) { + console.error( + chalk.red( + 'We detected ' + + chalk.bold('setupTestFrameworkScriptFile') + + ' in your package.json.\n\n' + + 'To add a setupTestFrameworkScriptFile, create the file ' + + chalk.bold('src/setupTests.js') + + ' and create-react-app will automatically load it for you.\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' - ) - ); + '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); } } From e32ee71361739637f689eeb91bc2c73289d3ceca Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 17 Jan 2018 13:25:40 +0000 Subject: [PATCH 4/4] Tweak the message --- packages/react-scripts/scripts/utils/createJestConfig.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index ea87ca3a1b8..16dd3db2a76 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -81,9 +81,9 @@ module.exports = (resolve, rootDir, isEjecting) => { 'We detected ' + chalk.bold('setupTestFrameworkScriptFile') + ' in your package.json.\n\n' + - 'To add a setupTestFrameworkScriptFile, create the file ' + + 'Remove it from Jest configuration, and put the initialization code in ' + chalk.bold('src/setupTests.js') + - ' and create-react-app will automatically load it for you.\n' + '.\nThis file will be loaded automatically.\n' ) ); } else {