mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore(ct): improve internal hook types (#20722)
This commit is contained in:
parent
59121a3c37
commit
4a3d79f291
@ -71,7 +71,7 @@ function render(component) {
|
|||||||
|
|
||||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||||
let App = () => render(component);
|
let App = () => render(component);
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_before_mount || []) {
|
for (const hook of window.__pw_hooks_before_mount || []) {
|
||||||
const wrapper = await hook({ App, hooksConfig });
|
const wrapper = await hook({ App, hooksConfig });
|
||||||
if (wrapper)
|
if (wrapper)
|
||||||
App = () => wrapper;
|
App = () => wrapper;
|
||||||
@ -79,7 +79,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|||||||
|
|
||||||
ReactDOM.render(App(), rootElement);
|
ReactDOM.render(App(), rootElement);
|
||||||
|
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_after_mount || [])
|
for (const hook of window.__pw_hooks_after_mount || [])
|
||||||
await hook({ hooksConfig });
|
await hook({ hooksConfig });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,7 @@ const unmountKey = Symbol('unmountKey');
|
|||||||
|
|
||||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||||
let App = () => createComponent(component);
|
let App = () => createComponent(component);
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_before_mount || []) {
|
for (const hook of window.__pw_hooks_before_mount || []) {
|
||||||
const wrapper = await hook({ App, hooksConfig });
|
const wrapper = await hook({ App, hooksConfig });
|
||||||
if (wrapper)
|
if (wrapper)
|
||||||
App = () => wrapper;
|
App = () => wrapper;
|
||||||
@ -88,7 +88,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|||||||
const unmount = solidRender(App, rootElement);
|
const unmount = solidRender(App, rootElement);
|
||||||
rootElement[unmountKey] = unmount;
|
rootElement[unmountKey] = unmount;
|
||||||
|
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_after_mount || [])
|
for (const hook of window.__pw_hooks_after_mount || [])
|
||||||
await hook({ hooksConfig });
|
await hook({ hooksConfig });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -87,7 +87,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|||||||
throw new Error('JSX mount notation is not supported');
|
throw new Error('JSX mount notation is not supported');
|
||||||
|
|
||||||
|
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_before_mount || [])
|
for (const hook of window.__pw_hooks_before_mount || [])
|
||||||
await hook({ hooksConfig });
|
await hook({ hooksConfig });
|
||||||
|
|
||||||
const svelteComponent = /** @type {SvelteComponent} */ (new componentCtor({
|
const svelteComponent = /** @type {SvelteComponent} */ (new componentCtor({
|
||||||
@ -103,7 +103,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|||||||
for (const [key, listener] of Object.entries(component.options?.on || {}))
|
for (const [key, listener] of Object.entries(component.options?.on || {}))
|
||||||
svelteComponent.$on(key, event => listener(event.detail));
|
svelteComponent.$on(key, event => listener(event.detail));
|
||||||
|
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_after_mount || [])
|
for (const hook of window.__pw_hooks_after_mount || [])
|
||||||
await hook({ hooksConfig, svelteComponent });
|
await hook({ hooksConfig, svelteComponent });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -232,12 +232,12 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|||||||
});
|
});
|
||||||
setDevtoolsHook(createDevTools(), {});
|
setDevtoolsHook(createDevTools(), {});
|
||||||
|
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_before_mount || [])
|
for (const hook of window.__pw_hooks_before_mount || [])
|
||||||
await hook({ app, hooksConfig });
|
await hook({ app, hooksConfig });
|
||||||
const instance = app.mount(rootElement);
|
const instance = app.mount(rootElement);
|
||||||
rootElement[appKey] = app;
|
rootElement[appKey] = app;
|
||||||
|
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_after_mount || [])
|
for (const hook of window.__pw_hooks_after_mount || [])
|
||||||
await hook({ app, hooksConfig, instance });
|
await hook({ app, hooksConfig, instance });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -161,7 +161,7 @@ const wrapperKey = Symbol('wrapperKey');
|
|||||||
|
|
||||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||||
let options = {};
|
let options = {};
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_before_mount || [])
|
for (const hook of window.__pw_hooks_before_mount || [])
|
||||||
options = await hook({ hooksConfig, Vue });
|
options = await hook({ hooksConfig, Vue });
|
||||||
|
|
||||||
const instance = new Vue({
|
const instance = new Vue({
|
||||||
@ -175,12 +175,12 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|||||||
rootElement.appendChild(instance.$el);
|
rootElement.appendChild(instance.$el);
|
||||||
/** @type {any} */ (rootElement)[instanceKey] = instance;
|
/** @type {any} */ (rootElement)[instanceKey] = instance;
|
||||||
|
|
||||||
for (const hook of /** @type {any} */(window).__pw_hooks_after_mount || [])
|
for (const hook of window.__pw_hooks_after_mount || [])
|
||||||
await hook({ hooksConfig, instance });
|
await hook({ hooksConfig, instance });
|
||||||
};
|
};
|
||||||
|
|
||||||
window.playwrightUnmount = async rootElement => {
|
window.playwrightUnmount = async rootElement => {
|
||||||
const component = /** @type {any} */(rootElement)[instanceKey];
|
const component = rootElement[instanceKey];
|
||||||
if (!component)
|
if (!component)
|
||||||
throw new Error('Component was not mounted');
|
throw new Error('Component was not mounted');
|
||||||
component.$destroy();
|
component.$destroy();
|
||||||
|
|||||||
@ -24,7 +24,7 @@ export type JsxComponent = {
|
|||||||
export type MountOptions = {
|
export type MountOptions = {
|
||||||
props?: Record<string, any>,
|
props?: Record<string, any>,
|
||||||
slots?: Record<string, any>,
|
slots?: Record<string, any>,
|
||||||
on?: { [key: string]: Function },
|
on?: Record<string, Function>,
|
||||||
hooksConfig?: any,
|
hooksConfig?: any,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,5 +41,7 @@ declare global {
|
|||||||
playwrightMount(component: Component, rootElement: Element, hooksConfig: any): Promise<void>;
|
playwrightMount(component: Component, rootElement: Element, hooksConfig: any): Promise<void>;
|
||||||
playwrightUnmount(rootElement: Element): Promise<void>;
|
playwrightUnmount(rootElement: Element): Promise<void>;
|
||||||
playwrightUpdate(rootElement: Element, component: Component): Promise<void>;
|
playwrightUpdate(rootElement: Element, component: Component): Promise<void>;
|
||||||
|
__pw_hooks_before_mount?: (<HooksConfig>(params: { hooksConfig: HooksConfig; } & any) => Promise<any>)[];
|
||||||
|
__pw_hooks_after_mount?: (<HooksConfig>(params: { hooksConfig: HooksConfig; } & any) => Promise<void>)[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user