diff --git a/CHANGELOG.md b/CHANGELOG.md index 099ba311f489..c5bc375a45fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ ### Performance -- `[jest-core, jest-transform]` Improve Jest startup time and test runtime, particularly when running with coverage, by caching micromatch and avoiding recreating RegExp instances ([#10131](https://github.com/facebook/jest/pull/10131)) +- `[jest-core, jest-transform, jest-haste-map]` Improve Jest startup time and test runtime, particularly when running with coverage, by caching micromatch and avoiding recreating RegExp instances ([#10131](https://github.com/facebook/jest/pull/10131)) ## 26.0.1 diff --git a/packages/jest-haste-map/src/HasteFS.ts b/packages/jest-haste-map/src/HasteFS.ts index 358eee2e3676..bdad6f292a82 100644 --- a/packages/jest-haste-map/src/HasteFS.ts +++ b/packages/jest-haste-map/src/HasteFS.ts @@ -5,8 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import micromatch = require('micromatch'); -import {replacePathSepForGlob} from 'jest-util'; +import {globsToMatcher, replacePathSepForGlob} from 'jest-util'; import type {Config} from '@jest/types'; import type {FileData} from './types'; import * as fastPath from './lib/fast_path'; @@ -84,9 +83,11 @@ export default class HasteFS { root: Config.Path | null, ): Set { const files = new Set(); + const matcher = globsToMatcher(globs); + for (const file of this.getAbsoluteFileIterator()) { const filePath = root ? fastPath.relative(root, file) : file; - if (micromatch([replacePathSepForGlob(filePath)], globs).length > 0) { + if (matcher(replacePathSepForGlob(filePath))) { files.add(file); } }