fix: merge{Tests,Expects} via ESM imports (#27630)

Backport to 1.39.X?

Fixes https://github.com/microsoft/playwright/issues/27617
This commit is contained in:
Max Schmitt 2023-10-17 00:09:44 +02:00 committed by GitHub
parent f8277ca99c
commit fd2fbe9d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View file

@ -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;

View file

@ -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');
});