Skip to content

Commit c45f472

Browse files
authored
feat(test-runner): error when overriding non-option fixture in config (#40197)
1 parent 2085f53 commit c45f472

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

packages/playwright/src/common/fixtures.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export class FixturePool {
9797
this._appendFixtureList({ fixtures: selectedOverrides, location: optionOverrides!.location }, !!disallowWorkerFixtures, true);
9898
}
9999

100+
if (optionOverrides) {
101+
for (const key of overrideKeys) {
102+
const registration = this._registrations.get(key);
103+
if (registration && !registration.option)
104+
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);
105+
}
106+
}
107+
100108
this.digest = this.validate();
101109
}
102110

tests/playwright-test/fixture-errors.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,3 +789,30 @@ test('should report fixture teardown error after test error', async ({ runInline
789789
expect(result.output).toContain('Error from the fixture foo');
790790
expect(result.output).toContain('Error from the test');
791791
});
792+
793+
test('should throw when overriding non-option fixture in config', async ({ runInlineTest }) => {
794+
const result = await runInlineTest({
795+
'playwright.config.ts': `
796+
module.exports = {
797+
use: {
798+
foo: 'overridden',
799+
headless: true,
800+
unknownThing: 'ignored',
801+
},
802+
};
803+
`,
804+
'a.spec.ts': `
805+
import { test as base, expect } from '@playwright/test';
806+
const test = base.extend({
807+
foo: async ({}, use) => await use('original'),
808+
});
809+
test('works', async ({ foo }) => {
810+
expect(foo).toBe('original');
811+
});
812+
`,
813+
});
814+
expect(result.exitCode).toBe(1);
815+
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.');
816+
expect(result.output).not.toContain('Fixture "headless"');
817+
expect(result.output).not.toContain('Fixture "unknownThing"');
818+
});

0 commit comments

Comments
 (0)