Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure pattern of replacePosixSep is a string #9546

Merged
merged 4 commits into from Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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