@stencil/vitest 1.0.0 → 1.1.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.
- package/README.md +33 -1
- package/dist/bin/stencil-test.js +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/testing/html-serializer.d.ts.map +1 -1
- package/dist/testing/html-serializer.js +14 -2
- package/package.json +19 -20
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ export default defineVitestConfig({
|
|
|
73
73
|
});
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
[refer Vitest documentation for all configuration options](https://vitest.dev/config/)
|
|
76
|
+
[refer to Vitest's documentation for all configuration options](https://vitest.dev/config/)
|
|
77
77
|
|
|
78
78
|
### 3. Load your components
|
|
79
79
|
|
|
@@ -240,6 +240,38 @@ await expect(root).toMatchScreenshot();
|
|
|
240
240
|
|
|
241
241
|
Refer to Vitest's [screenshot testing documentation](https://vitest.dev/guide/snapshot.html#visual-snapshots) for more details.
|
|
242
242
|
|
|
243
|
+
## Utils
|
|
244
|
+
|
|
245
|
+
### `serializeHtml(element, options?)`
|
|
246
|
+
|
|
247
|
+
Serializes an HTML element to a string, including shadow DOM content. Useful for debugging or creating custom assertions.
|
|
248
|
+
|
|
249
|
+
```tsx
|
|
250
|
+
import { serializeHtml } from '@stencil/vitest';
|
|
251
|
+
|
|
252
|
+
const html = serializeHtml(element, {
|
|
253
|
+
serializeShadowRoot: true, // Include shadow DOM (default: true)
|
|
254
|
+
pretty: true, // Prettify output (default: true)
|
|
255
|
+
excludeStyles: true, // Exclude <style> tags (default: true)
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### `prettifyHtml(html)`
|
|
260
|
+
|
|
261
|
+
Formats HTML string with indentation for readability.
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
import { prettifyHtml } from '@stencil/vitest';
|
|
265
|
+
|
|
266
|
+
const formatted = prettifyHtml('<div><span>Hello</span></div>');
|
|
267
|
+
// Returns:
|
|
268
|
+
// <div>
|
|
269
|
+
// <span>
|
|
270
|
+
// Hello
|
|
271
|
+
// </span>
|
|
272
|
+
// </div>
|
|
273
|
+
```
|
|
274
|
+
|
|
243
275
|
## CLI
|
|
244
276
|
|
|
245
277
|
The `stencil-test` CLI wraps both Stencil builds with Vitest testing.
|
package/dist/bin/stencil-test.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import './testing/matchers.js';
|
|
|
2
2
|
import './testing/snapshot-serializer.js';
|
|
3
3
|
export { h } from '@stencil/core';
|
|
4
4
|
export { render } from './testing/render.js';
|
|
5
|
+
export { serializeHtml, prettifyHtml, SerializeOptions } from './testing/html-serializer.js';
|
|
5
6
|
export type { RenderOptions, RenderResult } from './types.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAC7F,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-serializer.d.ts","sourceRoot":"","sources":["../../src/testing/html-serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"html-serializer.d.ts","sourceRoot":"","sources":["../../src/testing/html-serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,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;AAoGD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkDjD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -53,7 +53,11 @@ function serializeElementWithShadow(element, excludeStyles, serializeShadowRoot
|
|
|
53
53
|
}
|
|
54
54
|
html += '>';
|
|
55
55
|
// Add shadow DOM if present and requested
|
|
56
|
-
|
|
56
|
+
// Also check for Stencil non-shadow components with __childNodes (slot polyfill)
|
|
57
|
+
const stencilElem = elem;
|
|
58
|
+
const hasShadowRoot = serializeShadowRoot && 'shadowRoot' in elem && elem.shadowRoot;
|
|
59
|
+
const hasStencilPolyfill = serializeShadowRoot && '__childNodes' in stencilElem && stencilElem.__childNodes;
|
|
60
|
+
if (hasShadowRoot) {
|
|
57
61
|
// Use mock:shadow-root format to match mock-doc's output
|
|
58
62
|
html += '<mock:shadow-root>';
|
|
59
63
|
// Serialize shadow DOM children
|
|
@@ -77,7 +81,15 @@ function serializeElementWithShadow(element, excludeStyles, serializeShadowRoot
|
|
|
77
81
|
html += '</mock:shadow-root>';
|
|
78
82
|
}
|
|
79
83
|
// Add light DOM children
|
|
80
|
-
|
|
84
|
+
// For Stencil non-shadow components with slot polyfill, use __childNodes to access actual DOM
|
|
85
|
+
let childNodes;
|
|
86
|
+
if (hasStencilPolyfill) {
|
|
87
|
+
childNodes = stencilElem.__childNodes;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
childNodes = elem.childNodes;
|
|
91
|
+
}
|
|
92
|
+
const children = Array.from(childNodes);
|
|
81
93
|
for (const child of children) {
|
|
82
94
|
if (child.nodeType === 1) {
|
|
83
95
|
// Element node
|
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.1.0",
|
|
8
8
|
"description": "First-class testing utilities for Stencil design systems with Vitest",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"type": "module",
|
|
@@ -56,22 +56,6 @@
|
|
|
56
56
|
"web components",
|
|
57
57
|
"component testing"
|
|
58
58
|
],
|
|
59
|
-
"scripts": {
|
|
60
|
-
"build": "tsc && tsc -p tsconfig.bin.json",
|
|
61
|
-
"dev": "tsc --watch",
|
|
62
|
-
"test:e2e": "pnpm --filter test-project test",
|
|
63
|
-
"test:unit": "vitest run",
|
|
64
|
-
"test:unit:watch": "vitest",
|
|
65
|
-
"test:engines": "pnpm installed-check --no-workspaces --ignore-dev",
|
|
66
|
-
"lint": "eslint .",
|
|
67
|
-
"lint:fix": "eslint . --fix",
|
|
68
|
-
"format": "prettier --check .",
|
|
69
|
-
"format:fix": "prettier --write .",
|
|
70
|
-
"knip": "knip",
|
|
71
|
-
"quality": "pnpm format && pnpm lint && pnpm knip",
|
|
72
|
-
"quality:fix": "pnpm format:fix && pnpm lint:fix && pnpm knip",
|
|
73
|
-
"release": "semantic-release"
|
|
74
|
-
},
|
|
75
59
|
"publishConfig": {
|
|
76
60
|
"access": "public"
|
|
77
61
|
},
|
|
@@ -108,7 +92,7 @@
|
|
|
108
92
|
"dependencies": {
|
|
109
93
|
"jiti": "^2.6.1",
|
|
110
94
|
"local-pkg": "^1.1.2",
|
|
111
|
-
"vitest-environment-stencil": "
|
|
95
|
+
"vitest-environment-stencil": "1.1.0"
|
|
112
96
|
},
|
|
113
97
|
"devDependencies": {
|
|
114
98
|
"@eslint/js": "^9.39.2",
|
|
@@ -132,5 +116,20 @@
|
|
|
132
116
|
"engines": {
|
|
133
117
|
"node": "^20.0.0 || ^22.0.0 || >=24.0.0"
|
|
134
118
|
},
|
|
135
|
-
"
|
|
136
|
-
|
|
119
|
+
"scripts": {
|
|
120
|
+
"build": "tsc && tsc -p tsconfig.bin.json",
|
|
121
|
+
"dev": "tsc --watch",
|
|
122
|
+
"test:e2e": "pnpm --filter test-project test",
|
|
123
|
+
"test:unit": "vitest run",
|
|
124
|
+
"test:unit:watch": "vitest",
|
|
125
|
+
"test:engines": "pnpm installed-check --no-workspaces --ignore-dev",
|
|
126
|
+
"lint": "eslint .",
|
|
127
|
+
"lint:fix": "eslint . --fix",
|
|
128
|
+
"format": "prettier --check .",
|
|
129
|
+
"format:fix": "prettier --write .",
|
|
130
|
+
"knip": "knip",
|
|
131
|
+
"quality": "pnpm format && pnpm lint && pnpm knip",
|
|
132
|
+
"quality:fix": "pnpm format:fix && pnpm lint:fix && pnpm knip",
|
|
133
|
+
"release": "semantic-release"
|
|
134
|
+
}
|
|
135
|
+
}
|