diff --git a/packages/react-scripts/scripts/test.js b/packages/react-scripts/scripts/test.js
index 9de5181d739..40ec6dcd64f 100644
--- a/packages/react-scripts/scripts/test.js
+++ b/packages/react-scripts/scripts/test.js
@@ -20,6 +20,7 @@ require('dotenv').config({silent: true});
const jest = require('jest');
const argv = process.argv.slice(2);
+const overrideArg = (process.argv.filter((i) => i.match('--overrideConfig')) || [])[0];
// Watch unless on CI or in coverage mode
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
@@ -31,10 +32,17 @@ if (!process.env.CI && argv.indexOf('--coverage') < 0) {
const createJestConfig = require('../utils/createJestConfig');
const path = require('path');
const paths = require('../config/paths');
+
+var overrideConfig;
+if ( overrideArg ) {
+ overrideConfig = require(path.resolve(paths.appSrc, '..', overrideArg.split('=')[1] ));
+}
+
argv.push('--config', JSON.stringify(createJestConfig(
relativePath => path.resolve(__dirname, '..', relativePath),
path.resolve(paths.appSrc, '..'),
- false
+ false,
+ overrideConfig
)));
// @remove-on-eject-end
jest.run(argv);
diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md
index e290b935625..f921b1b8936 100644
--- a/packages/react-scripts/template/README.md
+++ b/packages/react-scripts/template/README.md
@@ -156,6 +156,9 @@ You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about [running tests](#running-tests) for more information.
+You can add your own test configuration by specifying a json file using '--overrideConfig'.
+This will also override existing react-scripts configuration.
+
### `npm run build`
Builds the app for production to the `build` folder.
diff --git a/packages/react-scripts/utils/createJestConfig.js b/packages/react-scripts/utils/createJestConfig.js
index f1c67c018f1..c9572b154a4 100644
--- a/packages/react-scripts/utils/createJestConfig.js
+++ b/packages/react-scripts/utils/createJestConfig.js
@@ -12,7 +12,7 @@
const fs = require('fs');
const paths = require('../config/paths');
-module.exports = (resolve, rootDir, isEjecting) => {
+module.exports = (resolve, rootDir, isEjecting, overrides) => {
// Use this instead of `paths.testsSetup` to avoid putting
// an absolute filename into configuration after ejecting.
const setupTestsFile = fs.existsSync(paths.testsSetup) ? '/src/setupTests.js' : undefined;
@@ -45,5 +45,12 @@ module.exports = (resolve, rootDir, isEjecting) => {
if (rootDir) {
config.rootDir = rootDir;
}
+
+ if( overrides ) {
+ Object.keys(overrides).forEach((k) => {
+ config[k] = overrides[k];
+ });
+ }
+
return config;
};