@stencil/vitest 1.9.0 → 1.9.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.
|
@@ -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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AAG,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
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
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.
|
|
7
|
+
"version": "1.9.1",
|
|
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.
|
|
103
|
+
"vitest-environment-stencil": "1.9.1"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@eslint/js": "^9.39.2",
|