mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-27 13:50:25 +03: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) => {
|
||||
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 });
|
||||
if (wrapper)
|
||||
App = () => wrapper;
|
||||
@ -79,7 +79,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
|
||||
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 });
|
||||
};
|
||||
|
||||
|
@ -79,7 +79,7 @@ const unmountKey = Symbol('unmountKey');
|
||||
|
||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
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 });
|
||||
if (wrapper)
|
||||
App = () => wrapper;
|
||||
@ -88,7 +88,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
const unmount = solidRender(App, rootElement);
|
||||
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 });
|
||||
};
|
||||
|
||||
|
@ -87,7 +87,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
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 });
|
||||
|
||||
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 || {}))
|
||||
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 });
|
||||
};
|
||||
|
||||
|
@ -232,12 +232,12 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
});
|
||||
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 });
|
||||
const instance = app.mount(rootElement);
|
||||
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 });
|
||||
};
|
||||
|
||||
|
@ -161,7 +161,7 @@ const wrapperKey = Symbol('wrapperKey');
|
||||
|
||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
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 });
|
||||
|
||||
const instance = new Vue({
|
||||
@ -175,12 +175,12 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
rootElement.appendChild(instance.$el);
|
||||
/** @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 });
|
||||
};
|
||||
|
||||
window.playwrightUnmount = async rootElement => {
|
||||
const component = /** @type {any} */(rootElement)[instanceKey];
|
||||
const component = rootElement[instanceKey];
|
||||
if (!component)
|
||||
throw new Error('Component was not mounted');
|
||||
component.$destroy();
|
||||
|
@ -24,7 +24,7 @@ export type JsxComponent = {
|
||||
export type MountOptions = {
|
||||
props?: Record<string, any>,
|
||||
slots?: Record<string, any>,
|
||||
on?: { [key: string]: Function },
|
||||
on?: Record<string, Function>,
|
||||
hooksConfig?: any,
|
||||
};
|
||||
|
||||
@ -41,5 +41,7 @@ declare global {
|
||||
playwrightMount(component: Component, rootElement: Element, hooksConfig: any): Promise<void>;
|
||||
playwrightUnmount(rootElement: Element): 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…
Reference in New Issue
Block a user