@stencil/vitest 1.7.2 → 1.8.1
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 +32 -0
- package/dist/bin/stencil-test.js +4 -0
- package/dist/config.js +47 -2
- package/dist/environments/stencil.d.ts.map +1 -1
- package/dist/environments/stencil.js +12 -1
- package/dist/globals.d.ts +23 -0
- package/dist/testing/matchers.d.ts +2 -0
- package/dist/testing/matchers.d.ts.map +1 -1
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -357,6 +357,38 @@ The `stencil-test` CLI supports most of Stencil's CLI options and all of Vitest
|
|
|
357
357
|
- For full Stencil CLI options, see [Stencil CLI docs](https://stenciljs.com/docs/cli).
|
|
358
358
|
- For full Vitest CLI options, see [Vitest CLI docs](https://vitest.dev/guide/cli.html).
|
|
359
359
|
|
|
360
|
+
### Global Variables
|
|
361
|
+
|
|
362
|
+
The `stencil-test` CLI exposes global variables that can be accessed in your tests to check which CLI flags were used:
|
|
363
|
+
|
|
364
|
+
| Global | Type | Description |
|
|
365
|
+
| ------------------- | --------- | -------------------------------------- |
|
|
366
|
+
| `__STENCIL_PROD__` | `boolean` | `true` when `--prod` flag is passed |
|
|
367
|
+
| `__STENCIL_SERVE__` | `boolean` | `true` when `--serve` flag is passed |
|
|
368
|
+
| `__STENCIL_PORT__` | `string` | Port number when `--port` is specified |
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
if (__STENCIL_PROD__) {
|
|
372
|
+
console.log('Running tests against production build');
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (__STENCIL_SERVE__) {
|
|
376
|
+
const baseUrl = `http://localhost:${__STENCIL_PORT__ || '3333'}`;
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
#### TypeScript Support
|
|
381
|
+
|
|
382
|
+
Add to your `tsconfig.json` for type definitions:
|
|
383
|
+
|
|
384
|
+
```json
|
|
385
|
+
{
|
|
386
|
+
"compilerOptions": {
|
|
387
|
+
"types": ["@stencil/vitest/globals"]
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
360
392
|
## License
|
|
361
393
|
|
|
362
394
|
MIT
|
package/dist/bin/stencil-test.js
CHANGED
|
@@ -207,6 +207,10 @@ function runTests() {
|
|
|
207
207
|
env: {
|
|
208
208
|
...process.env,
|
|
209
209
|
NODE_ENV: 'test',
|
|
210
|
+
// Expose CLI flags to tests via environment variables
|
|
211
|
+
STENCIL_PROD: args.prod ? 'true' : '',
|
|
212
|
+
STENCIL_SERVE: args.serve ? 'true' : '',
|
|
213
|
+
STENCIL_PORT: args.port || '',
|
|
210
214
|
},
|
|
211
215
|
});
|
|
212
216
|
vitestProcess.on('exit', (code) => {
|
package/dist/config.js
CHANGED
|
@@ -124,8 +124,37 @@ function generateCoverageExcludes(testIncludes, srcDir) {
|
|
|
124
124
|
function applyStencilDefaults(config, stencilConfig) {
|
|
125
125
|
// Start with the user's config
|
|
126
126
|
const result = { ...config };
|
|
127
|
-
//
|
|
128
|
-
|
|
127
|
+
// Expose STENCIL_* env vars to all test environments
|
|
128
|
+
// These are set by the stencil-test CLI when spawning vitest
|
|
129
|
+
const stencilEnvDefines = {
|
|
130
|
+
__STENCIL_PROD__: JSON.stringify(process.env.STENCIL_PROD === 'true'),
|
|
131
|
+
__STENCIL_SERVE__: JSON.stringify(process.env.STENCIL_SERVE === 'true'),
|
|
132
|
+
__STENCIL_PORT__: JSON.stringify(process.env.STENCIL_PORT || ''),
|
|
133
|
+
};
|
|
134
|
+
if (!result.define) {
|
|
135
|
+
result.define = stencilEnvDefines;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// Merge with existing defines, user's defines take precedence
|
|
139
|
+
result.define = {
|
|
140
|
+
...stencilEnvDefines,
|
|
141
|
+
...result.define,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Add JSX config for the active transformer
|
|
145
|
+
// Vite 7+ uses oxc by default, older versions use esbuild
|
|
146
|
+
if (result.oxc) {
|
|
147
|
+
// oxc is explicitly configured - set JSX options on it
|
|
148
|
+
if (!result.oxc.jsx) {
|
|
149
|
+
result.oxc.jsx = {
|
|
150
|
+
runtime: 'classic',
|
|
151
|
+
pragma: 'h',
|
|
152
|
+
pragmaFrag: 'Fragment',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (!result.esbuild) {
|
|
157
|
+
// No oxc config, set esbuild JSX options (for older Vite versions)
|
|
129
158
|
result.esbuild = {
|
|
130
159
|
jsxFactory: 'h',
|
|
131
160
|
jsxFragment: 'Fragment',
|
|
@@ -307,6 +336,22 @@ function enhanceTestConfig(testConfig, stencilConfig) {
|
|
|
307
336
|
*/
|
|
308
337
|
function enhanceProject(project, stencilConfig) {
|
|
309
338
|
const enhanced = { ...project };
|
|
339
|
+
// Expose STENCIL_* env vars at the project level for browser tests
|
|
340
|
+
// This ensures the defines are available in all project types
|
|
341
|
+
const stencilEnvDefines = {
|
|
342
|
+
__STENCIL_PROD__: JSON.stringify(process.env.STENCIL_PROD === 'true'),
|
|
343
|
+
__STENCIL_SERVE__: JSON.stringify(process.env.STENCIL_SERVE === 'true'),
|
|
344
|
+
__STENCIL_PORT__: JSON.stringify(process.env.STENCIL_PORT || ''),
|
|
345
|
+
};
|
|
346
|
+
if (!enhanced.define) {
|
|
347
|
+
enhanced.define = stencilEnvDefines;
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
enhanced.define = {
|
|
351
|
+
...stencilEnvDefines,
|
|
352
|
+
...enhanced.define,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
310
355
|
// Get output directories from Stencil config
|
|
311
356
|
const outputDirs = getStencilOutputDirs(stencilConfig);
|
|
312
357
|
const defaultExcludes = ['**/node_modules/**', ...outputDirs.map((dir) => `**/${dir}/**`)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stencil.d.ts","sourceRoot":"","sources":["../../src/environments/stencil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"stencil.d.ts","sourceRoot":"","sources":["../../src/environments/stencil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAiBvD,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,cAAc,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;CACrD;AAQD;;;;;;;;;;;;;;;;GAgBG;wBACa,WAAW;AAA3B,wBAmEE"}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
// Dynamically import populateGlobal to support both vitest 4.1+ (vitest/runtime) and older versions (vitest/environments)
|
|
2
|
+
async function getPopulateGlobal() {
|
|
3
|
+
try {
|
|
4
|
+
// Use variable to prevent Vite's static import analysis from failing on older vitest
|
|
5
|
+
const runtimePath = 'vitest/' + 'runtime';
|
|
6
|
+
return (await import(/* @vite-ignore */ runtimePath)).populateGlobal;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return (await import('vitest/environments')).populateGlobal;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
2
12
|
import happyDom from './env/happy-dom.js';
|
|
3
13
|
import jsdom from './env/jsdom.js';
|
|
4
14
|
import mockDoc from './env/mock-doc.js';
|
|
@@ -53,6 +63,7 @@ export default {
|
|
|
53
63
|
win.process.env.NODE_ENV = 'test';
|
|
54
64
|
}
|
|
55
65
|
// Populate global with window properties
|
|
66
|
+
const populateGlobal = await getPopulateGlobal();
|
|
56
67
|
const { keys, originals } = populateGlobal(global, win, {
|
|
57
68
|
bindFunctions: true,
|
|
58
69
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global variables injected by stencil-test CLI via Vite's define config.
|
|
3
|
+
*
|
|
4
|
+
* Usage in tests:
|
|
5
|
+
* ```typescript
|
|
6
|
+
* if (__STENCIL_PROD__) {
|
|
7
|
+
* // Running with --prod flag
|
|
8
|
+
* }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* To get TypeScript support, add to your tsconfig.json:
|
|
12
|
+
* ```json
|
|
13
|
+
* {
|
|
14
|
+
* "compilerOptions": {
|
|
15
|
+
* "types": ["@stencil/vitest/globals"]
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
declare const __STENCIL_PROD__: boolean;
|
|
22
|
+
declare const __STENCIL_SERVE__: boolean;
|
|
23
|
+
declare const __STENCIL_PORT__: string;
|
|
@@ -51,6 +51,8 @@ interface CustomMatchers<R = unknown> {
|
|
|
51
51
|
declare module 'vitest' {
|
|
52
52
|
interface Assertion<T = any> extends CustomMatchers<T> {
|
|
53
53
|
}
|
|
54
|
+
interface Matchers<T = any, R = T> extends CustomMatchers<R> {
|
|
55
|
+
}
|
|
54
56
|
interface AsymmetricMatchersContaining extends CustomMatchers {
|
|
55
57
|
}
|
|
56
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../../src/testing/matchers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,UAAU,cAAc,CAAC,CAAC,GAAG,OAAO;IAClC,mDAAmD;IACnD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC;IAClC,qDAAqD;IACrD,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACvC,gFAAgF;IAChF,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,2EAA2E;IAC3E,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IACtD,mEAAmE;IACnE,gBAAgB,CAAC,SAAS,E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sFAAsF;IACtF,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC;IACrC,+FAA+F;IAC/F,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC;IAC1C,yDAAyD;IACzD,mBAAmB,IAAI,CAAC,CAAC;IACzB,6EAA6E;IAC7E,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;IAC3C,uEAAuE;IACvE,yBAAyB,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;IAC1C,wEAAwE;IACxE,8BAA8B,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;IAC/C,uEAAuE;IACvE,6BAA6B,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;IAC9C,kFAAkF;IAClF,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;CAC7D;AAGD,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,SAAS,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;KAAG;IACzD,UAAU,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;KAAG;IAC/D,UAAU,4BAA6B,SAAQ,cAAc;KAAG;CACjE;AAioBD,OAAO,EAAE,CAAC"}
|
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.8.1",
|
|
8
8
|
"description": "First-class testing utilities for Stencil design systems with Vitest",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"type": "module",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"./environments/stencil": {
|
|
44
44
|
"types": "./dist/environments/stencil.d.ts",
|
|
45
45
|
"import": "./dist/environments/stencil.js"
|
|
46
|
+
},
|
|
47
|
+
"./globals": {
|
|
48
|
+
"types": "./dist/globals.d.ts"
|
|
46
49
|
}
|
|
47
50
|
},
|
|
48
51
|
"files": [
|
|
@@ -97,7 +100,7 @@
|
|
|
97
100
|
"dependencies": {
|
|
98
101
|
"jiti": "^2.6.1",
|
|
99
102
|
"local-pkg": "^1.1.2",
|
|
100
|
-
"vitest-environment-stencil": "1.
|
|
103
|
+
"vitest-environment-stencil": "1.8.1"
|
|
101
104
|
},
|
|
102
105
|
"devDependencies": {
|
|
103
106
|
"@eslint/js": "^9.39.2",
|
|
@@ -108,7 +111,7 @@
|
|
|
108
111
|
"@types/node": "24.10.4",
|
|
109
112
|
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
|
110
113
|
"@typescript-eslint/parser": "^8.50.0",
|
|
111
|
-
"@vitest/coverage-v8": "^4.
|
|
114
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
112
115
|
"eslint": "^9.39.2",
|
|
113
116
|
"installed-check": "^9.3.0",
|
|
114
117
|
"knip": "^5.76.3",
|
|
@@ -116,13 +119,13 @@
|
|
|
116
119
|
"prettier": "^3.7.4",
|
|
117
120
|
"semantic-release": "^25.0.2",
|
|
118
121
|
"typescript": "~5.8.3",
|
|
119
|
-
"vitest": "^4.
|
|
122
|
+
"vitest": "^4.1.0"
|
|
120
123
|
},
|
|
121
124
|
"engines": {
|
|
122
125
|
"node": "^20.0.0 || ^22.0.0 || >=24.0.0"
|
|
123
126
|
},
|
|
124
127
|
"scripts": {
|
|
125
|
-
"build": "tsc && tsc -p tsconfig.bin.json",
|
|
128
|
+
"build": "tsc && tsc -p tsconfig.bin.json && cp src/globals.d.ts dist/globals.d.ts",
|
|
126
129
|
"dev": "tsc --watch",
|
|
127
130
|
"test:e2e": "pnpm --filter test-project test",
|
|
128
131
|
"test:unit": "vitest run",
|