From edd812a1dc21e6925d47582d017676c72587e89f Mon Sep 17 00:00:00 2001 From: tolluset Date: Sat, 8 Jun 2024 01:55:43 +0900 Subject: [PATCH] fix: throw error when workers option is not number or percentage --- packages/playwright/src/common/config.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index 015dbc1e71..31a7b88c61 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 = resolveWorkes(workers); } } else { 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[]) { const teardownSet = new Set(); for (const project of projects) {