Skip to content

Commit 4ccaef6

Browse files
committed
cherry-pick(#31426): fix(runner): do not run beforeEach hooks upon skip modifier
1 parent 4f3f6ee commit 4ccaef6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/playwright/src/worker/workerMain.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ export class WorkerMain extends ProcessRunner {
570570
if (error instanceof TimeoutManagerError)
571571
throw error;
572572
firstError = firstError ?? error;
573+
// Skip in modifier prevents others from running.
574+
if (error instanceof SkipError)
575+
break;
573576
}
574577
}
575578
if (firstError)

tests/playwright-test/test-modifiers.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,3 +690,25 @@ test('static modifiers should be added in serial mode', async ({ runInlineTest }
690690
expect(result.report.suites[0].specs[2].tests[0].annotations).toEqual([{ type: 'skip' }]);
691691
expect(result.report.suites[0].specs[3].tests[0].annotations).toEqual([]);
692692
});
693+
694+
test('should skip beforeEach hooks upon modifiers', async ({ runInlineTest }) => {
695+
const result = await runInlineTest({
696+
'a.test.ts': `
697+
import { test } from '@playwright/test';
698+
test('top', () => {});
699+
700+
test.describe(() => {
701+
test.skip(({ viewport }) => true);
702+
test.beforeEach(() => { throw new Error(); });
703+
704+
test.describe(() => {
705+
test.beforeEach(() => { throw new Error(); });
706+
test('test', () => {});
707+
});
708+
});
709+
`,
710+
});
711+
expect(result.exitCode).toBe(0);
712+
expect(result.passed).toBe(1);
713+
expect(result.skipped).toBe(1);
714+
});

0 commit comments

Comments
 (0)