cherry-pick(#27630): fix: merge{Tests,Expects} via ESM imports (#27641)

This PR cherry-picks the following commits:

- fd2fbe9d2f

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Playwright Service 2023-10-17 13:43:45 -07:00 коммит произвёл GitHub
Родитель a115439b47
Коммит 0594783ed6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 42 добавлений и 0 удалений

Просмотреть файл

@ -28,4 +28,6 @@ export const _android = playwright._android;
export const test = playwright.test; export const test = playwright.test;
export const expect = playwright.expect; export const expect = playwright.expect;
export const defineConfig = playwright.defineConfig; export const defineConfig = playwright.defineConfig;
export const mergeTests = playwright.mergeTests;
export const mergeExpects = playwright.mergeExpects;
export default playwright.test; export default playwright.test;

Просмотреть файл

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