diff --git a/CHANGELOG.md b/CHANGELOG.md index f1775c014981..975de612d35c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - `[expect]` Display `expectedDiff` more carefully in `toBeCloseTo` ([#8389](https://github.com/facebook/jest/pull/8389)) - `[expect]` Avoid incorrect difference for subset when `toMatchObject` fails ([#9005](https://github.com/facebook/jest/pull/9005)) +- `[jest-config]` Use half of the available cores when `watchAll` mode is enabled ([#9117](https://github.com/facebook/jest/pull/9117)) - `[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-diff]` Do not inverse format if line consists of one change ([#8903](https://github.com/facebook/jest/pull/8903)) diff --git a/packages/jest-config/src/__tests__/getMaxWorkers.test.ts b/packages/jest-config/src/__tests__/getMaxWorkers.test.ts index aab3290c5357..443db5ec141b 100644 --- a/packages/jest-config/src/__tests__/getMaxWorkers.test.ts +++ b/packages/jest-config/src/__tests__/getMaxWorkers.test.ts @@ -33,6 +33,7 @@ describe('getMaxWorkers', () => { it('Returns based on the number of cpus', () => { expect(getMaxWorkers({})).toBe(3); expect(getMaxWorkers({watch: true})).toBe(2); + expect(getMaxWorkers({watchAll: true})).toBe(2); }); describe('% based', () => { diff --git a/packages/jest-config/src/getMaxWorkers.ts b/packages/jest-config/src/getMaxWorkers.ts index beb5cb377216..4cc6b7845438 100644 --- a/packages/jest-config/src/getMaxWorkers.ts +++ b/packages/jest-config/src/getMaxWorkers.ts @@ -9,7 +9,9 @@ import {cpus} from 'os'; import {Config} from '@jest/types'; export default function getMaxWorkers( - argv: Partial>, + argv: Partial< + Pick + >, defaultOptions?: Partial>, ): number { if (argv.runInBand) { @@ -21,7 +23,11 @@ export default function getMaxWorkers( } else { // In watch mode, Jest should be unobtrusive and not use all available CPUs. const numCpus = cpus() ? cpus().length : 1; - return Math.max(argv.watch ? Math.floor(numCpus / 2) : numCpus - 1, 1); + const isWatchModeEnabled = argv.watch || argv.watchAll; + return Math.max( + isWatchModeEnabled ? Math.floor(numCpus / 2) : numCpus - 1, + 1, + ); } }