Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(test-runner): error when overriding non-option fixture in config (#40197)
Dmitry Gozmanc45f472080b5
diff --git a/packages/playwright/src/common/fixtures.ts b/packages/playwright/src/common/fixtures.tsindex 30b144e663..b47c3f7d6a 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.tsindex ca1c6d7177..95b848a6f1 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 ({ runInlineexpect(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"');+});