From 00a35661c30e70fe52de17b349f80955d1650161 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 14 Apr 2026 13:36:31 +0100 Subject: [PATCH] feat(test-runner): error when overriding non-option fixture in config Setting a non-option fixture in a project's `use` section was silently ignored, leaving users wondering why their override had no effect. Emit a load-time error pointing at the right approach (test.extend, or declaring the fixture with { option: true }). --- packages/playwright/src/common/fixtures.ts | 8 ++++++ tests/playwright-test/fixture-errors.spec.ts | 27 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/packages/playwright/src/common/fixtures.ts b/packages/playwright/src/common/fixtures.ts index 30b144e663465..b47c3f7d6a01c 100644 --- a/packages/playwright/src/common/fixtures.ts +++ b/packages/playwright/src/common/fixtures.ts @@ -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(); } diff --git a/tests/playwright-test/fixture-errors.spec.ts b/tests/playwright-test/fixture-errors.spec.ts index ca1c6d7177ec8..95b848a6f1bca 100644 --- a/tests/playwright-test/fixture-errors.spec.ts +++ b/tests/playwright-test/fixture-errors.spec.ts @@ -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"'); +});