From 29409042ce6cc3f6aa6f63785e7c0529e8c9d1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Dec 2019 19:46:28 +0100 Subject: [PATCH 1/4] feat: limit number of workers when creating haste maps in projects --- .vscode/settings.json | 6 ++---- packages/jest-core/src/cli/index.ts | 2 +- packages/jest-runtime/src/cli/index.ts | 3 --- packages/jest-worker/README.md | 6 ------ 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c4951686b125..69015dbad6d0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,9 +5,7 @@ "**/node_modules": true, "**/build": true }, - "editor.formatOnSave": true, - "flow.useNPMPackagedFlow": true, + "eslint.autoFixOnSave": true, "javascript.validate.enable": false, - "jest.pathToJest": "yarn jest --", - "prettier.eslintIntegration": true + "jest.pathToJest": "yarn jest --" } diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index ad2f2e2bea73..cd2eba63e7e6 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -122,7 +122,7 @@ const buildContextsAndHasteMaps = async ( createDirectory(config.cacheDirectory); const hasteMapInstance = Runtime.createHasteMap(config, { console: new CustomConsole(outputStream, outputStream), - maxWorkers: globalConfig.maxWorkers, + maxWorkers: Math.max(1, globalConfig.maxWorkers / configs.length), resetCache: !config.cache, watch: globalConfig.watch || globalConfig.watchAll, watchman: globalConfig.watchman, diff --git a/packages/jest-runtime/src/cli/index.ts b/packages/jest-runtime/src/cli/index.ts index a70cf4ac3ead..22ed107ffb99 100644 --- a/packages/jest-runtime/src/cli/index.ts +++ b/packages/jest-runtime/src/cli/index.ts @@ -35,7 +35,6 @@ export function run(cliArgv?: Config.Argv, cliInfo?: Array) { .version(false) .options(args.options).argv; - // @ts-ignore: fix this at some point validateCLIOptions(argv, {...args.options, deprecationEntries}); } @@ -63,8 +62,6 @@ export function run(cliArgv?: Config.Argv, cliInfo?: Array) { const info = cliInfo ? ', ' + cliInfo.join(', ') : ''; console.log(`Using Jest Runtime v${VERSION}${info}`); } - // TODO: Figure this out - // @ts-ignore: this might not have the correct arguments const options = readConfig(argv, root); const globalConfig = options.globalConfig; // Always disable automocking in scripts. diff --git a/packages/jest-worker/README.md b/packages/jest-worker/README.md index 932326202edb..4f2222632b11 100644 --- a/packages/jest-worker/README.md +++ b/packages/jest-worker/README.md @@ -83,12 +83,6 @@ By default, no process is bound to any worker. The arguments that will be passed to the `setup` method during initialization. -#### `workerPool: (workerPath: string, options?: WorkerPoolOptions) => WorkerPoolInterface` (optional) - -Provide a custom worker pool to be used for spawning child processes. By default, Jest will use a node thread pool if available and fall back to child process threads. - -The arguments that will be passed to the `setup` method during initialization. - #### `enableWorkerThreads: boolean` (optional) `jest-worker` will automatically detect if `worker_threads` are available, but will not use them unless passed `enableWorkerThreads: true`. From c24eaf8f88b348451b2d807e50ecb15745661bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Dec 2019 19:56:47 +0100 Subject: [PATCH 2/4] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa564953b57a..6dc41106eef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ - `[jest-config]` Fix Jest multi project runner still cannot handle exactly one project ([#8894](https://github.com/facebook/jest/pull/8894)) - `[jest-console]` Add missing `console.group` calls to `NullConsole` ([#9024](https://github.com/facebook/jest/pull/9024)) - `[jest-core]` Don't include unref'd timers in --detectOpenHandles results ([#8941](https://github.com/facebook/jest/pull/8941)) +- `[jest-core]` Limit number of workers when creating haste maps in projects ([#9259](https://github.com/facebook/jest/pull/9259)) - `[jest-diff]` Do not inverse format if line consists of one change ([#8903](https://github.com/facebook/jest/pull/8903)) - `[jest-diff]` Rename some new options and change their default values ([#9077](https://github.com/facebook/jest/pull/9077)) - `[jest-fake-timers]` `getTimerCount` will not include cancelled immediates ([#8764](https://github.com/facebook/jest/pull/8764)) From 259fc2c100534356f5ef1c039881e10d4aeafa5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Dec 2019 20:01:00 +0100 Subject: [PATCH 3/4] floor the division --- packages/jest-core/src/cli/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index cd2eba63e7e6..da079919a161 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -122,7 +122,10 @@ const buildContextsAndHasteMaps = async ( createDirectory(config.cacheDirectory); const hasteMapInstance = Runtime.createHasteMap(config, { console: new CustomConsole(outputStream, outputStream), - maxWorkers: Math.max(1, globalConfig.maxWorkers / configs.length), + maxWorkers: Math.max( + 1, + Math.floor(globalConfig.maxWorkers / configs.length), + ), resetCache: !config.cache, watch: globalConfig.watch || globalConfig.watchAll, watchman: globalConfig.watchman, From f79f9b6df2587f8f4f8320663589f933cf560fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Dec 2019 20:18:41 +0100 Subject: [PATCH 4/4] bring back WorkerPool doc --- packages/jest-worker/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/jest-worker/README.md b/packages/jest-worker/README.md index 4f2222632b11..247b68b748e9 100644 --- a/packages/jest-worker/README.md +++ b/packages/jest-worker/README.md @@ -83,6 +83,12 @@ By default, no process is bound to any worker. The arguments that will be passed to the `setup` method during initialization. +#### `WorkerPool: (workerPath: string, options?: WorkerPoolOptions) => WorkerPoolInterface` (optional) + +Provide a custom worker pool to be used for spawning child processes. By default, Jest will use a node thread pool if available and fall back to child process threads. + +The arguments that will be passed to the `setup` method during initialization. + #### `enableWorkerThreads: boolean` (optional) `jest-worker` will automatically detect if `worker_threads` are available, but will not use them unless passed `enableWorkerThreads: true`.