diff --git a/packages/jest-config/src/getMaxWorkers.ts b/packages/jest-config/src/getMaxWorkers.ts index 1036816a181c..8ccb1ce54a61 100644 --- a/packages/jest-config/src/getMaxWorkers.ts +++ b/packages/jest-config/src/getMaxWorkers.ts @@ -22,7 +22,8 @@ export default function getMaxWorkers( return parseWorkers(defaultOptions.maxWorkers); } else { // In watch mode, Jest should be unobtrusive and not use all available CPUs. - const numCpus = cpus() ? cpus().length : 1; + const cpusInfo = cpus(); + const numCpus = cpusInfo?.length ?? 1; const isWatchModeEnabled = argv.watch || argv.watchAll; return Math.max( isWatchModeEnabled ? Math.floor(numCpus / 2) : numCpus - 1, @@ -42,7 +43,7 @@ const parseWorkers = (maxWorkers: string | number): number => { ) { const numCpus = cpus().length; const workers = Math.floor((parsed / 100) * numCpus); - return workers >= 1 ? workers : 1; + return Math.max(workers, 1); } return parsed > 0 ? parsed : 1;