Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/playwright/src/worker/fixtureRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class FixtureRunner {
throw firstError;
}

async resolveParametersForFunction(fn: Function, testInfo: TestInfoImpl, autoFixtures: 'worker' | 'test' | 'all-hooks-only', runnable: RunnableDescription): Promise<object | null> {
async resolveParametersForFunction(fn: Function, testInfo: TestInfoImpl, autoFixtures: 'worker' | 'test' | 'all-hooks-only', runnable: RunnableDescription): Promise<{ result: object } | null> {
const collector = new Set<FixtureRegistration>();

// Collect automatic fixtures.
Expand Down Expand Up @@ -264,7 +264,8 @@ export class FixtureRunner {
return null;
params[name] = fixture.value;
}
return params;
// Wrap in an object to avoid returning a thenable if a fixture is named 'then'.
return { result: params };
}

async resolveParametersAndRunFunction(fn: Function, testInfo: TestInfoImpl, autoFixtures: 'worker' | 'test' | 'all-hooks-only', runnable: RunnableDescription) {
Expand All @@ -273,7 +274,7 @@ export class FixtureRunner {
// Do not run the function when fixture setup has already failed.
return null;
}
await testInfo._runWithTimeout(runnable, () => fn(params, testInfo));
await testInfo._runWithTimeout(runnable, () => fn(params.result, testInfo));
}

private async _setupFixtureForRegistration(registration: FixtureRegistration, testInfo: TestInfoImpl, runnable: RunnableDescription): Promise<Fixture> {
Expand Down
5 changes: 4 additions & 1 deletion packages/playwright/src/worker/workerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ export class WorkerMain extends ProcessRunner {
await this._runEachHooksForSuites(suites, 'beforeEach', testInfo);

// Setup fixtures required by the test.
testFunctionParams = await this._fixtureRunner.resolveParametersForFunction(test.fn, testInfo, 'test', { type: 'test' });
const params = await this._fixtureRunner.resolveParametersForFunction(test.fn, testInfo, 'test', { type: 'test' });
if (params !== null)
testFunctionParams = params.result;

});

if (testFunctionParams === null) {
Expand Down
16 changes: 16 additions & 0 deletions tests/playwright-test/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,19 @@ test('should error if use is not called', async ({ runInlineTest }) => {
expect(result.failed).toBe(1);
expect(result.output).toContain(`use() was not called in fixture "fixture"`);
});

test('should not treat fixtures as thenable promise', async ({ runInlineTest }) => {
const { results } = await runInlineTest({
'a.test.ts': `
import { test as base, expect } from '@playwright/test';
const test = base.extend({
then: async ({}, use) => await use(() => 'test-function'),
});

test('should not treat fixtures as thenable promise', async ({ then }) => {
expect(typeof then).toBe('function');
});
`,
});
expect(results[0].status).toBe('passed');
});
Loading