Skip to content

Commit 9bacc37

Browse files
authored
Ensure pattern of replacePosixSep is a string (#9546)
1 parent 00e9e09 commit 9bacc37

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `[jest-config]` Treat `setupFilesAfterEnv` like `setupFiles` when normalizing configs against presets ([#9495](https://github.com/facebook/jest/pull/9495))
1111
- `[jest-config]` Support `.mjs` config files on Windows as well ([#9558](https://github.com/facebook/jest/pull/9558))
1212
- `[jest-cli]` Set `coverageProvider` correctly when provided in config ([#9562](https://github.com/facebook/jest/pull/9562))
13+
- `[jest-config]` Ensure pattern of `replacePosixSep` is a string ([#9546]https://github.com/facebook/jest/pull/9546)
1314
- `[jest-matcher-utils]` Fix diff highlight of symbol-keyed object. ([#9499](https://github.com/facebook/jest/pull/9499))
1415
- `[@jest/reporters]` Notifications should be fire&forget rather than having a timeout ([#9567](https://github.com/facebook/jest/pull/9567))
1516
- `[jest-resolve]` Fix module identity preservation with symlinks and browser field resolution ([#9511](https://github.com/facebook/jest/pull/9511))

packages/jest-config/src/__tests__/normalize.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,13 @@ describe('testPathPattern', () => {
15571557

15581558
expect(options.testPathPattern).toBe('a\\\\b|c\\\\d');
15591559
});
1560+
1561+
it('coerces all patterns to strings', () => {
1562+
const argv = {[opt.property]: [1]};
1563+
const {options} = normalize(initialOptions, argv);
1564+
1565+
expect(options.testPathPattern).toBe('1');
1566+
});
15601567
});
15611568
});
15621569
}

packages/jest-config/src/normalize.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,13 @@ const buildTestPathPattern = (argv: Config.Argv): string => {
421421
patterns.push(...argv.testPathPattern);
422422
}
423423

424-
const replacePosixSep = (pattern: string) => {
424+
const replacePosixSep = (pattern: string | number) => {
425+
// yargs coerces positional args into numbers
426+
const patternAsString = pattern.toString();
425427
if (path.sep === '/') {
426-
return pattern;
428+
return patternAsString;
427429
}
428-
return pattern.replace(/\//g, '\\\\');
430+
return patternAsString.replace(/\//g, '\\\\');
429431
};
430432

431433
const testPathPattern = patterns.map(replacePosixSep).join('|');

0 commit comments

Comments
 (0)