@playwright/experimental-ct-react17 1.32.0-alpha-1679083379000 → 1.32.0-beta-1679101708000
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/register.d.ts +1 -1
- package/register.mjs +2 -2
- package/registerSource.mjs +16 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/experimental-ct-react17",
|
|
3
|
-
"version": "1.32.0-
|
|
3
|
+
"version": "1.32.0-beta-1679101708000",
|
|
4
4
|
"description": "Playwright Component Testing for React",
|
|
5
5
|
"repository": "github:Microsoft/playwright",
|
|
6
6
|
"homepage": "https://playwright.dev",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@vitejs/plugin-react": "^3.1.0",
|
|
30
|
-
"@playwright/test": "1.32.0-
|
|
30
|
+
"@playwright/test": "1.32.0-beta-1679101708000",
|
|
31
31
|
"vite": "^4.1.1"
|
|
32
32
|
},
|
|
33
33
|
"bin": {
|
package/register.d.ts
CHANGED
package/register.mjs
CHANGED
package/registerSource.mjs
CHANGED
|
@@ -17,34 +17,35 @@
|
|
|
17
17
|
// @ts-check
|
|
18
18
|
// This file is injected into the registry as text, no dependencies are allowed.
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
import
|
|
20
|
+
// Don't clash with the user land.
|
|
21
|
+
import __pwReact from 'react';
|
|
22
|
+
import __pwReactDOM from 'react-dom';
|
|
22
23
|
|
|
23
24
|
/** @typedef {import('../playwright-test/types/component').Component} Component */
|
|
24
25
|
/** @typedef {import('react').FunctionComponent} FrameworkComponent */
|
|
25
26
|
|
|
26
27
|
/** @type {Map<string, FrameworkComponent>} */
|
|
27
|
-
const
|
|
28
|
+
const __pwRegistry = new Map();
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* @param {{[key: string]: FrameworkComponent}} components
|
|
31
32
|
*/
|
|
32
|
-
export function
|
|
33
|
+
export function pwRegister(components) {
|
|
33
34
|
for (const [name, value] of Object.entries(components))
|
|
34
|
-
|
|
35
|
+
__pwRegistry.set(name, value);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* @param {Component} component
|
|
39
40
|
*/
|
|
40
|
-
function
|
|
41
|
+
function __pwRender(component) {
|
|
41
42
|
if (typeof component !== 'object' || Array.isArray(component))
|
|
42
43
|
return component;
|
|
43
44
|
|
|
44
|
-
let componentFunc =
|
|
45
|
+
let componentFunc = __pwRegistry.get(component.type);
|
|
45
46
|
if (!componentFunc) {
|
|
46
47
|
// Lookup by shorthand.
|
|
47
|
-
for (const [name, value] of
|
|
48
|
+
for (const [name, value] of __pwRegistry) {
|
|
48
49
|
if (component.type.endsWith(`_${name}`)) {
|
|
49
50
|
componentFunc = value;
|
|
50
51
|
break;
|
|
@@ -53,17 +54,17 @@ function render(component) {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
if (!componentFunc && component.type[0].toUpperCase() === component.type[0])
|
|
56
|
-
throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...
|
|
57
|
+
throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...__pwRegistry.keys()]}`);
|
|
57
58
|
|
|
58
59
|
const componentFuncOrString = componentFunc || component.type;
|
|
59
60
|
|
|
60
61
|
if (component.kind !== 'jsx')
|
|
61
62
|
throw new Error('Object mount notation is not supported');
|
|
62
63
|
|
|
63
|
-
return
|
|
64
|
+
return __pwReact.createElement(componentFuncOrString, component.props, ...component.children.map(child => {
|
|
64
65
|
if (typeof child === 'string')
|
|
65
66
|
return child;
|
|
66
|
-
return
|
|
67
|
+
return __pwRender(child);
|
|
67
68
|
}).filter(child => {
|
|
68
69
|
if (typeof child === 'string')
|
|
69
70
|
return !!child.trim();
|
|
@@ -72,24 +73,24 @@ function render(component) {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
75
|
-
let App = () =>
|
|
76
|
+
let App = () => __pwRender(component);
|
|
76
77
|
for (const hook of window.__pw_hooks_before_mount || []) {
|
|
77
78
|
const wrapper = await hook({ App, hooksConfig });
|
|
78
79
|
if (wrapper)
|
|
79
80
|
App = () => wrapper;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
__pwReactDOM.render(App(), rootElement);
|
|
83
84
|
|
|
84
85
|
for (const hook of window.__pw_hooks_after_mount || [])
|
|
85
86
|
await hook({ hooksConfig });
|
|
86
87
|
};
|
|
87
88
|
|
|
88
89
|
window.playwrightUnmount = async rootElement => {
|
|
89
|
-
if (!
|
|
90
|
+
if (!__pwReactDOM.unmountComponentAtNode(rootElement))
|
|
90
91
|
throw new Error('Component was not mounted');
|
|
91
92
|
};
|
|
92
93
|
|
|
93
94
|
window.playwrightUpdate = async (rootElement, component) => {
|
|
94
|
-
|
|
95
|
+
__pwReactDOM.render(__pwRender(/** @type {Component} */(component)), rootElement);
|
|
95
96
|
};
|