Skip to content

Commit 1d8f955

Browse files
authored
use already read cpus variable only once and improve code little usi… (#10842)
1 parent 024295c commit 1d8f955

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/jest-config/src/getMaxWorkers.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export default function getMaxWorkers(
2222
return parseWorkers(defaultOptions.maxWorkers);
2323
} else {
2424
// In watch mode, Jest should be unobtrusive and not use all available CPUs.
25-
const numCpus = cpus() ? cpus().length : 1;
25+
const cpusInfo = cpus();
26+
const numCpus = cpusInfo?.length ?? 1;
2627
const isWatchModeEnabled = argv.watch || argv.watchAll;
2728
return Math.max(
2829
isWatchModeEnabled ? Math.floor(numCpus / 2) : numCpus - 1,
@@ -42,7 +43,7 @@ const parseWorkers = (maxWorkers: string | number): number => {
4243
) {
4344
const numCpus = cpus().length;
4445
const workers = Math.floor((parsed / 100) * numCpus);
45-
return workers >= 1 ? workers : 1;
46+
return Math.max(workers, 1);
4647
}
4748

4849
return parsed > 0 ? parsed : 1;

0 commit comments

Comments
 (0)