diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb18f9ca7a8..9721a6e4cb56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - `[jest-config]` Add support for `preset` written in ESM ([#11200](https://github.com/facebook/jest/pull/11200)) - `[jest-config, jest-runtime]` Support ESM for files other than `.js` and `.mjs` ([#10823](https://github.com/facebook/jest/pull/10823)) - `[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)) +- `[jest-config` Allow passing `forceNodeFilesystemAPI` through to `jest-haste-map` ([#11264](https://github.com/facebook/jest/pull/11264)) - `[jest-core]` make `TestWatcher` extend `emittery` ([#10324](https://github.com/facebook/jest/pull/10324)) - `[jest-core]` Run failed tests interactively the same way we do with snapshots ([#10858](https://github.com/facebook/jest/pull/10858)) - `[jest-core]` more `TestSequencer` methods can be async ([#10980](https://github.com/facebook/jest/pull/10980)) diff --git a/docs/Configuration.md b/docs/Configuration.md index 77083b095acb..618d62df9608 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -495,6 +495,8 @@ type HasteConfig = { computeSha1?: boolean; /** The platform to use as the default, e.g. 'ios'. */ defaultPlatform?: string | null; + /** Force use of Node's `fs` APIs rather than shelling out to `find` */ + forceNodeFilesystemAPI?: boolean; /** * Whether to follow symlinks when crawling for files. * This options cannot be used in projects which use watchman. diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index f69f806a639c..d8af652bf08d 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -21,6 +21,8 @@ exports[`--showConfig outputs config info and exits 1`] = ` "globals": {}, "haste": { "computeSha1": false, + "enableSymlinks": false, + "forceNodeFilesystemAPI": false, "throwOnModuleCollision": false }, "injectGlobals": true, diff --git a/packages/jest-config/src/Defaults.ts b/packages/jest-config/src/Defaults.ts index 22838a8cdbd5..7522da678ee3 100644 --- a/packages/jest-config/src/Defaults.ts +++ b/packages/jest-config/src/Defaults.ts @@ -31,6 +31,8 @@ const defaultOptions: Config.DefaultOptions = { globals: {}, haste: { computeSha1: false, + enableSymlinks: false, + forceNodeFilesystemAPI: false, throwOnModuleCollision: false, }, injectGlobals: true, diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index 515526e0ff8c..d655914a100e 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -56,6 +56,7 @@ const initialOptions: Config.InitialOptions = { computeSha1: true, defaultPlatform: 'ios', enableSymlinks: false, + forceNodeFilesystemAPI: false, hasteImplModulePath: '/haste_impl.js', platforms: ['ios', 'android'], throwOnModuleCollision: false, diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 1000d1e10c14..d34ec4b6ffcb 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -1865,3 +1865,15 @@ describe('haste.enableSymlinks', () => { expect(options.watchman).toBe(false); }); }); + +describe('haste.forceNodeFilesystemAPI', () => { + it('should pass option through', async () => { + const {options} = await normalize( + {haste: {forceNodeFilesystemAPI: true}, rootDir: '/root/'}, + {}, + ); + + expect(options.haste.forceNodeFilesystemAPI).toBe(true); + expect(console.warn).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index f2dbc7aa4ab1..e32ddc1b2a81 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -317,23 +317,24 @@ export default class Runtime { return new HasteMap({ cacheDirectory: config.cacheDirectory, computeSha1: config.haste.computeSha1, - console: options && options.console, + console: options?.console, dependencyExtractor: config.dependencyExtractor, enableSymlinks: config.haste.enableSymlinks, extensions: [Snapshot.EXTENSION].concat(config.moduleFileExtensions), + forceNodeFilesystemAPI: config.haste.forceNodeFilesystemAPI, hasteImplModulePath: config.haste.hasteImplModulePath, ignorePattern, - maxWorkers: (options && options.maxWorkers) || 1, + maxWorkers: options?.maxWorkers || 1, mocksPattern: escapePathForRegex(path.sep + '__mocks__' + path.sep), name: config.name, platforms: config.haste.platforms || ['ios', 'android'], - resetCache: options && options.resetCache, + resetCache: options?.resetCache, retainAllFiles: false, rootDir: config.rootDir, roots: config.roots, throwOnModuleCollision: config.haste.throwOnModuleCollision, - useWatchman: options && options.watchman, - watch: options && options.watch, + useWatchman: options?.watchman, + watch: options?.watch, }); } diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index f620a3a081ce..698495285bb5 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -22,6 +22,8 @@ export type HasteConfig = { computeSha1?: boolean; /** The platform to use as the default, e.g. 'ios'. */ defaultPlatform?: string | null; + /** Force use of Node's `fs` APIs rather than shelling out to `find` */ + forceNodeFilesystemAPI?: boolean; /** * Whether to follow symlinks when crawling for files. * This options cannot be used in projects which use watchman.