Skip to content

Commit

Permalink
Ensure pattern of replacePosixSep is a string (#9546)
Browse files Browse the repository at this point in the history
  • Loading branch information
luann112 authored Feb 12, 2020
1 parent 00e9e09 commit 9bacc37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
}
Expand Down
8 changes: 5 additions & 3 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('|');
Expand Down

0 comments on commit 9bacc37

Please sign in to comment.