Skip to content

Commit

Permalink
Forbid testMatch and testRegex being used together
Browse files Browse the repository at this point in the history
  • Loading branch information
pugnascotia committed Jan 24, 2017
1 parent d700650 commit 90b0f57
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
"
`;
10 changes: 10 additions & 0 deletions packages/jest-config/src/__tests__/normalize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90b0f57

Please sign in to comment.