@playwright/experimental-ct-react17 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 +11 -70
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/experimental-ct-react17",
|
|
3
|
-
"version": "1.41.
|
|
3
|
+
"version": "1.41.1",
|
|
4
4
|
"description": "Playwright Component Testing for React",
|
|
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
|
"@vitejs/plugin-react": "^4.0.0"
|
|
34
34
|
},
|
|
35
35
|
"bin": {
|
package/registerSource.mjs
CHANGED
|
@@ -17,93 +17,35 @@
|
|
|
17
17
|
// @ts-check
|
|
18
18
|
// This file is injected into the registry as text, no dependencies are allowed.
|
|
19
19
|
|
|
20
|
-
// Don't clash with the user land.
|
|
21
20
|
import __pwReact from 'react';
|
|
22
21
|
import __pwReactDOM from 'react-dom';
|
|
23
|
-
|
|
24
|
-
/** @typedef {import('../playwright-ct-core/types/component').JsxComponentChild} JsxComponentChild */
|
|
25
22
|
/** @typedef {import('../playwright-ct-core/types/component').JsxComponent} JsxComponent */
|
|
26
|
-
/** @typedef {import('react').FunctionComponent} FrameworkComponent */
|
|
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
23
|
|
|
41
24
|
/**
|
|
42
25
|
* @param {any} component
|
|
43
26
|
* @returns {component is JsxComponent}
|
|
44
27
|
*/
|
|
45
|
-
function
|
|
46
|
-
return
|
|
28
|
+
function isJsxComponent(component) {
|
|
29
|
+
return typeof component === 'object' && component && component.__pw_type === 'jsx';
|
|
47
30
|
}
|
|
48
31
|
|
|
49
32
|
/**
|
|
50
|
-
* @param {
|
|
33
|
+
* @param {any} value
|
|
51
34
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// Lookup by shorthand.
|
|
59
|
-
for (const [name, value] of __pwLoaderRegistry) {
|
|
60
|
-
if (component.type.endsWith(`_${name}`)) {
|
|
61
|
-
componentFactory = value;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
35
|
+
function __pwRender(value) {
|
|
36
|
+
return window.__pwTransformObject(value, v => {
|
|
37
|
+
if (isJsxComponent(v)) {
|
|
38
|
+
const component = v;
|
|
39
|
+
const props = component.props ? __pwRender(component.props) : {};
|
|
40
|
+
return { result: __pwReact.createElement(/** @type { any } */ (component.type), { ...props, children: undefined }, props.children) };
|
|
64
41
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!componentFactory && component.type[0].toUpperCase() === component.type[0])
|
|
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());
|
|
72
|
-
|
|
73
|
-
if (component.children?.length)
|
|
74
|
-
await Promise.all(component.children.map(child => __pwResolveComponent(child)));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @param {JsxComponentChild} child
|
|
79
|
-
*/
|
|
80
|
-
function __renderChild(child) {
|
|
81
|
-
if (Array.isArray(child))
|
|
82
|
-
return child.map(grandChild => __renderChild(grandChild));
|
|
83
|
-
if (isComponent(child))
|
|
84
|
-
return __pwRender(child);
|
|
85
|
-
return child;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @param {JsxComponent} component
|
|
90
|
-
*/
|
|
91
|
-
function __pwRender(component) {
|
|
92
|
-
const componentFunc = __pwRegistry.get(component.type);
|
|
93
|
-
const children = component.children?.map(child => __renderChild(child)).filter(child => {
|
|
94
|
-
if (typeof child === 'string')
|
|
95
|
-
return !!child.trim();
|
|
96
|
-
return true;
|
|
97
42
|
});
|
|
98
|
-
const reactChildren = Array.isArray(children) && children.length === 1 ? children[0] : children;
|
|
99
|
-
return __pwReact.createElement(componentFunc || component.type, component.props, reactChildren);
|
|
100
43
|
}
|
|
101
44
|
|
|
102
45
|
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
103
|
-
if (component
|
|
46
|
+
if (!isJsxComponent(component))
|
|
104
47
|
throw new Error('Object mount notation is not supported');
|
|
105
48
|
|
|
106
|
-
await __pwResolveComponent(component);
|
|
107
49
|
let App = () => __pwRender(component);
|
|
108
50
|
for (const hook of window.__pw_hooks_before_mount || []) {
|
|
109
51
|
const wrapper = await hook({ App, hooksConfig });
|
|
@@ -123,9 +65,8 @@ window.playwrightUnmount = async rootElement => {
|
|
|
123
65
|
};
|
|
124
66
|
|
|
125
67
|
window.playwrightUpdate = async (rootElement, component) => {
|
|
126
|
-
if (component
|
|
68
|
+
if (!isJsxComponent(component))
|
|
127
69
|
throw new Error('Object mount notation is not supported');
|
|
128
70
|
|
|
129
|
-
await __pwResolveComponent(component);
|
|
130
71
|
__pwReactDOM.render(__pwRender(component), rootElement);
|
|
131
72
|
};
|