@playwright/experimental-ct-vue 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/registerSource.mjs +32 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/experimental-ct-vue",
3
- "version": "1.41.0",
3
+ "version": "1.41.1",
4
4
  "description": "Playwright Component Testing for Vue",
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.0",
32
+ "@playwright/experimental-ct-core": "1.41.1",
33
33
  "@vitejs/plugin-vue": "^4.2.1"
34
34
  },
35
35
  "bin": {
@@ -22,69 +22,35 @@ import { compile as __pwCompile } from '@vue/compiler-dom';
22
22
  import * as __pwVue from 'vue';
23
23
 
24
24
  /** @typedef {import('../playwright-ct-core/types/component').Component} Component */
25
- /** @typedef {import('../playwright-ct-core/types/component').JsxComponentChild} JsxComponentChild */
26
25
  /** @typedef {import('../playwright-ct-core/types/component').JsxComponent} JsxComponent */
27
26
  /** @typedef {import('../playwright-ct-core/types/component').ObjectComponent} ObjectComponent */
28
27
  /** @typedef {import('vue').Component} FrameworkComponent */
29
28
 
30
- /** @type {Map<string, () => Promise<FrameworkComponent>>} */
31
- const __pwLoaderRegistry = new Map();
32
- /** @type {Map<string, FrameworkComponent>} */
33
- const __pwRegistry = new Map();
34
-
35
- /**
36
- * @param {{[key: string]: () => Promise<FrameworkComponent>}} components
37
- */
38
- export function pwRegister(components) {
39
- for (const [name, value] of Object.entries(components))
40
- __pwLoaderRegistry.set(name, value);
41
- }
29
+ const __pwAllListeners = new Map();
42
30
 
43
31
  /**
44
32
  * @param {any} component
45
- * @returns {component is Component}
33
+ * @returns {component is ObjectComponent}
46
34
  */
47
- function isComponent(component) {
48
- return !(typeof component !== 'object' || Array.isArray(component));
35
+ function isObjectComponent(component) {
36
+ return typeof component === 'object' && component && component.__pw_type === 'object-component';
49
37
  }
50
38
 
51
39
  /**
52
- * @param {Component | JsxComponentChild} component
40
+ * @param {any} component
41
+ * @returns {component is JsxComponent}
53
42
  */
54
- async function __pwResolveComponent(component) {
55
- if (!isComponent(component))
56
- return;
57
-
58
- let componentFactory = __pwLoaderRegistry.get(component.type);
59
- if (!componentFactory) {
60
- // Lookup by shorthand.
61
- for (const [name, value] of __pwLoaderRegistry) {
62
- if (component.type.endsWith(`_${name}_vue`)) {
63
- componentFactory = value;
64
- break;
65
- }
66
- }
67
- }
68
-
69
- if (!componentFactory && component.type[0].toUpperCase() === component.type[0])
70
- throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...__pwRegistry.keys()]}`);
71
-
72
- if (componentFactory)
73
- __pwRegistry.set(component.type, await componentFactory());
74
-
75
- if ('children' in component && component.children?.length)
76
- await Promise.all(component.children.map(child => __pwResolveComponent(child)));
43
+ function isJsxComponent(component) {
44
+ return typeof component === 'object' && component && component.__pw_type === 'jsx';
77
45
  }
78
46
 
79
- const __pwAllListeners = new Map();
80
-
81
47
  /**
82
- * @param {JsxComponentChild} child
48
+ * @param {any} child
83
49
  */
84
50
  function __pwCreateChild(child) {
85
51
  if (Array.isArray(child))
86
52
  return child.map(grandChild => __pwCreateChild(grandChild));
87
- if (isComponent(child))
53
+ if (isJsxComponent(child) || isObjectComponent(child))
88
54
  return __pwCreateWrapper(child);
89
55
  return child;
90
56
  }
@@ -132,14 +98,23 @@ function __pwSlotToFunction(slot) {
132
98
  throw Error(`Invalid slot received.`);
133
99
  }
134
100
 
101
+ /**
102
+ * @param {JsxComponent} component
103
+ * @returns {any[] | undefined}
104
+ */
105
+ function __pwJsxChildArray(component) {
106
+ if (!component.props.children)
107
+ return;
108
+ if (Array.isArray(component.props.children))
109
+ return component.props.children;
110
+ return [component.props.children];
111
+ }
112
+
135
113
  /**
136
114
  * @param {Component} component
137
115
  */
138
116
  function __pwCreateComponent(component) {
139
- let componentFunc = __pwRegistry.get(component.type);
140
- componentFunc = componentFunc || component.type;
141
-
142
- const isVueComponent = componentFunc !== component.type;
117
+ const isVueComponent = typeof component.type !== 'string';
143
118
 
144
119
  /**
145
120
  * @type {(import('vue').VNode | string)[]}
@@ -151,12 +126,12 @@ function __pwCreateComponent(component) {
151
126
  /** @type {{[key: string]: any}} */
152
127
  let props = {};
153
128
 
154
- if (component.kind === 'jsx') {
155
- for (const child of component.children || []) {
156
- if (typeof child !== 'string' && child.type === 'template' && child.kind === 'jsx') {
129
+ if (component.__pw_type === 'jsx') {
130
+ for (const child of __pwJsxChildArray(component) || []) {
131
+ if (isJsxComponent(child) && child.type === 'template') {
157
132
  const slotProperty = Object.keys(child.props).find(k => k.startsWith('v-slot:'));
158
133
  const slot = slotProperty ? slotProperty.substring('v-slot:'.length) : 'default';
159
- slots[slot] = child.children?.map(__pwCreateChild);
134
+ slots[slot] = __pwJsxChildArray(child)?.map(__pwCreateChild);
160
135
  } else {
161
136
  children.push(__pwCreateChild(child));
162
137
  }
@@ -175,16 +150,16 @@ function __pwCreateComponent(component) {
175
150
  }
176
151
  }
177
152
 
178
- if (component.kind === 'object') {
153
+ if (component.__pw_type === 'object-component') {
179
154
  // Vue test util syntax.
180
- for (const [key, value] of Object.entries(component.options?.slots || {})) {
155
+ for (const [key, value] of Object.entries(component.slots || {})) {
181
156
  if (key === 'default')
182
157
  children.push(__pwSlotToFunction(value));
183
158
  else
184
159
  slots[key] = __pwSlotToFunction(value);
185
160
  }
186
- props = component.options?.props || {};
187
- for (const [key, value] of Object.entries(component.options?.on || {}))
161
+ props = component.props || {};
162
+ for (const [key, value] of Object.entries(component.on || {}))
188
163
  listeners[key] = value;
189
164
  }
190
165
 
@@ -197,7 +172,7 @@ function __pwCreateComponent(component) {
197
172
  lastArg = children;
198
173
  }
199
174
 
200
- return { Component: componentFunc, props, slots: lastArg, listeners };
175
+ return { Component: component.type, props, slots: lastArg, listeners };
201
176
  }
202
177
 
203
178
  function __pwWrapFunctions(slots) {
@@ -248,7 +223,6 @@ const __pwAppKey = Symbol('appKey');
248
223
  const __pwWrapperKey = Symbol('wrapperKey');
249
224
 
250
225
  window.playwrightMount = async (component, rootElement, hooksConfig) => {
251
- await __pwResolveComponent(component);
252
226
  const app = __pwCreateApp({
253
227
  render: () => {
254
228
  const wrapper = __pwCreateWrapper(component);
@@ -275,7 +249,6 @@ window.playwrightUnmount = async rootElement => {
275
249
  };
276
250
 
277
251
  window.playwrightUpdate = async (rootElement, component) => {
278
- await __pwResolveComponent(component);
279
252
  const wrapper = rootElement[__pwWrapperKey];
280
253
  if (!wrapper)
281
254
  throw new Error('Component was not mounted');