@playwright/experimental-ct-react17 1.40.0-alpha-oct-25-2023 → 1.40.0-alpha-oct-27-2023
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 +13 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/experimental-ct-react17",
|
|
3
|
-
"version": "1.40.0-alpha-oct-
|
|
3
|
+
"version": "1.40.0-alpha-oct-27-2023",
|
|
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.40.0-alpha-oct-
|
|
32
|
+
"@playwright/experimental-ct-core": "1.40.0-alpha-oct-27-2023",
|
|
33
33
|
"@vitejs/plugin-react": "^4.0.0"
|
|
34
34
|
},
|
|
35
35
|
"bin": {
|
package/registerSource.mjs
CHANGED
|
@@ -21,14 +21,13 @@
|
|
|
21
21
|
import __pwReact from 'react';
|
|
22
22
|
import __pwReactDOM from 'react-dom';
|
|
23
23
|
|
|
24
|
-
/** @typedef {import('../playwright-ct-core/types/component').
|
|
24
|
+
/** @typedef {import('../playwright-ct-core/types/component').JsxComponentChild} JsxComponentChild */
|
|
25
25
|
/** @typedef {import('../playwright-ct-core/types/component').JsxComponent} JsxComponent */
|
|
26
|
-
/** @typedef {import('../playwright-ct-core/types/component').ObjectComponent} ObjectComponent */
|
|
27
26
|
/** @typedef {import('react').FunctionComponent} FrameworkComponent */
|
|
28
27
|
|
|
29
28
|
/** @type {Map<string, () => Promise<FrameworkComponent>>} */
|
|
30
29
|
const __pwLoaderRegistry = new Map();
|
|
31
|
-
/** @type {Map<string, FrameworkComponent} */
|
|
30
|
+
/** @type {Map<string, FrameworkComponent>} */
|
|
32
31
|
const __pwRegistry = new Map();
|
|
33
32
|
|
|
34
33
|
/**
|
|
@@ -40,15 +39,15 @@ export function pwRegister(components) {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
/**
|
|
43
|
-
* @param {
|
|
44
|
-
* @returns {component is JsxComponent
|
|
42
|
+
* @param {any} component
|
|
43
|
+
* @returns {component is JsxComponent}
|
|
45
44
|
*/
|
|
46
45
|
function isComponent(component) {
|
|
47
46
|
return !(typeof component !== 'object' || Array.isArray(component));
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
/**
|
|
51
|
-
* @param {
|
|
50
|
+
* @param {JsxComponent | JsxComponentChild} component
|
|
52
51
|
*/
|
|
53
52
|
async function __pwResolveComponent(component) {
|
|
54
53
|
if (!isComponent(component))
|
|
@@ -76,7 +75,7 @@ async function __pwResolveComponent(component) {
|
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
/**
|
|
79
|
-
* @param {
|
|
78
|
+
* @param {JsxComponent | JsxComponentChild} component
|
|
80
79
|
*/
|
|
81
80
|
function __pwRender(component) {
|
|
82
81
|
if (!isComponent(component))
|
|
@@ -84,9 +83,6 @@ function __pwRender(component) {
|
|
|
84
83
|
|
|
85
84
|
const componentFunc = __pwRegistry.get(component.type);
|
|
86
85
|
|
|
87
|
-
if (component.kind !== 'jsx')
|
|
88
|
-
throw new Error('Object mount notation is not supported');
|
|
89
|
-
|
|
90
86
|
return __pwReact.createElement(componentFunc || component.type, component.props, ...component.children.map(child => {
|
|
91
87
|
if (typeof child === 'string')
|
|
92
88
|
return child;
|
|
@@ -99,6 +95,9 @@ function __pwRender(component) {
|
|
|
99
95
|
}
|
|
100
96
|
|
|
101
97
|
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
98
|
+
if (component.kind !== 'jsx')
|
|
99
|
+
throw new Error('Object mount notation is not supported');
|
|
100
|
+
|
|
102
101
|
await __pwResolveComponent(component);
|
|
103
102
|
let App = () => __pwRender(component);
|
|
104
103
|
for (const hook of window.__pw_hooks_before_mount || []) {
|
|
@@ -119,6 +118,9 @@ window.playwrightUnmount = async rootElement => {
|
|
|
119
118
|
};
|
|
120
119
|
|
|
121
120
|
window.playwrightUpdate = async (rootElement, component) => {
|
|
121
|
+
if (component.kind !== 'jsx')
|
|
122
|
+
throw new Error('Object mount notation is not supported');
|
|
123
|
+
|
|
122
124
|
await __pwResolveComponent(component);
|
|
123
|
-
__pwReactDOM.render(__pwRender(
|
|
125
|
+
__pwReactDOM.render(__pwRender(component), rootElement);
|
|
124
126
|
};
|