Skip to content

Commit

Permalink
feat(config): allow passing option to force node crawl (#11264)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 2, 2021
1 parent 6d45caa commit 6d87f9e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions docs/Configuration.md
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Expand Up @@ -21,6 +21,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
"globals": {},
"haste": {
"computeSha1": false,
"enableSymlinks": false,
"forceNodeFilesystemAPI": false,
"throwOnModuleCollision": false
},
"injectGlobals": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-config/src/Defaults.ts
Expand Up @@ -31,6 +31,8 @@ const defaultOptions: Config.DefaultOptions = {
globals: {},
haste: {
computeSha1: false,
enableSymlinks: false,
forceNodeFilesystemAPI: false,
throwOnModuleCollision: false,
},
injectGlobals: true,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/ValidConfig.ts
Expand Up @@ -56,6 +56,7 @@ const initialOptions: Config.InitialOptions = {
computeSha1: true,
defaultPlatform: 'ios',
enableSymlinks: false,
forceNodeFilesystemAPI: false,
hasteImplModulePath: '<rootDir>/haste_impl.js',
platforms: ['ios', 'android'],
throwOnModuleCollision: false,
Expand Down
12 changes: 12 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.ts
Expand Up @@ -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();
});
});
11 changes: 6 additions & 5 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -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,
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/jest-types/src/Config.ts
Expand Up @@ -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.
Expand Down

0 comments on commit 6d87f9e

Please sign in to comment.