Skip to content

Commit

Permalink
fix(runner): do not run beforeEach hooks upon skip modifier (#31426)
Browse files Browse the repository at this point in the history
Fixes #31425
  • Loading branch information
pavelfeldman committed Jun 25, 2024
1 parent f11ab2f commit da44134
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/playwright/src/worker/workerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions tests/playwright-test/test-modifiers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit da44134

Please sign in to comment.