From da441347e24d6136a66baa5beb12b5964b6a6e0f Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 25 Jun 2024 10:47:37 -0700 Subject: [PATCH] fix(runner): do not run beforeEach hooks upon skip modifier (#31426) Fixes https://github.com/microsoft/playwright/issues/31425 --- packages/playwright/src/worker/workerMain.ts | 3 +++ tests/playwright-test/test-modifiers.spec.ts | 22 ++++++++++++++++++++ 2 files changed, 25 insertions(+) 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); +});