Skip to content

Commit 6d87f9e

Browse files
authored
feat(config): allow passing option to force node crawl (#11264)
1 parent 6d45caa commit 6d87f9e

File tree

8 files changed

+28
-5
lines changed

8 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- `[jest-config]` Add support for `preset` written in ESM ([#11200](https://github.com/facebook/jest/pull/11200))
1212
- `[jest-config, jest-runtime]` Support ESM for files other than `.js` and `.mjs` ([#10823](https://github.com/facebook/jest/pull/10823))
1313
- `[jest-config, jest-runtime]` [**BREAKING**] Use "modern" implementation as default for fake timers ([#10874](https://github.com/facebook/jest/pull/10874) & [#11197](https://github.com/facebook/jest/pull/11197))
14+
- `[jest-config` Allow passing `forceNodeFilesystemAPI` through to `jest-haste-map` ([#11264](https://github.com/facebook/jest/pull/11264))
1415
- `[jest-core]` make `TestWatcher` extend `emittery` ([#10324](https://github.com/facebook/jest/pull/10324))
1516
- `[jest-core]` Run failed tests interactively the same way we do with snapshots ([#10858](https://github.com/facebook/jest/pull/10858))
1617
- `[jest-core]` more `TestSequencer` methods can be async ([#10980](https://github.com/facebook/jest/pull/10980))

docs/Configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ type HasteConfig = {
495495
computeSha1?: boolean;
496496
/** The platform to use as the default, e.g. 'ios'. */
497497
defaultPlatform?: string | null;
498+
/** Force use of Node's `fs` APIs rather than shelling out to `find` */
499+
forceNodeFilesystemAPI?: boolean;
498500
/**
499501
* Whether to follow symlinks when crawling for files.
500502
* This options cannot be used in projects which use watchman.

e2e/__tests__/__snapshots__/showConfig.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
2121
"globals": {},
2222
"haste": {
2323
"computeSha1": false,
24+
"enableSymlinks": false,
25+
"forceNodeFilesystemAPI": false,
2426
"throwOnModuleCollision": false
2527
},
2628
"injectGlobals": true,

packages/jest-config/src/Defaults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const defaultOptions: Config.DefaultOptions = {
3131
globals: {},
3232
haste: {
3333
computeSha1: false,
34+
enableSymlinks: false,
35+
forceNodeFilesystemAPI: false,
3436
throwOnModuleCollision: false,
3537
},
3638
injectGlobals: true,

packages/jest-config/src/ValidConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const initialOptions: Config.InitialOptions = {
5656
computeSha1: true,
5757
defaultPlatform: 'ios',
5858
enableSymlinks: false,
59+
forceNodeFilesystemAPI: false,
5960
hasteImplModulePath: '<rootDir>/haste_impl.js',
6061
platforms: ['ios', 'android'],
6162
throwOnModuleCollision: false,

packages/jest-config/src/__tests__/normalize.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,3 +1865,15 @@ describe('haste.enableSymlinks', () => {
18651865
expect(options.watchman).toBe(false);
18661866
});
18671867
});
1868+
1869+
describe('haste.forceNodeFilesystemAPI', () => {
1870+
it('should pass option through', async () => {
1871+
const {options} = await normalize(
1872+
{haste: {forceNodeFilesystemAPI: true}, rootDir: '/root/'},
1873+
{},
1874+
);
1875+
1876+
expect(options.haste.forceNodeFilesystemAPI).toBe(true);
1877+
expect(console.warn).not.toHaveBeenCalled();
1878+
});
1879+
});

packages/jest-runtime/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,24 @@ export default class Runtime {
317317
return new HasteMap({
318318
cacheDirectory: config.cacheDirectory,
319319
computeSha1: config.haste.computeSha1,
320-
console: options && options.console,
320+
console: options?.console,
321321
dependencyExtractor: config.dependencyExtractor,
322322
enableSymlinks: config.haste.enableSymlinks,
323323
extensions: [Snapshot.EXTENSION].concat(config.moduleFileExtensions),
324+
forceNodeFilesystemAPI: config.haste.forceNodeFilesystemAPI,
324325
hasteImplModulePath: config.haste.hasteImplModulePath,
325326
ignorePattern,
326-
maxWorkers: (options && options.maxWorkers) || 1,
327+
maxWorkers: options?.maxWorkers || 1,
327328
mocksPattern: escapePathForRegex(path.sep + '__mocks__' + path.sep),
328329
name: config.name,
329330
platforms: config.haste.platforms || ['ios', 'android'],
330-
resetCache: options && options.resetCache,
331+
resetCache: options?.resetCache,
331332
retainAllFiles: false,
332333
rootDir: config.rootDir,
333334
roots: config.roots,
334335
throwOnModuleCollision: config.haste.throwOnModuleCollision,
335-
useWatchman: options && options.watchman,
336-
watch: options && options.watch,
336+
useWatchman: options?.watchman,
337+
watch: options?.watch,
337338
});
338339
}
339340

packages/jest-types/src/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export type HasteConfig = {
2222
computeSha1?: boolean;
2323
/** The platform to use as the default, e.g. 'ios'. */
2424
defaultPlatform?: string | null;
25+
/** Force use of Node's `fs` APIs rather than shelling out to `find` */
26+
forceNodeFilesystemAPI?: boolean;
2527
/**
2628
* Whether to follow symlinks when crawling for files.
2729
* This options cannot be used in projects which use watchman.

0 commit comments

Comments
 (0)