Skip to content

Commit

Permalink
refactor: revert some style changes and clean some code
Browse files Browse the repository at this point in the history
  • Loading branch information
shfx committed Feb 15, 2025
1 parent d6b3cde commit 0d076a0
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions packages/playwright-ct-svelte/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ import { createRawSnippet } from "svelte";
* @returns {component is ObjectComponent}
*/
function isObjectComponent(component) {
return (
typeof component === 'object' &&
component &&
component.__pw_type === 'object-component'
);
return typeof component === 'object' && component && component.__pw_type === 'object-component';
}

/** @type {( component: ObjectComponent ) => Record<string, any>} */
Expand All @@ -59,7 +55,7 @@ function extractParams(component) {
})
);

return {props, slots, on};
return {...props, ...slots, ...on};
}

const __pwSvelteComponentKey = Symbol('svelteComponent');
Expand All @@ -75,15 +71,9 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
if (!isObjectComponent(component))
throw new Error('JSX mount notation is not supported');

let {props, slots, on} = extractParams(component);

super({
target: rootElement,
props: {
...props,
...slots,
...on,
},
props: extractParams(component),
...options
});
}
Expand All @@ -106,10 +96,9 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
};

window.playwrightUnmount = async rootElement => {
const svelteComponent = /** @type {SvelteComponent} */ (
rootElement[__pwSvelteComponentKey]
);
if (!svelteComponent) throw new Error('Component was not mounted');
const svelteComponent = /** @type {SvelteComponent} */ (rootElement[__pwSvelteComponentKey]);
if (!svelteComponent)
throw new Error('Component was not mounted');
svelteComponent.$destroy();
delete rootElement[__pwSvelteComponentKey];
};
Expand All @@ -118,16 +107,9 @@ window.playwrightUpdate = async (rootElement, component) => {
if (!isObjectComponent(component))
throw new Error('JSX mount notation is not supported');

const svelteComponent = /** @type {SvelteComponent} */ (
rootElement[__pwSvelteComponentKey]
);
if (!svelteComponent) throw new Error('Component was not mounted');

let {props, slots, on} = extractParams(component);
const svelteComponent = /** @type {SvelteComponent} */ (rootElement[__pwSvelteComponentKey]);
if (!svelteComponent)
throw new Error('Component was not mounted');

svelteComponent.$set({
...props,
...slots,
...on,
});
svelteComponent.$set(extractParams(component));
};

0 comments on commit 0d076a0

Please sign in to comment.