diff --git a/src/test/fixtures.ts b/src/test/fixtures.ts index d7395ff8d7..956849767d 100644 --- a/src/test/fixtures.ts +++ b/src/test/fixtures.ts @@ -16,7 +16,7 @@ import { wrapInPromise } from './util'; import * as crypto from 'crypto'; -import { FixturesWithLocation, Location } from './types'; +import { FixturesWithLocation, Location, WorkerInfo, TestInfo } from './types'; type FixtureScope = 'test' | 'worker'; type FixtureRegistration = { @@ -228,7 +228,7 @@ export class FixtureRunner { this.testScopeClean = true; } - async resolveParametersAndRunHookOrTest(fn: Function, scope: FixtureScope, info: any) { + async resolveParametersAndRunHookOrTest(fn: Function, scope: FixtureScope, info: WorkerInfo|TestInfo) { // Install all automatic fixtures. for (const registration of this.pool!.registrations.values()) { const shouldSkip = scope === 'worker' && registration.scope === 'test'; diff --git a/src/test/workerRunner.ts b/src/test/workerRunner.ts index d8ea34ee10..942358ce64 100644 --- a/src/test/workerRunner.ts +++ b/src/test/workerRunner.ts @@ -147,7 +147,7 @@ export class WorkerRunner extends EventEmitter { if (!this._fixtureRunner.dependsOnWorkerFixturesOnly(beforeAllModifier.fn, beforeAllModifier.location)) continue; // TODO: separate timeout for beforeAll modifiers? - const result = await raceAgainstDeadline(this._fixtureRunner.resolveParametersAndRunHookOrTest(beforeAllModifier.fn, 'worker', undefined), this._deadline()); + const result = await raceAgainstDeadline(this._fixtureRunner.resolveParametersAndRunHookOrTest(beforeAllModifier.fn, 'worker', this._workerInfo), this._deadline()); if (result.timedOut) { this._fatalError = serializeError(new Error(`Timeout of ${this._project.config.timeout}ms exceeded while running ${beforeAllModifier.type} modifier`)); this._reportDoneAndStop(); diff --git a/tests/playwright-test/fixtures.spec.ts b/tests/playwright-test/fixtures.spec.ts index fcc00f3505..75eb1b03f7 100644 --- a/tests/playwright-test/fixtures.spec.ts +++ b/tests/playwright-test/fixtures.spec.ts @@ -340,6 +340,34 @@ test('automatic fixtures should work', async ({ runInlineTest }) => { expect(result.results.map(r => r.status)).toEqual(['passed', 'passed']); }); +test('automatic fixtures should keep workerInfo after conditional skip', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.js': ` + const test = pwt.test; + test.use({ + automaticTestFixture: [ async ({}, runTest, workerInfo) => { + await runTest(); + expect(workerInfo.workerIndex).toBe(0); + console.log('success test fixture') + }, { auto: true } ], + + automaticWorkerFixture: [ async ({}, runTest, workerInfo) => { + await runTest(); + expect(workerInfo.workerIndex).toBe(0); + console.log('success worker fixture') + }, { scope: 'worker', auto: true } ], + }); + test.skip(({ }) => false); + test('good', async ({ }) => { + }); + ` + }); + expect(result.exitCode).toBe(0); + expect(result.output).toContain('success test fixture'); + expect(result.output).toContain('success worker fixture'); + expect(result.results.map(r => r.status)).toEqual(['passed']); +}); + test('tests does not run non-automatic worker fixtures', async ({ runInlineTest }) => { const result = await runInlineTest({ 'a.test.js': `