Skip to content

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

fix(runner): do not run beforeEach hooks upon skip modifier (#31426)

Pavel Feldmanda441347e24d
diff --git a/packages/playwright/src/worker/workerMain.ts b/packages/playwright/src/worker/workerMain.ts
index e97bf2945c..2f0dcc424d 100644
--- a/packages/playwright/src/worker/workerMain.ts
+++ b/packages/playwright/src/worker/workerMain.ts
@@ -570,6 +570,9 @@ export class WorkerMain extends ProcessRunner {
if (error instanceof TimeoutManagerError)
throw error;
firstError = firstError ?? error;
+ // Skip in modifier prevents others from running.
+ if (error instanceof SkipError)
+ break;
}
}
if (firstError)
diff --git a/tests/playwright-test/test-modifiers.spec.ts b/tests/playwright-test/test-modifiers.spec.ts
index 2d11ad0c9a..0dd41bd0ab 100644
--- a/tests/playwright-test/test-modifiers.spec.ts
+++ b/tests/playwright-test/test-modifiers.spec.ts
@@ -715,3 +715,25 @@ test('should contain only one slow modifier', async ({ runInlineTest }) => {
expect(result.report.suites[1].specs[0].tests[0].annotations).toEqual([{ type: 'skip' }, { type: 'issue', description: 'my-value' }]);
expect(result.report.suites[2].specs[0].tests[0].annotations).toEqual([{ type: 'slow' }, { type: 'issue', description: 'my-value' }]);
});
+
+test('should skip beforeEach hooks upon modifiers', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'a.test.ts': `
+ import { test } from '@playwright/test';
+ test('top', () => {});
+
+ test.describe(() => {
+ test.skip(({ viewport }) => true);
+ test.beforeEach(() => { throw new Error(); });
+
+ test.describe(() => {
+ test.beforeEach(() => { throw new Error(); });
+ test('test', () => {});
+ });
+ });
+ `,
+ });
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(1);
+ expect(result.skipped).toBe(1);
+});