diff --git a/docusaurus/docs/running-tests.md b/docusaurus/docs/running-tests.md index 5f93a391771..96c84abd254 100644 --- a/docusaurus/docs/running-tests.md +++ b/docusaurus/docs/running-tests.md @@ -279,7 +279,13 @@ Supported overrides: - [`collectCoverageFrom`](https://jestjs.io/docs/en/configuration.html#collectcoveragefrom-array) - [`coverageReporters`](https://jestjs.io/docs/en/configuration.html#coveragereporters-array-string) - [`coverageThreshold`](https://jestjs.io/docs/en/configuration.html#coveragethreshold-object) +- [`globalSetup`](https://jestjs.io/docs/en/configuration.html#globalsetup-string) +- [`globalTeardown`](https://jestjs.io/docs/en/configuration.html#globalteardown-string) +- [`moduleNameMapper`](https://jestjs.io/docs/en/configuration.html#modulenamemapper-object-string-string) +- [`resetMocks`](https://jestjs.io/docs/en/configuration.html#resetmocks-boolean) +- [`resetModules`](https://jestjs.io/docs/en/configuration.html#resetmodules-boolean) - [`snapshotSerializers`](https://jestjs.io/docs/en/configuration.html#snapshotserializers-array-string) +- [`watchPathIgnorePatterns`](https://jestjs.io/docs/en/configuration.html#watchpathignorepatterns-array-string) Example package.json: diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 5294220b1fe..ad16984a0f3 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -79,15 +79,22 @@ module.exports = (resolve, rootDir, isEjecting) => { 'coverageThreshold', 'globalSetup', 'globalTeardown', + 'moduleNameMapper', 'resetMocks', 'resetModules', 'snapshotSerializers', 'watchPathIgnorePatterns', ]; + const mergedKeys = ['moduleNameMapper']; if (overrides) { supportedKeys.forEach(key => { if (overrides.hasOwnProperty(key)) { - config[key] = overrides[key]; + if (mergedKeys.includes(key)) { + // Allow overrides[key] to override internal configuration + config[key] = Object.assign(config[key], overrides[key]); + } else { + config[key] = overrides[key]; + } delete overrides[key]; } });