diff --git a/packages/playwright/test.mjs b/packages/playwright/test.mjs index affa8048dd..7b7e14a34e 100644 --- a/packages/playwright/test.mjs +++ b/packages/playwright/test.mjs @@ -28,4 +28,6 @@ export const _android = playwright._android; export const test = playwright.test; export const expect = playwright.expect; export const defineConfig = playwright.defineConfig; +export const mergeTests = playwright.mergeTests; +export const mergeExpects = playwright.mergeExpects; export default playwright.test; diff --git a/tests/playwright-test/esm.spec.ts b/tests/playwright-test/esm.spec.ts index d3ad3c7360..0a32e35956 100644 --- a/tests/playwright-test/esm.spec.ts +++ b/tests/playwright-test/esm.spec.ts @@ -632,3 +632,43 @@ test('should be able to use use execSync with a Node.js file inside a spec', asy 'fork: hello from hellofork.js', ]); }); + +test('should be able to use mergeTests/mergeExpect', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.mjs': ` + import { test as base, expect as baseExpect, mergeTests, mergeExpects } from '@playwright/test'; + const test = mergeTests( + base.extend({ + myFixture1: '1', + }), + base.extend({ + myFixture2: '2', + }), + ); + + const expect = mergeExpects( + baseExpect.extend({ + async toBeFoo1(page, x) { + return { pass: true, message: () => '' }; + } + }), + baseExpect.extend({ + async toBeFoo2(page, x) { + return { pass: true, message: () => '' }; + } + }), + ); + + test('merged', async ({ myFixture1, myFixture2 }) => { + console.log('%%myFixture1: ' + myFixture1); + console.log('%%myFixture2: ' + myFixture2); + await expect(1).toBeFoo1(); + await expect(1).toBeFoo2(); + }); + `, + }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); + expect(result.outputLines).toContain('myFixture1: 1'); + expect(result.outputLines).toContain('myFixture2: 2'); +});