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

Fixes https://github.com/microsoft/playwright/issues/31425
This commit is contained in:
Pavel Feldman 2024-06-25 10:47:37 -07:00 committed by GitHub
parent f11ab2f145
commit da441347e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -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)

View File

@ -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);
});