mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
fix(test runner): make sure auto worker fixtures run before auto test fixtures (#27131)
Fixes #27114.
This commit is contained in:
parent
c119bd5bd8
commit
3bcf9687e6
@ -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.
|
||||
|
@ -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',
|
||||
]);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user