From ecd979f7710814d70d290bfb8fe1fba10cf7d536 Mon Sep 17 00:00:00 2001 From: Brandon Chinn Date: Tue, 25 Apr 2023 19:02:02 -0700 Subject: [PATCH] Return TestPathPatterns in normalize helper --- .../__snapshots__/normalize.test.ts.snap | 4 ++-- packages/jest-config/src/normalize.ts | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/jest-config/src/__tests__/__snapshots__/normalize.test.ts.snap b/packages/jest-config/src/__tests__/__snapshots__/normalize.test.ts.snap index 3a7d0dff6d45..5d309a3ae54d 100644 --- a/packages/jest-config/src/__tests__/__snapshots__/normalize.test.ts.snap +++ b/packages/jest-config/src/__tests__/__snapshots__/normalize.test.ts.snap @@ -482,9 +482,9 @@ exports[`testMatch throws if testRegex and testMatch are both specified 1`] = ` " `; -exports[`testPathPattern ignores invalid regular expressions and logs a warning 1`] = `" Invalid testPattern a( supplied. Running all tests instead."`; +exports[`testPathPattern ignores invalid regular expressions and logs a warning 1`] = `" Invalid testPattern /a(/i supplied. Running all tests instead."`; -exports[`testPathPattern --testPathPattern ignores invalid regular expressions and logs a warning 1`] = `" Invalid testPattern a( supplied. Running all tests instead."`; +exports[`testPathPattern --testPathPattern ignores invalid regular expressions and logs a warning 1`] = `" Invalid testPattern /a(/i supplied. Running all tests instead."`; exports[`testTimeout should throw an error if timeout is a negative number 1`] = ` "Validation Error: diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 983d77edf2e6..586b7d119def 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -391,7 +391,7 @@ const normalizeReporters = ({ }); }; -const buildTestPathPattern = (argv: Config.Argv): string => { +const buildTestPathPatterns = (argv: Config.Argv): TestPathPatterns => { const patterns = []; if (argv._) { @@ -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.', ), ); @@ -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( @@ -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;