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
8 changes: 8 additions & 0 deletions packages/playwright/src/common/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ export class FixturePool {
this._appendFixtureList({ fixtures: selectedOverrides, location: optionOverrides!.location }, !!disallowWorkerFixtures, true);
}

if (optionOverrides) {
for (const key of overrideKeys) {
const registration = this._registrations.get(key);
if (registration && !registration.option)
this._addLoadError(`Fixture "${key}" cannot be overridden in the configuration "use" section. Only fixtures registered with { option: true } can be set in the config.`, optionOverrides.location);
}
}

this.digest = this.validate();
}

Expand Down
27 changes: 27 additions & 0 deletions tests/playwright-test/fixture-errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,30 @@ test('should report fixture teardown error after test error', async ({ runInline
expect(result.output).toContain('Error from the fixture foo');
expect(result.output).toContain('Error from the test');
});

test('should throw when overriding non-option fixture in config', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
use: {
foo: 'overridden',
headless: true,
unknownThing: 'ignored',
},
};
`,
'a.spec.ts': `
import { test as base, expect } from '@playwright/test';
const test = base.extend({
foo: async ({}, use) => await use('original'),
});
test('works', async ({ foo }) => {
expect(foo).toBe('original');
});
`,
});
expect(result.exitCode).toBe(1);
expect(result.output).toContain('Fixture "foo" cannot be overridden in the configuration "use" section. Only fixtures registered with { option: true } can be set in the config.');
expect(result.output).not.toContain('Fixture "headless"');
expect(result.output).not.toContain('Fixture "unknownThing"');
});
Loading