mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
chore: dedupe ct fixtures (#14002)
This commit is contained in:
parent
1bbefce9af
commit
dc36b0158a
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
const { test: baseTest, expect, devices, _addRunnerPlugin } = require('@playwright/test');
|
||||
const { mount } = require('@playwright/test/lib/mount');
|
||||
const { fixtures } = require('@playwright/test/lib/mount');
|
||||
const path = require('path');
|
||||
|
||||
_addRunnerPlugin(() => {
|
||||
@ -26,30 +26,6 @@ _addRunnerPlugin(() => {
|
||||
() => require('@vitejs/plugin-react')());
|
||||
});
|
||||
|
||||
const test = baseTest.extend({
|
||||
_workerPage: [async ({ browser }, use) => {
|
||||
const page = await browser._wrapApiCall(async () => {
|
||||
const page = await browser.newPage();
|
||||
await page.addInitScript('navigator.serviceWorker.register = () => {}');
|
||||
return page;
|
||||
});
|
||||
await use(page);
|
||||
}, { scope: 'worker' }],
|
||||
|
||||
context: async ({ page }, use) => {
|
||||
await use(page.context());
|
||||
},
|
||||
|
||||
page: async ({ _workerPage }, use) => {
|
||||
await use(_workerPage);
|
||||
},
|
||||
|
||||
mount: async ({ page, baseURL, viewport }, use) => {
|
||||
await use(async (component, options) => {
|
||||
const selector = await mount(page, component, options, baseURL, viewport);
|
||||
return page.locator(selector);
|
||||
});
|
||||
},
|
||||
});
|
||||
const test = baseTest.extend(fixtures);
|
||||
|
||||
module.exports = { test, expect, devices };
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
const { test: baseTest, expect, devices, _addRunnerPlugin } = require('@playwright/test');
|
||||
const { mount } = require('@playwright/test/lib/mount');
|
||||
const { fixtures } = require('@playwright/test/lib/mount');
|
||||
const path = require('path');
|
||||
|
||||
_addRunnerPlugin(() => {
|
||||
@ -26,30 +26,6 @@ _addRunnerPlugin(() => {
|
||||
() => require('@sveltejs/vite-plugin-svelte').svelte());
|
||||
});
|
||||
|
||||
const test = baseTest.extend({
|
||||
_workerPage: [async ({ browser }, use) => {
|
||||
const page = await browser._wrapApiCall(async () => {
|
||||
const page = await browser.newPage();
|
||||
await page.addInitScript('navigator.serviceWorker.register = () => {}');
|
||||
return page;
|
||||
});
|
||||
await use(page);
|
||||
}, { scope: 'worker' }],
|
||||
|
||||
context: async ({ page }, use) => {
|
||||
await use(page.context());
|
||||
},
|
||||
|
||||
page: async ({ _workerPage }, use) => {
|
||||
await use(_workerPage);
|
||||
},
|
||||
|
||||
mount: async ({ page, baseURL, viewport }, use) => {
|
||||
await use(async (component, options) => {
|
||||
const selector = await mount(page, component, options, baseURL, viewport);
|
||||
return page.locator(selector);
|
||||
});
|
||||
},
|
||||
});
|
||||
const test = baseTest.extend(fixtures);
|
||||
|
||||
module.exports = { test, expect, devices };
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
const { test: baseTest, expect, devices, _addRunnerPlugin } = require('@playwright/test');
|
||||
const { mount } = require('@playwright/test/lib/mount');
|
||||
const { fixtures } = require('@playwright/test/lib/mount');
|
||||
const path = require('path');
|
||||
|
||||
_addRunnerPlugin(() => {
|
||||
@ -26,30 +26,6 @@ _addRunnerPlugin(() => {
|
||||
() => require('@vitejs/plugin-vue')());
|
||||
});
|
||||
|
||||
const test = baseTest.extend({
|
||||
_workerPage: [async ({ browser }, use) => {
|
||||
const page = await browser._wrapApiCall(async () => {
|
||||
const page = await browser.newPage();
|
||||
await page.addInitScript('navigator.serviceWorker.register = () => {}');
|
||||
return page;
|
||||
});
|
||||
await use(page);
|
||||
}, { scope: 'worker' }],
|
||||
|
||||
context: async ({ page }, use) => {
|
||||
await use(page.context());
|
||||
},
|
||||
|
||||
page: async ({ _workerPage }, use) => {
|
||||
await use(_workerPage);
|
||||
},
|
||||
|
||||
mount: async ({ page, baseURL, viewport }, use) => {
|
||||
await use(async (component, options) => {
|
||||
const selector = await mount(page, component, options, baseURL, viewport);
|
||||
return page.locator(selector);
|
||||
});
|
||||
},
|
||||
});
|
||||
const test = baseTest.extend(fixtures);
|
||||
|
||||
module.exports = { test, expect, devices };
|
||||
|
@ -14,21 +14,43 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { Page, ViewportSize } from '@playwright/test';
|
||||
import type { Fixtures, Locator, Page, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, ViewportSize } from './types';
|
||||
import { createGuid } from 'playwright-core/lib/utils';
|
||||
|
||||
export async function mount(page: Page, jsxOrType: any, options: any, baseURL: string, viewport: ViewportSize): Promise<string> {
|
||||
return await (page as any)._wrapApiCall(async () => {
|
||||
return await innerMount(page, jsxOrType, options, baseURL, viewport);
|
||||
}, true);
|
||||
}
|
||||
export const fixtures: Fixtures<PlaywrightTestArgs & PlaywrightTestOptions & { mount: (component: any, options: any) => Promise<Locator> }, PlaywrightWorkerArgs & { _workerPage: Page }> = {
|
||||
_workerPage: [async ({ browser }, use) => {
|
||||
const page = await (browser as any)._wrapApiCall(async () => {
|
||||
const page = await browser.newPage();
|
||||
await page.addInitScript('navigator.serviceWorker.register = () => {}');
|
||||
return page;
|
||||
});
|
||||
await use(page);
|
||||
}, { scope: 'worker' }],
|
||||
|
||||
async function innerMount(page: Page, jsxOrType: any, options: any, baseURL: string, viewport: ViewportSize): Promise<string> {
|
||||
context: async ({ page }, use) => {
|
||||
await use(page.context());
|
||||
},
|
||||
|
||||
page: async ({ _workerPage }, use) => {
|
||||
await use(_workerPage);
|
||||
},
|
||||
|
||||
mount: async ({ page, viewport }, use) => {
|
||||
await use(async (component, options) => {
|
||||
const selector = await (page as any)._wrapApiCall(async () => {
|
||||
return await innerMount(page, component, options, viewport || { width: 1280, height: 800 });
|
||||
}, true);
|
||||
return page.locator(selector);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
async function innerMount(page: Page, jsxOrType: any, options: any, viewport: ViewportSize): Promise<string> {
|
||||
await page.goto('about:blank');
|
||||
await (page as any)._resetForReuse();
|
||||
await (page.context() as any)._resetForReuse();
|
||||
await page.setViewportSize(viewport);
|
||||
await page.goto(baseURL);
|
||||
await page.goto(process.env.PLAYWRIGHT_VITE_COMPONENTS_BASE_URL!);
|
||||
|
||||
let component;
|
||||
if (typeof jsxOrType === 'string')
|
||||
|
@ -40,7 +40,7 @@ export function createPlugin(
|
||||
|
||||
configDir = configDirectory;
|
||||
|
||||
process.env.PLAYWRIGHT_TEST_BASE_URL = `http://localhost:${port}/playwright/index.html`;
|
||||
process.env.PLAYWRIGHT_VITE_COMPONENTS_BASE_URL = `http://localhost:${port}/playwright/index.html`;
|
||||
|
||||
viteConfig.root = viteConfig.root || configDir;
|
||||
viteConfig.plugins = viteConfig.plugins || [
|
||||
|
Loading…
Reference in New Issue
Block a user