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
chore(fixtures): report fixtures that do not call use (#37430)
Pavel Feldman86e61b1fe9ab
diff --git a/packages/playwright/src/worker/fixtureRunner.ts b/packages/playwright/src/worker/fixtureRunner.tsindex 413c86c0ee..6329afaff7 100644--- a/packages/playwright/src/worker/fixtureRunner.ts+++ b/packages/playwright/src/worker/fixtureRunner.ts@@ -117,6 +117,8 @@ class Fixture {this._selfTeardownComplete = (async () => {try {await this.registration.fn(params, useFunc, info);+ if (!useFuncStarted.isDone())+ throw new Error(`use() was not called in fixture "${this.registration.name}"`);} catch (error) {this.failed = true;if (!useFuncStarted.isDone())diff --git a/tests/playwright-test/fixtures.spec.ts b/tests/playwright-test/fixtures.spec.tsindex f822557d4a..7bde432d0f 100644--- a/tests/playwright-test/fixtures.spec.ts+++ b/tests/playwright-test/fixtures.spec.ts@@ -816,3 +816,21 @@ test('automatic worker fixtures should start before automatic test fixtures', as'WORKER FIXTURE 2',]);});++test('should error if use is not called', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'a.test.ts': `+ import { test as base, expect } from '@playwright/test';+ const test = base.extend({+ fixture: async ({}, use) => {+ return 123;+ },+ });++ test('test', async ({ fixture }) => {+ });+ `,+ });+ expect(result.failed).toBe(1);+ expect(result.output).toContain(`use() was not called in fixture "fixture"`);+});