Skip to content

Commit

Permalink
Return TestPathPatterns in normalize helper
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Sep 22, 2023
1 parent 86993d4 commit ecd979f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ exports[`testMatch throws if testRegex and testMatch are both specified 1`] = `
<red></color>"
`;
exports[`testPathPattern <regexForTestFiles> ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern a( supplied. Running all tests instead.</color>"`;
exports[`testPathPattern <regexForTestFiles> ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern /a(/i supplied. Running all tests instead.</color>"`;
exports[`testPathPattern --testPathPattern ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern a( supplied. Running all tests instead.</color>"`;
exports[`testPathPattern --testPathPattern ignores invalid regular expressions and logs a warning 1`] = `"<red> Invalid testPattern /a(/i supplied. Running all tests instead.</color>"`;
exports[`testTimeout should throw an error if timeout is a negative number 1`] = `
"<red><bold><bold>● </intensity><bold>Validation Error</intensity>:</color>
Expand Down
20 changes: 10 additions & 10 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ const normalizeReporters = ({
});
};

const buildTestPathPattern = (argv: Config.Argv): string => {
const buildTestPathPatterns = (argv: Config.Argv): TestPathPatterns => {
const patterns = [];

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

const testPathPatterns = new TestPathPatterns(patterns);
if (testPathPatterns.isValid()) {
return testPathPatterns.regexString;
} else {
showTestPathPatternError(testPathPatterns.regexString);
return '';
if (!testPathPatterns.isValid()) {
showTestPathPatternsError(testPathPatterns);
return new TestPathPatterns([]);
}
return testPathPatterns;
};

const showTestPathPatternError = (testPathPattern: string) => {
const showTestPathPatternsError = (testPathPatterns: TestPathPatterns) => {
clearLine(process.stdout);

// eslint-disable-next-line no-console
console.log(
chalk.red(
` Invalid testPattern ${testPathPattern} supplied. ` +
` Invalid testPattern ${testPathPatterns.toPretty()} supplied. ` +
'Running all tests instead.',
),
);
Expand Down Expand Up @@ -998,7 +997,8 @@ export default async function normalize(
}

newOptions.nonFlagArgs = argv._?.map(arg => `${arg}`);
newOptions.testPathPattern = buildTestPathPattern(argv);
const testPathPatterns = buildTestPathPatterns(argv);
newOptions.testPathPattern = testPathPatterns.regexString;
newOptions.json = !!argv.json;

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

0 comments on commit ecd979f

Please sign in to comment.