@stencil/vitest 1.9.0 → 1.9.2

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.
@@ -3,6 +3,28 @@ import { spawn } from 'child_process';
3
3
  import { existsSync, unlinkSync, writeFileSync } from 'fs';
4
4
  import { extname, join } from 'path';
5
5
  import { createJiti } from 'jiti';
6
+ /**
7
+ * Creates a clean environment for spawning npm/npx commands.
8
+ * Filters out pnpm-specific npm_config_* variables that npm doesn't recognize,
9
+ * which cause warnings like "Unknown env config" in npm 10+.
10
+ */
11
+ function getCleanNpmEnv(extraEnv = {}) {
12
+ const pnpmOnlyConfigs = new Set([
13
+ 'npm_config_npm-globalconfig',
14
+ 'npm_config_verify-deps-before-run',
15
+ 'npm_config_catalog',
16
+ 'npm_config__jsr-registry',
17
+ 'npm_config_only-built-dependencies',
18
+ 'npm_globalconfig_only-built-dependencies',
19
+ ]);
20
+ const cleanEnv = {};
21
+ for (const [key, value] of Object.entries(process.env)) {
22
+ if (!pnpmOnlyConfigs.has(key)) {
23
+ cleanEnv[key] = value;
24
+ }
25
+ }
26
+ return { ...cleanEnv, ...extraEnv };
27
+ }
6
28
  function parseArgs(argv) {
7
29
  const parsed = {
8
30
  watch: false,
@@ -235,14 +257,13 @@ function runTests() {
235
257
  cwd,
236
258
  stdio: 'inherit',
237
259
  shell: true,
238
- env: {
239
- ...process.env,
260
+ env: getCleanNpmEnv({
240
261
  NODE_ENV: 'test',
241
262
  // Expose CLI flags to tests via environment variables
242
263
  STENCIL_PROD: args.prod ? 'true' : '',
243
264
  STENCIL_SERVE: args.serve ? 'true' : '',
244
265
  STENCIL_PORT: args.port || '',
245
- },
266
+ }),
246
267
  });
247
268
  vitestProcess.on('exit', (code) => {
248
269
  isRunningTests = false;
@@ -631,6 +652,7 @@ process.on('SIGTERM', () => cleanup());
631
652
  stencilProcess = spawn('npx', stencilArgs, {
632
653
  cwd,
633
654
  shell: true,
655
+ env: getCleanNpmEnv(),
634
656
  });
635
657
  // Pipe stdout and watch for build completion
636
658
  stencilProcess.stdout?.on('data', handleStencilOutput);
@@ -1 +1 @@
1
- {"version":3,"file":"spy-helper.d.ts","sourceRoot":"","sources":["../../src/testing/spy-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEvC;;GAEG;AACH,UAAU,aAAa;IACrB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,aAAa;IAC9C;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,UAAU,gBAAiB,SAAQ,IAAI;IACrC;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACxC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAChC;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAgD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AAM,EAAE,IAAI,CAAC,CAAC;IAC5B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAChC;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAgDD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAEjE;AAqLD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,GAAG,SAAS,CAkBlF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAQ1D"}
@@ -43,8 +43,8 @@ function resolveConfigForTag(config, tagName) {
43
43
  export function setRenderSpyConfig(config) {
44
44
  pendingRenderConfig = config;
45
45
  }
46
- // Store original define before patching
47
- const origDefine = customElements.define.bind(customElements);
46
+ // Store original define before patching (only in browser/jsdom environments)
47
+ const origDefine = typeof customElements !== 'undefined' ? customElements.define.bind(customElements) : undefined;
48
48
  /**
49
49
  * Apply spies to a target instance (shared logic)
50
50
  */
@@ -158,53 +158,55 @@ function applySpies(target, config) {
158
158
  }
159
159
  return spies;
160
160
  }
161
- // Patch customElements.define to intercept component registration
162
- customElements.define = function (name, ctor, options) {
163
- const lc = name.toLowerCase();
164
- const OrigCtor = ctor;
165
- // Wrap ALL components to enable per-render spies without module-level registration
166
- const Wrapped = class extends OrigCtor {
167
- constructor(...args) {
168
- super(...args);
169
- // Check for spy config: per-render takes priority, then module-level
170
- // Capture config now, at constructor time (before async callbacks)
171
- const baseConfig = pendingRenderConfig || spyTargets[lc];
172
- if (!baseConfig)
173
- return; // No spying configured, quick exit
174
- // Resolve config for this specific tag (handles per-component overrides)
175
- const configToUse = resolveConfigForTag(baseConfig, lc);
176
- if (!configToUse)
177
- return; // No config applies to this tag
178
- // After super(), registerHost has run and we have access to hostRef
179
- const hostRef = this.__stencil__getHostRef?.();
180
- if (hostRef && hostRef.$fetchedCbList$) {
181
- // Lazy-load path: Use $fetchedCbList$ to apply spies after constructor but before render
182
- const element = this;
183
- // Capture config in closure for when callback executes
184
- const capturedConfig = configToUse;
185
- hostRef.$fetchedCbList$.push(() => {
186
- const instance = hostRef.$lazyInstance$;
187
- if (instance) {
188
- const spies = applySpies(instance, capturedConfig);
189
- elementSpies.set(element, spies);
190
- }
191
- });
192
- }
193
- else if (hostRef) {
194
- // Custom-elements output with Stencil runtime: element IS the instance
195
- // Apply spies immediately since there's no lazy loading
196
- const spies = applySpies(this, configToUse);
197
- elementSpies.set(this, spies);
198
- }
199
- else {
200
- // Custom-elements output path: element IS the instance
201
- const spies = applySpies(this, configToUse);
202
- elementSpies.set(this, spies);
161
+ // Patch customElements.define to intercept component registration (only in browser/jsdom environments)
162
+ if (typeof customElements !== 'undefined' && origDefine) {
163
+ customElements.define = function (name, ctor, options) {
164
+ const lc = name.toLowerCase();
165
+ const OrigCtor = ctor;
166
+ // Wrap ALL components to enable per-render spies without module-level registration
167
+ const Wrapped = class extends OrigCtor {
168
+ constructor(...args) {
169
+ super(...args);
170
+ // Check for spy config: per-render takes priority, then module-level
171
+ // Capture config now, at constructor time (before async callbacks)
172
+ const baseConfig = pendingRenderConfig || spyTargets[lc];
173
+ if (!baseConfig)
174
+ return; // No spying configured, quick exit
175
+ // Resolve config for this specific tag (handles per-component overrides)
176
+ const configToUse = resolveConfigForTag(baseConfig, lc);
177
+ if (!configToUse)
178
+ return; // No config applies to this tag
179
+ // After super(), registerHost has run and we have access to hostRef
180
+ const hostRef = this.__stencil__getHostRef?.();
181
+ if (hostRef && hostRef.$fetchedCbList$) {
182
+ // Lazy-load path: Use $fetchedCbList$ to apply spies after constructor but before render
183
+ const element = this;
184
+ // Capture config in closure for when callback executes
185
+ const capturedConfig = configToUse;
186
+ hostRef.$fetchedCbList$.push(() => {
187
+ const instance = hostRef.$lazyInstance$;
188
+ if (instance) {
189
+ const spies = applySpies(instance, capturedConfig);
190
+ elementSpies.set(element, spies);
191
+ }
192
+ });
193
+ }
194
+ else if (hostRef) {
195
+ // Custom-elements output with Stencil runtime: element IS the instance
196
+ // Apply spies immediately since there's no lazy loading
197
+ const spies = applySpies(this, configToUse);
198
+ elementSpies.set(this, spies);
199
+ }
200
+ else {
201
+ // Custom-elements output path: element IS the instance
202
+ const spies = applySpies(this, configToUse);
203
+ elementSpies.set(this, spies);
204
+ }
203
205
  }
204
- }
206
+ };
207
+ return origDefine.call(customElements, name, Wrapped, options);
205
208
  };
206
- return origDefine.call(customElements, name, Wrapped, options);
207
- };
209
+ }
208
210
  /**
209
211
  * Get the spies for a rendered component instance.
210
212
  * Spies are lazily applied on first call to ensure the instance is fully constructed.
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.9.0",
7
+ "version": "1.9.2",
8
8
  "description": "First-class testing utilities for Stencil design systems with Vitest",
9
9
  "license": "MIT",
10
10
  "type": "module",
@@ -100,7 +100,7 @@
100
100
  "dependencies": {
101
101
  "jiti": "^2.6.1",
102
102
  "local-pkg": "^1.1.2",
103
- "vitest-environment-stencil": "1.9.0"
103
+ "vitest-environment-stencil": "1.9.2"
104
104
  },
105
105
  "devDependencies": {
106
106
  "@eslint/js": "^9.39.2",