Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use half of the available cores when in watchAll mode #9117

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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