diff --git a/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap b/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap index c6c180c9a974..80ff4271da2c 100644 --- a/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap +++ b/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap @@ -44,3 +44,13 @@ exports[`testEnvironment throws on invalid environment names 1`] = ` https://facebook.github.io/jest/docs/configuration.html " `; + +exports[`testMatch throws if testRegex and testMatch are both specified 1`] = ` +"● Validation Error: + + Configuration options testMatch and testRegex cannot be used together. + + Configuration Documentation: + https://facebook.github.io/jest/docs/configuration.html +" +`; diff --git a/packages/jest-config/src/__tests__/normalize-test.js b/packages/jest-config/src/__tests__/normalize-test.js index 76438ac43437..898e74a8c3b0 100644 --- a/packages/jest-config/src/__tests__/normalize-test.js +++ b/packages/jest-config/src/__tests__/normalize-test.js @@ -589,6 +589,16 @@ describe('testMatch', () => { expect(config.testRegex).toBe(''); }); + + it('throws if testRegex and testMatch are both specified', () => { + expect(() => { + normalize({ + rootDir: '/root', + testMatch: ['**/*.js'], + testRegex: '.*', + }); + }).toThrowErrorMatchingSnapshot(); + }); }); describe('preset', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index ff596aee0be3..090676841d36 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -372,6 +372,13 @@ function normalize(config: InitialConfig, argv: Object = {}) { } } + if (config.testRegex && config.testMatch) { + throw createConfigError( + ` Configuration options ${chalk.bold('testMatch')} and` + + ` ${chalk.bold('testRegex')} cannot be used together.` + ); + } + if (config.testRegex && (!config.testMatch)) { // Prevent the default testMatch conflicting with any explicitly // configured `testRegex` value