diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 705f0f87ae3..17f5d641c77 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -73,15 +73,25 @@ module.exports = (resolve, rootDir, isEjecting) => { 'extraGlobals', 'globalSetup', 'globalTeardown', + 'moduleNameMapper', 'resetMocks', 'resetModules', 'snapshotSerializers', + 'transform', + 'transformIgnorePatterns', 'watchPathIgnorePatterns', ]; if (overrides) { supportedKeys.forEach(key => { if (overrides.hasOwnProperty(key)) { - config[key] = overrides[key]; + if (Array.isArray(config[key]) || typeof config[key] !== 'object') { + // for arrays or primitive types, directly override the config key + config[key] = overrides[key]; + } else { + // for object types, extend gracefully + config[key] = Object.assign({}, config[key], overrides[key]); + } + delete overrides[key]; } });