Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Fixes

* `[jest-config]` Use all `--testPathPattern` and `<regexForTestFiles>` args in
`testPathPattern`([#5066](https://github.com/facebook/jest/pull/5066))
* `[jest-cli]` Do not support `--watch` inside non-version-controlled environments
([#5060](https://github.com/facebook/jest/pull/5060))
* `[jest-config]` Escape Windows path separator in testPathPattern CLI arguments
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export const options = {
description:
'A regexp pattern string that is matched against all tests ' +
'paths before executing the test.',
type: 'string',
type: 'array',
},
testRegex: {
description: 'The regexp pattern Jest uses to detect test files.',
Expand Down
28 changes: 25 additions & 3 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,18 +1055,32 @@ describe('testPathPattern', () => {

describe('--testPathPattern', () => {
it('uses testPathPattern if set', () => {
const {options} = normalize(initialOptions, {testPathPattern: 'a/b'});
const {options} = normalize(initialOptions, {testPathPattern: ['a/b']});
expect(options.testPathPattern).toBe('a/b');
});

it('ignores invalid regular expressions and logs a warning', () => {
const {options} = normalize(initialOptions, {testPathPattern: 'a('});
const {options} = normalize(initialOptions, {testPathPattern: ['a(']});
expect(options.testPathPattern).toBe('');
expect(console.log.mock.calls[0][0]).toMatchSnapshot();
});

it('escapes Windows path separators', () => {
testWindowsPathSeparator({testPathPattern: 'a\\b'}, 'a\\\\b');
testWindowsPathSeparator({testPathPattern: ['a\\b']}, 'a\\\\b');
});

it('joins multiple --testPathPatterns if set', () => {
const {options} = normalize(initialOptions, {
testPathPattern: ['a/b', 'c/d'],
});
expect(options.testPathPattern).toBe('a/b|c/d');
});

it('escapes Windows path separators in multiple args', () => {
testWindowsPathSeparator(
{testPathPattern: ['a\\b', 'c\\d']},
'a\\\\b|c\\\\d',
);
});
});

Expand Down Expand Up @@ -1095,4 +1109,12 @@ describe('testPathPattern', () => {
testWindowsPathSeparator({_: ['a\\b', 'c\\d']}, 'a\\\\b|c\\\\d');
});
});

it('joins multiple --testPathPatterns and <regexForTestFiles>', () => {
const {options} = normalize(initialOptions, {
_: ['a', 'b'],
testPathPattern: ['c', 'd'],
});
expect(options.testPathPattern).toBe('a|b|c|d');
});
});
27 changes: 12 additions & 15 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,25 +279,22 @@ const normalizeReporters = (options: InitialOptions, basedir) => {
};

const buildTestPathPattern = (argv: Argv): string => {
const patterns = [];

if (argv._) {
patterns.push(...argv._);
}
if (argv.testPathPattern) {
if (validatePattern(argv.testPathPattern)) {
return replacePathSepForRegex(argv.testPathPattern);
} else {
showTestPathPatternError(argv.testPathPattern);
}
patterns.push(...argv.testPathPattern);
}

if (argv._ && argv._.length) {
const testPathPattern = argv._.map(replacePathSepForRegex).join('|');

if (validatePattern(testPathPattern)) {
return testPathPattern;
} else {
showTestPathPatternError(testPathPattern);
}
const testPathPattern = patterns.map(replacePathSepForRegex).join('|');
if (validatePattern(testPathPattern)) {
return testPathPattern;
} else {
showTestPathPatternError(testPathPattern);
return '';
}

return '';
};

const showTestPathPatternError = (testPathPattern: string) => {
Expand Down
2 changes: 1 addition & 1 deletion types/Argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type Argv = {|
testMatch: Array<string>,
testNamePattern: string,
testPathIgnorePatterns: Array<string>,
testPathPattern: string,
testPathPattern: Array<string>,
testRegex: string,
testResultsProcessor: ?string,
testRunner: string,
Expand Down