Skip to content

Commit

Permalink
Use half of the available cores when in watchAll mode (#9117)
Browse files Browse the repository at this point in the history
  • Loading branch information
brapifra authored and SimenB committed Nov 1, 2019
1 parent b257a15 commit 9a9dbf2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/__tests__/getMaxWorkers.test.ts
Expand Up @@ -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', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/jest-config/src/getMaxWorkers.ts
Expand Up @@ -9,7 +9,9 @@ import {cpus} from 'os';
import {Config} from '@jest/types';

export default function getMaxWorkers(
argv: Partial<Pick<Config.Argv, 'maxWorkers' | 'runInBand' | 'watch'>>,
argv: Partial<
Pick<Config.Argv, 'maxWorkers' | 'runInBand' | 'watch' | 'watchAll'>
>,
defaultOptions?: Partial<Pick<Config.Argv, 'maxWorkers'>>,
): number {
if (argv.runInBand) {
Expand All @@ -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,
);
}
}

Expand Down

0 comments on commit 9a9dbf2

Please sign in to comment.