Skip to content

Commit

Permalink
refactor: add comments to our temporary extractParams function
Browse files Browse the repository at this point in the history
  • Loading branch information
shfx committed Mar 2, 2025
1 parent f48267c commit f37b2bd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/playwright-ct-svelte/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ function isObjectComponent(component) {
return typeof component === 'object' && component && component.__pw_type === 'object-component';
}

// This is a temporary function for extracting parameters from the
// current Playwright mount API to a format accepted by Svelte 5
/** @type {( component: ObjectComponent ) => Record<string, any>} */
function extractParams(component) {
let {props, slots, on} = component;

// Svelte 5 is dropping support for the old slot implementation in
// exchange for prop-based snippets. They have to be of a certain
// type, though. To still support strings as slots for testing
// purposes, we want to convert a string to a Snippet.
slots = Object.fromEntries(
Object.entries(slots ?? {}).map(([key, snippet]) => {
if(typeof snippet === "string") {
Expand All @@ -48,6 +54,9 @@ function extractParams(component) {
})
);

// To support the current Playwright CT "on" mounting API, we want
// to go through all event names and modify their names, as they
// will be used as standard component properties.
on = Object.fromEntries(
Object.entries(on ?? {}).map(([key, fn]) => {
return [`on${key}`, fn]
Expand Down

0 comments on commit f37b2bd

Please sign in to comment.