Skip to content

Commit ecd979f

Browse files
Return TestPathPatterns in normalize helper
1 parent 86993d4 commit ecd979f

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

packages/jest-config/src/__tests__/__snapshots__/normalize.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ exports[`testMatch throws if testRegex and testMatch are both specified 1`] = `
482482
<red></color>"
483483
`;
484484
485-
exports[`testPathPattern <regexForTestFiles> ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern a( supplied. Running all tests instead.</color>"`;
485+
exports[`testPathPattern <regexForTestFiles> ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern /a(/i supplied. Running all tests instead.</color>"`;
486486
487-
exports[`testPathPattern --testPathPattern ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern a( supplied. Running all tests instead.</color>"`;
487+
exports[`testPathPattern --testPathPattern ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern /a(/i supplied. Running all tests instead.</color>"`;
488488
489489
exports[`testTimeout should throw an error if timeout is a negative number 1`] = `
490490
"<red><bold><bold>● </intensity><bold>Validation Error</intensity>:</color>

packages/jest-config/src/normalize.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ const normalizeReporters = ({
391391
});
392392
};
393393

394-
const buildTestPathPattern = (argv: Config.Argv): string => {
394+
const buildTestPathPatterns = (argv: Config.Argv): TestPathPatterns => {
395395
const patterns = [];
396396

397397
if (argv._) {
@@ -402,21 +402,20 @@ const buildTestPathPattern = (argv: Config.Argv): string => {
402402
}
403403

404404
const testPathPatterns = new TestPathPatterns(patterns);
405-
if (testPathPatterns.isValid()) {
406-
return testPathPatterns.regexString;
407-
} else {
408-
showTestPathPatternError(testPathPatterns.regexString);
409-
return '';
405+
if (!testPathPatterns.isValid()) {
406+
showTestPathPatternsError(testPathPatterns);
407+
return new TestPathPatterns([]);
410408
}
409+
return testPathPatterns;
411410
};
412411

413-
const showTestPathPatternError = (testPathPattern: string) => {
412+
const showTestPathPatternsError = (testPathPatterns: TestPathPatterns) => {
414413
clearLine(process.stdout);
415414

416415
// eslint-disable-next-line no-console
417416
console.log(
418417
chalk.red(
419-
` Invalid testPattern ${testPathPattern} supplied. ` +
418+
` Invalid testPattern ${testPathPatterns.toPretty()} supplied. ` +
420419
'Running all tests instead.',
421420
),
422421
);
@@ -998,7 +997,8 @@ export default async function normalize(
998997
}
999998

1000999
newOptions.nonFlagArgs = argv._?.map(arg => `${arg}`);
1001-
newOptions.testPathPattern = buildTestPathPattern(argv);
1000+
const testPathPatterns = buildTestPathPatterns(argv);
1001+
newOptions.testPathPattern = testPathPatterns.regexString;
10021002
newOptions.json = !!argv.json;
10031003

10041004
newOptions.testFailureExitCode = parseInt(
@@ -1017,7 +1017,7 @@ export default async function normalize(
10171017
if (argv.all) {
10181018
newOptions.onlyChanged = false;
10191019
newOptions.onlyFailures = false;
1020-
} else if (newOptions.testPathPattern) {
1020+
} else if (testPathPatterns.isSet()) {
10211021
// When passing a test path pattern we don't want to only monitor changed
10221022
// files unless `--watch` is also passed.
10231023
newOptions.onlyChanged = newOptions.watch;

0 commit comments

Comments
 (0)