diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f35b5d7fe32..9f5f6e37a23f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - `[jest-config]` Treat `setupFilesAfterEnv` like `setupFiles` when normalizing configs against presets ([#9495](https://github.com/facebook/jest/pull/9495)) - `[jest-config]` Support `.mjs` config files on Windows as well ([#9558](https://github.com/facebook/jest/pull/9558)) - `[jest-cli]` Set `coverageProvider` correctly when provided in config ([#9562](https://github.com/facebook/jest/pull/9562)) +- `[jest-config]` Ensure pattern of `replacePosixSep` is a string ([#9546]https://github.com/facebook/jest/pull/9546) - `[jest-matcher-utils]` Fix diff highlight of symbol-keyed object. ([#9499](https://github.com/facebook/jest/pull/9499)) - `[@jest/reporters]` Notifications should be fire&forget rather than having a timeout ([#9567](https://github.com/facebook/jest/pull/9567)) - `[jest-resolve]` Fix module identity preservation with symlinks and browser field resolution ([#9511](https://github.com/facebook/jest/pull/9511)) diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index b3b59a894df8..ce238fe2afd8 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -1557,6 +1557,13 @@ describe('testPathPattern', () => { expect(options.testPathPattern).toBe('a\\\\b|c\\\\d'); }); + + it('coerces all patterns to strings', () => { + const argv = {[opt.property]: [1]}; + const {options} = normalize(initialOptions, argv); + + expect(options.testPathPattern).toBe('1'); + }); }); }); } diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index a2454c373732..ea72cdef7f85 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -421,11 +421,13 @@ const buildTestPathPattern = (argv: Config.Argv): string => { patterns.push(...argv.testPathPattern); } - const replacePosixSep = (pattern: string) => { + const replacePosixSep = (pattern: string | number) => { + // yargs coerces positional args into numbers + const patternAsString = pattern.toString(); if (path.sep === '/') { - return pattern; + return patternAsString; } - return pattern.replace(/\//g, '\\\\'); + return patternAsString.replace(/\//g, '\\\\'); }; const testPathPattern = patterns.map(replacePosixSep).join('|');