@stencil/vitest 1.1.20 → 1.2.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-serializer.d.ts","sourceRoot":"","sources":["../../src/testing/html-serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkCH,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,qCAAqC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oCAAoC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,gBAAgB,GAAG,MAAM,EAC3D,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAWR;AAyID;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"html-serializer.d.ts","sourceRoot":"","sources":["../../src/testing/html-serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkCH,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,qCAAqC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oCAAoC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,gBAAgB,GAAG,MAAM,EAC3D,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAWR;AAyID;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAuDjD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -195,14 +195,18 @@ export function prettifyHtml(html) {
|
|
|
195
195
|
lines.push(' '.repeat(indentLevel * indentSize) + part);
|
|
196
196
|
}
|
|
197
197
|
else if (part.endsWith('/>')) {
|
|
198
|
-
// Self-closing tag
|
|
198
|
+
// Self-closing tag (XML style)
|
|
199
199
|
lines.push(' '.repeat(indentLevel * indentSize) + part);
|
|
200
200
|
}
|
|
201
201
|
else {
|
|
202
202
|
// Opening tag
|
|
203
203
|
lines.push(' '.repeat(indentLevel * indentSize) + part);
|
|
204
|
-
//
|
|
205
|
-
|
|
204
|
+
// Check if it's a void element - if so, don't increase indent
|
|
205
|
+
const tagName = part.match(/<([^\s>/]+)/)?.[1]?.toLowerCase();
|
|
206
|
+
if (!tagName || !VOID_ELEMENTS.has(tagName)) {
|
|
207
|
+
// Not a void element, increase indent for next content
|
|
208
|
+
indentLevel++;
|
|
209
|
+
}
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
else {
|
package/dist/testing/render.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import type { RenderResult } from '../types.js';
|
|
2
2
|
interface RenderOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Whether to clear existing stage containers before rendering. Defaults to true.
|
|
5
|
+
*/
|
|
3
6
|
clearStage?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Attributes to set on the stage container element. Defaults to { class: 'stencil-component-stage' }.
|
|
9
|
+
*/
|
|
4
10
|
stageAttrs?: Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Wait for the component to be fully rendered before returning.
|
|
13
|
+
* In browser mode, this polls until the element has dimensions.
|
|
14
|
+
* Defaults to true.
|
|
15
|
+
*/
|
|
16
|
+
waitForReady?: boolean;
|
|
5
17
|
}
|
|
6
18
|
/**
|
|
7
19
|
* Render using Stencil's render
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/testing/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAY,MAAM,aAAa,CAAC;AAE1D,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/testing/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAY,MAAM,aAAa,CAAC;AAE1D,UAAU,aAAa;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAwCD;;GAEG;AACH,wBAAsB,MAAM,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,CAAC,GAAG,GAAG,EACvE,KAAK,EAAE,GAAG,EACV,OAAO,GAAE,aAGR,GACA,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CA6I7B"}
|
package/dist/testing/render.js
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
import { render as stencilRender } from '@stencil/core';
|
|
2
2
|
// Track event spies
|
|
3
3
|
const eventSpies = new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* Detect if we're running in a real browser vs a mock DOM environment
|
|
6
|
+
*/
|
|
7
|
+
function isRealBrowser() {
|
|
8
|
+
if (typeof window === 'undefined')
|
|
9
|
+
return false;
|
|
10
|
+
if (!navigator.webdriver)
|
|
11
|
+
return false;
|
|
12
|
+
const ua = navigator?.userAgent ?? '';
|
|
13
|
+
if (ua.includes('jsdom'))
|
|
14
|
+
return false;
|
|
15
|
+
if ('happyDOM' in window)
|
|
16
|
+
return false;
|
|
17
|
+
if ('__stencil_mock_doc__' in window)
|
|
18
|
+
return false;
|
|
19
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Poll until element has dimensions (is rendered/visible in real browser)
|
|
26
|
+
*/
|
|
27
|
+
async function waitForRendered(element, timeout = 5000) {
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
while (Date.now() - start < timeout) {
|
|
30
|
+
const rect = element.getBoundingClientRect();
|
|
31
|
+
if (rect.width > 0 && rect.height > 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await new Promise((r) => requestAnimationFrame(r));
|
|
35
|
+
}
|
|
36
|
+
// Don't throw on timeout - element might be intentionally zero-sized
|
|
37
|
+
}
|
|
4
38
|
/**
|
|
5
39
|
* Render using Stencil's render
|
|
6
40
|
*/
|
|
@@ -8,7 +42,6 @@ export async function render(vnode, options = {
|
|
|
8
42
|
clearStage: true,
|
|
9
43
|
stageAttrs: { class: 'stencil-component-stage' },
|
|
10
44
|
}) {
|
|
11
|
-
// Use Stencil's render which handles VNodes properly in the browser
|
|
12
45
|
const container = document.createElement('div');
|
|
13
46
|
Object.entries(options.stageAttrs || {}).forEach(([key, value]) => {
|
|
14
47
|
container.setAttribute(key, value);
|
|
@@ -19,6 +52,7 @@ export async function render(vnode, options = {
|
|
|
19
52
|
existingStages.forEach((stage) => stage.remove());
|
|
20
53
|
}
|
|
21
54
|
document.body.appendChild(container);
|
|
55
|
+
// Use Stencil's render which handles VNodes properly in the browser
|
|
22
56
|
await stencilRender(vnode, container);
|
|
23
57
|
// Get the rendered element
|
|
24
58
|
const element = container.firstElementChild;
|
|
@@ -29,6 +63,7 @@ export async function render(vnode, options = {
|
|
|
29
63
|
if (typeof element.componentOnReady === 'function') {
|
|
30
64
|
await element.componentOnReady();
|
|
31
65
|
}
|
|
66
|
+
// Define waitForChanges first so we can use it in the ready check
|
|
32
67
|
function waitForChanges(documentElement = element) {
|
|
33
68
|
return new Promise((resolve) => {
|
|
34
69
|
// Wait for Stencil's RAF-based update cycle
|
|
@@ -39,16 +74,15 @@ export async function render(vnode, options = {
|
|
|
39
74
|
const waitComponentOnReady = (elm, promises) => {
|
|
40
75
|
if (!elm)
|
|
41
76
|
return;
|
|
42
|
-
if ('shadowRoot' in elm) {
|
|
77
|
+
if ('shadowRoot' in elm && elm.shadowRoot) {
|
|
43
78
|
waitComponentOnReady(elm.shadowRoot, promises);
|
|
44
79
|
}
|
|
45
80
|
const children = elm.children;
|
|
46
81
|
const len = children.length;
|
|
47
82
|
for (let i = 0; i < len; i++) {
|
|
48
83
|
const childElm = children[i];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
promises.push(childStencilElm.componentOnReady().then(() => { }));
|
|
84
|
+
if (childElm.tagName.includes('-') && typeof childElm.componentOnReady === 'function') {
|
|
85
|
+
promises.push(childElm.componentOnReady().then(() => { }));
|
|
52
86
|
}
|
|
53
87
|
waitComponentOnReady(childElm, promises);
|
|
54
88
|
}
|
|
@@ -61,6 +95,15 @@ export async function render(vnode, options = {
|
|
|
61
95
|
});
|
|
62
96
|
});
|
|
63
97
|
}
|
|
98
|
+
// Wait for component to be fully rendered if requested (default: true)
|
|
99
|
+
if (options.waitForReady !== false) {
|
|
100
|
+
if (isRealBrowser()) {
|
|
101
|
+
// In real browser, poll until element has dimensions
|
|
102
|
+
await waitForRendered(element);
|
|
103
|
+
}
|
|
104
|
+
// Always wait for Stencil's update cycle to complete
|
|
105
|
+
await waitForChanges();
|
|
106
|
+
}
|
|
64
107
|
const setProps = async (newProps) => {
|
|
65
108
|
Object.entries(newProps).forEach(([key, value]) => {
|
|
66
109
|
element[key] = value;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/stenciljs/vitest"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.2.0",
|
|
8
8
|
"description": "First-class testing utilities for Stencil design systems with Vitest",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"type": "module",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"dependencies": {
|
|
98
98
|
"jiti": "^2.6.1",
|
|
99
99
|
"local-pkg": "^1.1.2",
|
|
100
|
-
"vitest-environment-stencil": "1.
|
|
100
|
+
"vitest-environment-stencil": "1.2.0"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
103
|
"@eslint/js": "^9.39.2",
|