$ npm install jest-haste-map
jest-haste-map
is a module used by Jest, a popular JavaScript testing framework, to create a fast lookup of files in a project. It helps Jest efficiently locate and track changes in files during testing, making it particularly useful for large projects with many files.
with npm :
npm install jest-haste-map --save-dev
with yarn :
yarn add jest-haste-map --dev
jest-haste-map
is compatible with both ES modules
and CommonJS
const map = new HasteMap.default({
// options
});
import HasteMap from 'jest-haste-map';
import os from 'os';
import {dirname} from 'path';
import {fileURLToPath} from 'url';
const root = dirname(fileURLToPath(import.meta.url));
const map = new HasteMap.default({
id: 'myproject', //Used for caching.
extensions: ['js'], // Tells jest-haste-map to only crawl .js files.
maxWorkers: os.availableParallelism(), //Parallelizes across all available CPUs.
platforms: [], // This is only used for React Native, you can leave it empty.
roots: [root], // Can be used to only search a subset of files within `rootDir`
retainAllFiles: true,
rootDir: root, //The project root.
});
const {hasteFS} = await map.build();
const files = hasteFS.getAllFiles();
console.log(files);
Option | Type | Required | Default Value |
---|---|---|---|
cacheDirectory | string | No | os.tmpdir() |
computeDependencies | boolean | No | true |
computeSha1 | boolean | No | false |
console | Console | No | - |
dependencyExtractor | string | null | No | null |
enableSymlinks | boolean | No | false |
extensions | Array<string> | Yes | - |
forceNodeFilesystemAPI | boolean | Yes | - |
hasteImplModulePath | string | Yes | - |
hasteMapModulePath | string | Yes | - |
id | string | Yes | - |
ignorePattern | HasteRegExp | No | - |
maxWorkers | number | Yes | - |
mocksPattern | string | No | - |
platforms | Array<string> | Yes | - |
resetCache | boolean | No | - |
retainAllFiles | boolean | Yes | - |
rootDir | string | Yes | - |
roots | Array<string> | Yes | - |
skipPackageJson | boolean | Yes | - |
throwOnModuleCollision | boolean | Yes | - |
useWatchman | boolean | No | true |
For more, you can check github
© 2010 - cnpmjs.org x YWFE | Home | YWFE