@stencil/unplugin 5.0.0-beta.19 → 5.0.0-beta.20
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 +73 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -77,6 +77,78 @@ module.exports = {
|
|
|
77
77
|
};
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
## Testing with Vitest
|
|
81
|
+
|
|
82
|
+
### `newSpecPage()` tests
|
|
83
|
+
|
|
84
|
+
`stencilSpecPage()` is a Vite plugin for your `vitest.config.ts`. It transpiles components so they work with `newSpecPage()` from `@stencil/core/testing`, which lets spec tests written for Stencil v4 run under Vitest without changing their imports.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
// vitest.config.ts
|
|
88
|
+
import { defineConfig } from 'vitest/config';
|
|
89
|
+
import { stencilSpecPage } from '@stencil/unplugin';
|
|
90
|
+
|
|
91
|
+
export default defineConfig({
|
|
92
|
+
plugins: [stencilSpecPage()],
|
|
93
|
+
test: {
|
|
94
|
+
include: ['src/**/*.spec.{ts,tsx}'],
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
// src/components/my-button/my-button.spec.ts
|
|
101
|
+
import { newSpecPage } from '@stencil/core/testing';
|
|
102
|
+
import { expect, it } from 'vitest';
|
|
103
|
+
|
|
104
|
+
import { MyButton } from './my-button';
|
|
105
|
+
|
|
106
|
+
it('renders its label', async () => {
|
|
107
|
+
const page = await newSpecPage({
|
|
108
|
+
components: [MyButton],
|
|
109
|
+
html: `<my-button label="Save"></my-button>`,
|
|
110
|
+
});
|
|
111
|
+
expect(page.root!.shadowRoot!.textContent).toBe('Save');
|
|
112
|
+
|
|
113
|
+
page.root!.label = 'Cancel';
|
|
114
|
+
await page.waitForChanges();
|
|
115
|
+
expect(page.root!.shadowRoot!.textContent).toBe('Cancel');
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
In this mode components don't register themselves as custom elements. `newSpecPage()` registers the ones you pass it, in Stencil's mock DOM.
|
|
120
|
+
|
|
121
|
+
The plugin also resolves a bare `@stencil/core` import to `@stencil/core/testing` in test files, so something like `setMode` imported from `@stencil/core` affects the same runtime `newSpecPage()` uses.
|
|
122
|
+
|
|
123
|
+
It takes the same [options](#options) as the other plugins.
|
|
124
|
+
|
|
125
|
+
### Browser and Node tests
|
|
126
|
+
|
|
127
|
+
For tests that import a component and use it as a real custom element, use `stencilVite()`. Components are compiled on the fly, so no Stencil build is needed first, and each one registers itself when its file is imported. A test must import every component it renders, including ones rendered by other components.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
// vitest.config.ts
|
|
131
|
+
import { playwright } from '@vitest/browser-playwright';
|
|
132
|
+
import { defineConfig } from 'vitest/config';
|
|
133
|
+
import { stencilVite } from '@stencil/unplugin';
|
|
134
|
+
|
|
135
|
+
export default defineConfig({
|
|
136
|
+
plugins: [stencilVite()],
|
|
137
|
+
test: {
|
|
138
|
+
browser: {
|
|
139
|
+
enabled: true,
|
|
140
|
+
provider: playwright(),
|
|
141
|
+
headless: true,
|
|
142
|
+
instances: [{ browser: 'chromium' }],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The same plugin works for tests that run in Node with a simulated DOM. Replace the `browser` block with an `environment`: `'jsdom'`, `'happy-dom'`, or the `'stencil'` environment from [`@stencil/vitest`](https://github.com/stenciljs/vitest), which uses Stencil's mock-doc by default.
|
|
149
|
+
|
|
150
|
+
To have `components.d.ts` written while tests run, so the JSX in them type-checks, pass `types: true`.
|
|
151
|
+
|
|
80
152
|
## Options
|
|
81
153
|
|
|
82
154
|
All options are optional.
|
|
@@ -110,6 +182,7 @@ stencilVite({
|
|
|
110
182
|
| `exclude` | `['node_modules/**']` | Files to skip |
|
|
111
183
|
| `dev` | `false` (auto in Vite) | Inject HMR client code into component output |
|
|
112
184
|
| `docs` | `false` | Scan and accumulate component metadata for docs/CEM |
|
|
185
|
+
| `types` | `false` | Write `<srcDir>/components.d.ts` at build start and keep it current as components change |
|
|
113
186
|
| `transpileOptions` | — | Passed through to `transpileSync` (see `TranspileOptions`) |
|
|
114
187
|
|
|
115
188
|
## How it works
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/unplugin",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.20",
|
|
4
4
|
"description": "Universal bundler plugin for Stencil components (Vite, Rollup, Webpack, esbuild)",
|
|
5
5
|
"homepage": "https://stenciljs.com/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typescript": ">5.0.0 <7.0.0",
|
|
46
46
|
"vite": "^8.2.1",
|
|
47
47
|
"vitest": "^4.1.10",
|
|
48
|
-
"@stencil/core": "5.0.0-beta.
|
|
48
|
+
"@stencil/core": "5.0.0-beta.20"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"less": "^4.0.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"postcss-load-config": "^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
55
55
|
"sass": "^1.0.0",
|
|
56
56
|
"typescript": ">=5.0.0",
|
|
57
|
-
"@stencil/core": "^5.0.0 || 5.0.0-beta.
|
|
57
|
+
"@stencil/core": "^5.0.0 || 5.0.0-beta.20"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"less": {
|
|
@@ -73,6 +73,9 @@
|
|
|
73
73
|
"optional": true
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=22.0.0"
|
|
78
|
+
},
|
|
76
79
|
"volta": {
|
|
77
80
|
"extends": "../../package.json"
|
|
78
81
|
},
|