Skip to content

Commit

Permalink
normalize before micro-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojs committed Jun 8, 2021
1 parent bdc37bb commit bd36b97
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/jest-core/src/SearchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,22 @@ export default class SearchSource {
const allFiles = this._context.hasteFS.getAllFiles();
const options = {nocase: true, windows: false};

function normalizePosix(filePath: string) {
return filePath.replace(/\\/g, '/');
}

paths = paths
.map(p => {
const relativePath = path
.resolve(this._context.config.cwd, p)
.replace(/\\/g, '\\\\')
// Escape extended globs without a pattern: https://github.com/micromatch/micromatch#extended-globbing
// (* and ? are forbidden in file names)
.replace(/(@|\+|!)([^\(])/g, '\\$1$2')
// Allow search in hidden directories
.replace(/\\\./g, '\\\\.');
const match = micromatch(allFiles, relativePath, options);
return match[0];
// micromatch works with forward slashes: https://github.com/micromatch/micromatch#backslashes
const normalizedPath = normalizePosix(
path.resolve(this._context.config.cwd, p),
);
const match = micromatch(
allFiles.map(normalizePosix),
normalizedPath,
options,
);
return path.resolve(match[0]);
})
.filter(Boolean);
return paths;
Expand Down

0 comments on commit bd36b97

Please sign in to comment.