fix: throw error when workers option is not number or percentage

This commit is contained in:
tolluset 2024-06-08 01:55:43 +09:00
parent 43d6d012d4
commit edd812a1dc

View file

@ -107,7 +107,7 @@ export class FullConfigInternal {
const cpus = os.cpus().length; const cpus = os.cpus().length;
this.config.workers = Math.max(1, Math.floor(cpus * (parseInt(workers, 10) / 100))); this.config.workers = Math.max(1, Math.floor(cpus * (parseInt(workers, 10) / 100)));
} else { } else {
this.config.workers = parseInt(workers, 10); this.config.workers = resolveWorkes(workers);
} }
} else { } else {
this.config.workers = workers; this.config.workers = workers;
@ -223,6 +223,15 @@ function resolveReporters(reporters: Config['reporter'], rootDir: string): Repor
}); });
} }
function resolveWorkes(workers: string) {
const parsedWorkers = parseInt(workers, 10);
if (isNaN(parsedWorkers)) {
throw new Error('Workers must be a number or percentage.');
}
return parsedWorkers;
}
function resolveProjectDependencies(projects: FullProjectInternal[]) { function resolveProjectDependencies(projects: FullProjectInternal[]) {
const teardownSet = new Set<FullProjectInternal>(); const teardownSet = new Set<FullProjectInternal>();
for (const project of projects) { for (const project of projects) {