@playwright/experimental-ct-svelte 1.41.0 → 1.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/registerSource.mjs +12 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/experimental-ct-svelte",
|
|
3
|
-
"version": "1.41.
|
|
3
|
+
"version": "1.41.1",
|
|
4
4
|
"description": "Playwright Component Testing for Svelte",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@playwright/experimental-ct-core": "1.41.
|
|
32
|
+
"@playwright/experimental-ct-core": "1.41.1",
|
|
33
33
|
"@sveltejs/vite-plugin-svelte": "^3.0.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
package/registerSource.mjs
CHANGED
|
@@ -25,50 +25,12 @@ import { detach as __pwDetach, insert as __pwInsert, noop as __pwNoop } from 'sv
|
|
|
25
25
|
/** @typedef {any} FrameworkComponent */
|
|
26
26
|
/** @typedef {import('svelte').SvelteComponent} SvelteComponent */
|
|
27
27
|
|
|
28
|
-
/** @type {Map<string, () => Promise<FrameworkComponent>>} */
|
|
29
|
-
const __pwLoaderRegistry = new Map();
|
|
30
|
-
/** @type {Map<string, FrameworkComponent>} */
|
|
31
|
-
const __pwRegistry = new Map();
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {{[key: string]: () => Promise<FrameworkComponent>}} components
|
|
35
|
-
*/
|
|
36
|
-
export function pwRegister(components) {
|
|
37
|
-
for (const [name, value] of Object.entries(components))
|
|
38
|
-
__pwLoaderRegistry.set(name, value);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
28
|
/**
|
|
42
29
|
* @param {any} component
|
|
43
30
|
* @returns {component is ObjectComponent}
|
|
44
31
|
*/
|
|
45
|
-
function
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param {ObjectComponent} component
|
|
51
|
-
*/
|
|
52
|
-
async function __pwResolveComponent(component) {
|
|
53
|
-
if (!isComponent(component))
|
|
54
|
-
return;
|
|
55
|
-
|
|
56
|
-
let componentFactory = __pwLoaderRegistry.get(component.type);
|
|
57
|
-
if (!componentFactory) {
|
|
58
|
-
// Lookup by shorthand.
|
|
59
|
-
for (const [name, value] of __pwLoaderRegistry) {
|
|
60
|
-
if (component.type.endsWith(`_${name}_svelte`)) {
|
|
61
|
-
componentFactory = value;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!componentFactory)
|
|
68
|
-
throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...__pwRegistry.keys()]}`);
|
|
69
|
-
|
|
70
|
-
if (componentFactory)
|
|
71
|
-
__pwRegistry.set(component.type, await componentFactory());
|
|
32
|
+
function isObjectComponent(component) {
|
|
33
|
+
return typeof component === 'object' && component && component.__pw_type === 'object-component';
|
|
72
34
|
}
|
|
73
35
|
|
|
74
36
|
/**
|
|
@@ -105,19 +67,19 @@ function __pwCreateSlots(slots) {
|
|
|
105
67
|
const __pwSvelteComponentKey = Symbol('svelteComponent');
|
|
106
68
|
|
|
107
69
|
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
108
|
-
if (component
|
|
70
|
+
if (!isObjectComponent(component))
|
|
109
71
|
throw new Error('JSX mount notation is not supported');
|
|
110
72
|
|
|
111
|
-
|
|
112
|
-
const componentCtor =
|
|
73
|
+
const objectComponent = component;
|
|
74
|
+
const componentCtor = component.type;
|
|
113
75
|
|
|
114
76
|
class App extends componentCtor {
|
|
115
77
|
constructor(options = {}) {
|
|
116
78
|
super({
|
|
117
79
|
target: rootElement,
|
|
118
80
|
props: {
|
|
119
|
-
...
|
|
120
|
-
$$slots: __pwCreateSlots(
|
|
81
|
+
...objectComponent.props,
|
|
82
|
+
$$slots: __pwCreateSlots(objectComponent.slots),
|
|
121
83
|
$$scope: {},
|
|
122
84
|
},
|
|
123
85
|
...options
|
|
@@ -134,7 +96,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
|
134
96
|
|
|
135
97
|
rootElement[__pwSvelteComponentKey] = svelteComponent;
|
|
136
98
|
|
|
137
|
-
for (const [key, listener] of Object.entries(
|
|
99
|
+
for (const [key, listener] of Object.entries(objectComponent.on || {}))
|
|
138
100
|
svelteComponent.$on(key, event => listener(event.detail));
|
|
139
101
|
|
|
140
102
|
for (const hook of window.__pw_hooks_after_mount || [])
|
|
@@ -149,17 +111,16 @@ window.playwrightUnmount = async rootElement => {
|
|
|
149
111
|
};
|
|
150
112
|
|
|
151
113
|
window.playwrightUpdate = async (rootElement, component) => {
|
|
152
|
-
if (component
|
|
114
|
+
if (!isObjectComponent(component))
|
|
153
115
|
throw new Error('JSX mount notation is not supported');
|
|
154
116
|
|
|
155
|
-
await __pwResolveComponent(component);
|
|
156
117
|
const svelteComponent = /** @type {SvelteComponent} */ (rootElement[__pwSvelteComponentKey]);
|
|
157
118
|
if (!svelteComponent)
|
|
158
119
|
throw new Error('Component was not mounted');
|
|
159
120
|
|
|
160
|
-
for (const [key, listener] of Object.entries(component.
|
|
121
|
+
for (const [key, listener] of Object.entries(component.on || {}))
|
|
161
122
|
svelteComponent.$on(key, event => listener(event.detail));
|
|
162
123
|
|
|
163
|
-
if (component.
|
|
164
|
-
svelteComponent.$set(component.
|
|
124
|
+
if (component.props)
|
|
125
|
+
svelteComponent.$set(component.props);
|
|
165
126
|
};
|