Skip to content

Commit

Permalink
use already read cpus variable only once and improve code little usi… (
Browse files Browse the repository at this point in the history
  • Loading branch information
sktguha committed Mar 4, 2021
1 parent 024295c commit 1d8f955
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/jest-config/src/getMaxWorkers.ts
Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 1d8f955

Please sign in to comment.