fix(test runner): make sure auto worker fixtures run before auto test fixtures (#27131)

Fixes #27114.
This commit is contained in:
Dmitry Gozman 2023-09-15 14:51:31 -07:00 committed by GitHub
parent c119bd5bd8
commit 3bcf9687e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 5 deletions

View File

@ -235,6 +235,7 @@ export class FixtureRunner {
async resolveParametersForFunction(fn: Function, testInfo: TestInfoImpl, autoFixtures: 'worker' | 'test' | 'all-hooks-only'): Promise<object | null> {
// Install automatic fixtures.
const auto: FixtureRegistration[] = [];
for (const registration of this.pool!.registrations.values()) {
if (registration.auto === false)
continue;
@ -243,11 +244,14 @@ export class FixtureRunner {
shouldRun = registration.scope === 'worker' || registration.auto === 'all-hooks-included';
else if (autoFixtures === 'worker')
shouldRun = registration.scope === 'worker';
if (shouldRun) {
const fixture = await this.setupFixtureForRegistration(registration, testInfo);
if (fixture.failed)
return null;
}
if (shouldRun)
auto.push(registration);
}
auto.sort((r1, r2) => (r1.scope === 'worker' ? 0 : 1) - (r2.scope === 'worker' ? 0 : 1));
for (const registration of auto) {
const fixture = await this.setupFixtureForRegistration(registration, testInfo);
if (fixture.failed)
return null;
}
// Install used fixtures.

View File

@ -783,3 +783,36 @@ test('worker teardown errors reflected in timed-out tests', async ({ runInlineTe
expect(result.output).toContain('Test timeout of 1000ms exceeded.');
expect(result.output).toContain('Rejecting!');
});
test('automatic worker fixtures should start before automatic test fixtures', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
import { test as base, expect } from '@playwright/test';
const test = base.extend({
autoTest: [async ({}, use) => {
console.log('\\n%%TEST FIXTURE 1');
await use();
console.log('\\n%%TEST FIXTURE 2');
}, { scope: 'test', auto: true }],
autoWorker: [async ({}, use) => {
console.log('\\n%%WORKER FIXTURE 1');
await use();
console.log('\\n%%WORKER FIXTURE 2');
}, { scope: 'worker', auto: true }],
});
test('test', async () => {
console.log('\\n%%TEST');
});
`
});
expect(result.exitCode).toBe(0);
expect(result.outputLines).toEqual([
'WORKER FIXTURE 1',
'TEST FIXTURE 1',
'TEST',
'TEST FIXTURE 2',
'WORKER FIXTURE 2',
]);
});