From abaddc01c9efc19c8163198a65b005452dfa795b Mon Sep 17 00:00:00 2001 From: Lee Byonghun Date: Mon, 10 Jun 2024 18:27:54 +0900 Subject: [PATCH] fix: throw error when workers option is not number or percentage (#31210) --- packages/playwright/src/common/config.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index 015dbc1e71..ac7b313820 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -107,7 +107,7 @@ export class FullConfigInternal { const cpus = os.cpus().length; this.config.workers = Math.max(1, Math.floor(cpus * (parseInt(workers, 10) / 100))); } else { - this.config.workers = parseInt(workers, 10); + this.config.workers = parseWorkers(workers); } } else { this.config.workers = workers; @@ -223,6 +223,14 @@ function resolveReporters(reporters: Config['reporter'], rootDir: string): Repor }); } +function parseWorkers(workers: string) { + const parsedWorkers = parseInt(workers, 10); + if (isNaN(parsedWorkers)) + throw new Error(`Workers ${workers} must be a number or percentage.`); + + return parsedWorkers; +} + function resolveProjectDependencies(projects: FullProjectInternal[]) { const teardownSet = new Set(); for (const project of projects) {