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): make _extendTest experimental (#11210)
Dmitry Gozmanf77c874e8a3a
diff --git a/packages/playwright-test/src/testType.ts b/packages/playwright-test/src/testType.tsindex 71633c1ede..e30c6c2607 100644--- a/packages/playwright-test/src/testType.ts+++ b/packages/playwright-test/src/testType.ts@@ -52,7 +52,7 @@ export class TestTypeImpl {test.step = wrapFunctionWithLocation(this._step.bind(this));test.use = wrapFunctionWithLocation(this._use.bind(this));test.extend = wrapFunctionWithLocation(this._extend.bind(this));- test.extendTest = wrapFunctionWithLocation(this._extendTest.bind(this));+ test._extendTest = wrapFunctionWithLocation(this._extendTest.bind(this));test.info = () => {const result = currentTestInfo();if (!result)@@ -203,7 +203,7 @@ export class TestTypeImpl {private _extend(location: Location, fixtures: Fixtures) {if ((fixtures as any)[testTypeSymbol])- throw new Error(`test.extend() accepts fixtures object, not a test object.\nDid you mean to call test.extendTest()?`);+ throw new Error(`test.extend() accepts fixtures object, not a test object.\nDid you mean to call test._extendTest()?`);const fixturesWithLocation: FixturesWithLocation = { fixtures, location };return new TestTypeImpl([...this.fixtures, fixturesWithLocation]).test;}@@ -211,7 +211,7 @@ export class TestTypeImpl {private _extendTest(location: Location, test: TestType<any, any>) {const testTypeImpl = (test as any)[testTypeSymbol] as TestTypeImpl;if (!testTypeImpl)- throw new Error(`test.extendTest() accepts a single "test" parameter.\nDid you mean to call test.extend() with fixtures instead?`);+ throw new Error(`test._extendTest() accepts a single "test" parameter.\nDid you mean to call test.extend() with fixtures instead?`);// Filter out common ancestor fixtures.const newFixtures = testTypeImpl.fixtures.filter(theirs => !this.fixtures.find(ours => ours.fixtures === theirs.fixtures));return new TestTypeImpl([...this.fixtures, ...newFixtures]).test;diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.tsindex 2c834cbaa3..c47f5261e4 100644--- a/packages/playwright-test/types/test.d.ts+++ b/packages/playwright-test/types/test.d.ts@@ -2598,7 +2598,6 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue* @param fixtures An object containing fixtures and/or options. Learn more about [fixtures format](https://playwright.dev/docs/test-fixtures).*/extend<T, W extends KeyValue = {}>(fixtures: Fixtures<T, W, TestArgs, WorkerArgs>): TestType<TestArgs & T, WorkerArgs & W>;- extendTest<T, W>(other: TestType<T, W>): TestType<TestArgs & T, WorkerArgs & W>;/*** Returns information about the currently running test. This method can only be called during the test execution,* otherwise it throws.diff --git a/tests/config/baseTest.ts b/tests/config/baseTest.tsindex 84f27a63bc..bddb5a6e80 100644--- a/tests/config/baseTest.ts+++ b/tests/config/baseTest.ts@@ -14,19 +14,27 @@* limitations under the License.*/-import { test } from '@playwright/test';+import { test, TestType, Fixtures } from '@playwright/test';import { commonFixtures, CommonFixtures } from './commonFixtures';import { serverTest } from './serverFixtures';import { coverageTest } from './coverageFixtures';import { platformTest } from './platformFixtures';import { testModeTest } from './testModeFixtures';-export const baseTest = test- .extendTest(coverageTest)- .extendTest(platformTest)- .extendTest(testModeTest)+interface TestTypeEx<TestArgs, WorkerArgs> extends TestType<TestArgs, WorkerArgs> {+ extend<T, W = {}>(fixtures: Fixtures<T, W, TestArgs, WorkerArgs>): TestTypeEx<TestArgs & T, WorkerArgs & W>;+ _extendTest<T, W>(other: TestType<T, W>): TestTypeEx<TestArgs & T, WorkerArgs & W>;+}+type BaseT = (typeof test) extends TestType<infer T, infer W> ? T : never; // eslint-disable-line+type BaseW = (typeof test) extends TestType<infer T, infer W> ? W : never; // eslint-disable-line+export const base = test as TestTypeEx<BaseT, BaseW>;++export const baseTest = base+ ._extendTest(coverageTest)+ ._extendTest(platformTest)+ ._extendTest(testModeTest).extend<CommonFixtures>(commonFixtures)- .extendTest(serverTest)+ ._extendTest(serverTest).extend<{}, { _snapshotSuffix: string }>({_snapshotSuffix: ['', { scope: 'worker' }],});diff --git a/tests/playwright-test/test-extend.spec.ts b/tests/playwright-test/test-extend.spec.tsindex 3b9a377b74..85704980f2 100644--- a/tests/playwright-test/test-extend.spec.ts+++ b/tests/playwright-test/test-extend.spec.ts@@ -181,7 +181,7 @@ test('test.extend should be able to merge', async ({ runInlineTest }) => {fixture2: ({}, use) => use('fixture2'),});- const test3 = test1.extendTest(test2);+ const test3 = test1._extendTest(test2);test3('merged', async ({ param, fixture1, myFixture, fixture2 }) => {console.log('param-' + param);@@ -199,7 +199,7 @@ test('test.extend should be able to merge', async ({ runInlineTest }) => {expect(result.output).toContain('fixture2-fixture2');});-test('test.extend should print nice message when used as extendTest', async ({ runInlineTest }) => {+test('test.extend should print nice message when used as _extendTest', async ({ runInlineTest }) => {const result = await runInlineTest({'a.test.js': `const test1 = pwt.test.extend({});@@ -211,13 +211,13 @@ test('test.extend should print nice message when used as extendTest', async ({ r});expect(result.exitCode).toBe(1);expect(result.passed).toBe(0);- expect(result.output).toContain('Did you mean to call test.extendTest()?');+ expect(result.output).toContain('Did you mean to call test._extendTest()?');});-test('test.extendTest should print nice message when used as extend', async ({ runInlineTest }) => {+test('test._extendTest should print nice message when used as extend', async ({ runInlineTest }) => {const result = await runInlineTest({'a.test.js': `- const test3 = pwt.test.extendTest({});+ const test3 = pwt.test._extendTest({});test3('test', () => {});`,});diff --git a/tests/playwright-test/types-2.spec.ts b/tests/playwright-test/types-2.spec.tsindex 0d1b6965f0..589529a3a6 100644--- a/tests/playwright-test/types-2.spec.ts+++ b/tests/playwright-test/types-2.spec.ts@@ -81,7 +81,9 @@ test('test.extend options should check types', async ({ runTSC }) => {// @ts-expect-errorbar: async ({ baz }, run) => { await run(42); }});- export const test4 = test1.extendTest(test1b);+ // TODO: enable when _extendTest is out of experiment.+ // export const test4 = test1._extendTest(test1b);+ export const test4 = test1;`,'playwright.config.ts': `import { Params } from './helper';@@ -114,7 +116,8 @@ test('test.extend options should check types', async ({ runTSC }) => {test2('my test', async ({ foo, bar }) => {});// @ts-expect-errortest2('my test', async ({ foo, baz }) => {});- test4('my test', async ({ foo, bar }) => {});+ // TODO: enable when _extendTest is out of experiment.+ // test4('my test', async ({ foo, bar }) => {});`});expect(result.exitCode).toBe(0);diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.tsindex b81cef0998..808e9efe17 100644--- a/utils/generate_types/overrides-test.d.ts+++ b/utils/generate_types/overrides-test.d.ts@@ -266,7 +266,6 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValuestep(title: string, body: () => Promise<any>): Promise<any>;expect: Expect;extend<T, W extends KeyValue = {}>(fixtures: Fixtures<T, W, TestArgs, WorkerArgs>): TestType<TestArgs & T, WorkerArgs & W>;- extendTest<T, W>(other: TestType<T, W>): TestType<TestArgs & T, WorkerArgs & W>;info(): TestInfo;}