@stencil/unplugin 5.0.0-beta.2 → 5.0.0-beta.21
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 +78 -1
- package/dist/index.d.mts +15 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1061 -348
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
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,16 +182,21 @@ 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
|
|
116
189
|
|
|
117
190
|
### Component transform
|
|
118
191
|
|
|
119
|
-
Only files containing Stencil decorators (`@Component`, `@Prop`, `@State`, etc.) are
|
|
192
|
+
Only files containing Stencil decorators (`@Component`, `@Prop`, `@State`, etc.) are compiled. Everything else passes through untouched, apart from `Build` flag folding (below).
|
|
120
193
|
|
|
121
194
|
Matching files are compiled with `componentExport: 'customelement'`, which means each component self-registers via `customElements.define` (if not already defined) when the module is imported — no separate registration step needed.
|
|
122
195
|
|
|
196
|
+
### `Build` flags
|
|
197
|
+
|
|
198
|
+
In production builds, `Build.isBrowser` / `Build.isServer` checks are replaced with `true` / `false`, so server-only code is tree-shaken out of browser bundles.
|
|
199
|
+
|
|
123
200
|
### CSS pipeline
|
|
124
201
|
|
|
125
202
|
Stencil emits style imports with query parameters (e.g. `./my-comp.css?tag=my-comp&encapsulation=shadow`). The plugin intercepts these and runs them through the following pipeline (each step only runs if the peer dep is installed):
|
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ type TranspileCompatKeys = 'lightDomPatches' | 'lifecycleDOMEvents' | 'initializ
|
|
|
7
7
|
*
|
|
8
8
|
* Auto-populated from the project's `stencil.config.ts`; values set here override the auto-detected ones.
|
|
9
9
|
*/
|
|
10
|
-
type StencilConfigSubset = Pick<StencilConfig, 'signalBacking'> & {
|
|
10
|
+
type StencilConfigSubset = Pick<StencilConfig, 'signalBacking' | 'hydratedFlag' | 'srcDir'> & {
|
|
11
11
|
compat?: Pick<ConfigCompat, TranspileCompatKeys>;
|
|
12
12
|
};
|
|
13
13
|
interface StencilPluginOptions {
|
|
@@ -56,6 +56,14 @@ interface StencilPluginOptions {
|
|
|
56
56
|
* preset) to avoid paying the startup scan cost for non-docs builds.
|
|
57
57
|
*/
|
|
58
58
|
docs?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* When `true`, the plugin writes `<srcDir>/components.d.ts` - the same typings `stencil build`
|
|
61
|
+
* generates, CSS-only components included - at build start, and keeps it current as component
|
|
62
|
+
* sources change. For projects whose dev loop doesn't run the Stencil compiler (e.g. Storybook).
|
|
63
|
+
*
|
|
64
|
+
* Uses the same project scan as `docs`. Off by default.
|
|
65
|
+
*/
|
|
66
|
+
types?: boolean;
|
|
59
67
|
/**
|
|
60
68
|
* Stencil config flags that affect transpilation. The plugin automatically
|
|
61
69
|
* detects and reads `stencil.config.ts` from the project root — set this only
|
|
@@ -67,17 +75,19 @@ interface StencilPluginOptions {
|
|
|
67
75
|
stencilConfig?: StencilConfigSubset;
|
|
68
76
|
}
|
|
69
77
|
//#endregion
|
|
70
|
-
//#region src/
|
|
71
|
-
declare const STENCIL_DOCS_ID = "@stencil/unplugin/docs";
|
|
78
|
+
//#region src/project-scan.d.ts
|
|
72
79
|
/**
|
|
73
80
|
* Returns the current CEM. Only populated when `docs: true` is set.
|
|
74
81
|
* @returns the current CEM, or an empty CEM if `docs: true` was not set.
|
|
75
82
|
*/
|
|
76
83
|
declare function getStencilCEM(): CustomElementsManifest;
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/plugin.d.ts
|
|
86
|
+
declare const STENCIL_DOCS_ID = "@stencil/unplugin/docs";
|
|
77
87
|
declare const unpluginStencil: import("unplugin").UnpluginInstance<StencilPluginOptions | undefined, boolean>;
|
|
78
88
|
//#endregion
|
|
79
89
|
//#region src/index.d.ts
|
|
80
|
-
declare const stencilVite: (options?: StencilPluginOptions | undefined) => import("
|
|
90
|
+
declare const stencilVite: (options?: StencilPluginOptions | undefined) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
|
|
81
91
|
declare const stencilRollup: (options?: StencilPluginOptions | undefined) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
|
|
82
92
|
declare const stencilWebpack: (options?: StencilPluginOptions | undefined) => WebpackPluginInstance;
|
|
83
93
|
declare const stencilEsbuild: (options?: StencilPluginOptions | undefined) => import("unplugin").EsbuildPlugin;
|
|
@@ -93,7 +103,7 @@ declare const stencilRspack: (options?: StencilPluginOptions | undefined) => Rsp
|
|
|
93
103
|
* @param options - plugin options; `mode` is fixed to `'spec-page'` and cannot be overridden
|
|
94
104
|
* @returns a Vite plugin
|
|
95
105
|
*/
|
|
96
|
-
declare const stencilSpecPage: (options?: Omit<StencilPluginOptions, "mode">) => import("
|
|
106
|
+
declare const stencilSpecPage: (options?: Omit<StencilPluginOptions, "mode">) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
|
|
97
107
|
//#endregion
|
|
98
108
|
export { STENCIL_DOCS_ID, type StencilPluginOptions, getStencilCEM, stencilEsbuild, stencilRollup, stencilRspack, stencilSpecPage, stencilVite, stencilWebpack, unpluginStencil };
|
|
99
109
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/options.ts","../src/plugin.ts","../src/index.ts"],"mappings":";;KAEK;;;;;;;KAQO,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/options.ts","../src/project-scan.ts","../src/plugin.ts","../src/index.ts"],"mappings":";;KAEK;;;;;;;KAQO,sBAAsB,KAChC;EAGA,SAAS,KAAK,cAAc;;UAGb;;;;;;EAMf,mBAAmB,KACjB;;;;;;;;;;;;;;EAsBF;;;;;EAMA;;;;EAKA;;;;;;EAOA;;;;;;;;;;EAWA;;;;;;;;EASA;;;;;;;;;EAUA,gBAAgB;;;;;;;;iBCtCF,iBAAiB;;;cCwBpB;cAqFA,oCAAe,iBAAA;;;cC/Jf,cAAW,UAAA,oDAAA,6BAAA;cACX,gBAAa,UAAA,wDAAA,uCAAA;cACb,iBAAc,UAAA,qCAAA;cACd,iBAAc,UAAA,wDAAA;cACd,gBAAa,UAAA,qCAAA;;;;;;;;;;;;cAab,kBAAmB,UAAS,KAAK,iDAAkC,6BAAA"}
|