Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test-runner): reject workers=0 or negative value (#40440)

devareddy05ef64d929cfee
diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts
index 45259df4c5..fed3cd4131 100644
--- a/packages/playwright/src/common/config.ts
+++ b/packages/playwright/src/common/config.ts
@@ -225,8 +225,12 @@ function resolveWorkers(workers: string | number): number {
const parsedWorkers = parseInt(workers, 10);
if (isNaN(parsedWorkers))
throw new Error(`Workers ${workers} must be a number or percentage.`);
+ if (parsedWorkers < 1)
+ throw new Error(`Workers must be a positive number, received ${parsedWorkers}.`);
return parsedWorkers;
}
+ if (workers < 1)
+ throw new Error(`Workers must be a positive number, received ${workers}.`);
return workers;
}
diff --git a/tests/playwright-test/config.spec.ts b/tests/playwright-test/config.spec.ts
index 2c6342f001..e7cefd2cd7 100644
--- a/tests/playwright-test/config.spec.ts
+++ b/tests/playwright-test/config.spec.ts
@@ -552,6 +552,18 @@ test('should throw when workers option is invalid', async ({ runInlineTest }) =>
expect(result.output).toContain('config.workers must be a number or percentage');
});
+test('should throw when workers is negative via CLI (regression for #39938)', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'playwright.config.ts': `module.exports = {};`,
+ 'a.test.ts': `
+ import { test } from '@playwright/test';
+ test('pass', () => {});
+ `,
+ }, { workers: -1 });
+ expect(result.exitCode).toBe(1);
+ expect(result.output).toContain('Workers must be a positive number');
+});
+
test('should work with undefined values and base', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `