vitest 3.1.0-beta.1 → 3.1.0-beta.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.
- package/dist/browser.js +4 -4
- package/dist/chunks/base.CylSMlTD.js +41 -0
- package/dist/chunks/benchmark.BKUatJGy.js +39 -0
- package/dist/chunks/cac.JtTXbKz0.js +1525 -0
- package/dist/chunks/{cli-api.BwkkJsRe.js → cli-api.BTtPTYMs.js} +4638 -5072
- package/dist/chunks/console.D6t261w0.js +173 -0
- package/dist/chunks/constants.BZZyIeIE.js +43 -0
- package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
- package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
- package/dist/chunks/creator.BEXek7yQ.js +640 -0
- package/dist/chunks/date.CDOsz-HY.js +53 -0
- package/dist/chunks/defaults.DmfNPoe5.js +114 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
- package/dist/chunks/execute.DZKwfrTs.js +791 -0
- package/dist/chunks/git.DXfdBEfR.js +74 -0
- package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
- package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
- package/dist/chunks/index.DFXFpH3w.js +607 -0
- package/dist/chunks/index.VfYQ6MXY.js +104 -0
- package/dist/chunks/index.ZIOEXBQB.js +2382 -0
- package/dist/chunks/inspector.DbDkSkFn.js +54 -0
- package/dist/chunks/node.IqGoMrm4.js +15 -0
- package/dist/chunks/{reporters.d.r7poTZjA.d.ts → reporters.d.5g6jXhoW.d.ts} +14 -3
- package/dist/chunks/rpc.DGgL5dw7.js +92 -0
- package/dist/chunks/run-once.I7PpBOk1.js +47 -0
- package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
- package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
- package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
- package/dist/chunks/utils.BfxieIyZ.js +66 -0
- package/dist/chunks/utils.CtocqOoE.js +72 -0
- package/dist/chunks/utils.OLmtDstN.js +194 -0
- package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
- package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
- package/dist/chunks/vm.BW5voG-u.js +789 -0
- package/dist/cli.js +2 -2
- package/dist/config.cjs +97 -103
- package/dist/config.d.ts +3 -3
- package/dist/config.js +6 -6
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +6 -6
- package/dist/environments.js +1 -1
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/node.d.ts +3 -3
- package/dist/node.js +36 -45
- package/dist/path.js +1 -4
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +4 -4
- package/dist/runners.js +231 -267
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +98 -114
- package/dist/workers/forks.js +22 -22
- package/dist/workers/runVmTests.js +61 -66
- package/dist/workers/threads.js +13 -13
- package/dist/workers/vmForks.js +24 -24
- package/dist/workers/vmThreads.js +15 -15
- package/dist/workers.js +10 -10
- package/package.json +11 -11
- package/dist/chunks/base.DV59CbtV.js +0 -45
- package/dist/chunks/benchmark.DL72EVN-.js +0 -40
- package/dist/chunks/cac.BjmXy7OV.js +0 -1664
- package/dist/chunks/console.CN7AiMGV.js +0 -179
- package/dist/chunks/constants.DTYd6dNH.js +0 -46
- package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
- package/dist/chunks/creator.BsBnpTzI.js +0 -670
- package/dist/chunks/date.W2xKR2qe.js +0 -53
- package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
- package/dist/chunks/execute.eDH0aFFd.js +0 -839
- package/dist/chunks/git.B5SDxu-n.js +0 -69
- package/dist/chunks/index.DOyx6FYJ.js +0 -2551
- package/dist/chunks/index.K90BXFOx.js +0 -658
- package/dist/chunks/index.uXkkC4xl.js +0 -111
- package/dist/chunks/inspector.DKLceBVD.js +0 -54
- package/dist/chunks/node.AKq966Jp.js +0 -15
- package/dist/chunks/rpc.TVf73xOu.js +0 -102
- package/dist/chunks/run-once.2ogXb3JV.js +0 -28
- package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
- package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
- package/dist/chunks/utils.C8RiOc4B.js +0 -77
- package/dist/chunks/utils.Cn0zI1t3.js +0 -68
- package/dist/chunks/utils.bLM2atbD.js +0 -198
- package/dist/chunks/vite.d.Fvq-NZoa.d.ts +0 -11
- package/dist/chunks/vm.jEFQDlX_.js +0 -852
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import { Console } from 'node:console';
|
|
2
|
+
|
|
3
|
+
const LIVING_KEYS = [
|
|
4
|
+
"DOMException",
|
|
5
|
+
"URL",
|
|
6
|
+
"URLSearchParams",
|
|
7
|
+
"EventTarget",
|
|
8
|
+
"NamedNodeMap",
|
|
9
|
+
"Node",
|
|
10
|
+
"Attr",
|
|
11
|
+
"Element",
|
|
12
|
+
"DocumentFragment",
|
|
13
|
+
"DOMImplementation",
|
|
14
|
+
"Document",
|
|
15
|
+
"XMLDocument",
|
|
16
|
+
"CharacterData",
|
|
17
|
+
"Text",
|
|
18
|
+
"CDATASection",
|
|
19
|
+
"ProcessingInstruction",
|
|
20
|
+
"Comment",
|
|
21
|
+
"DocumentType",
|
|
22
|
+
"NodeList",
|
|
23
|
+
"RadioNodeList",
|
|
24
|
+
"HTMLCollection",
|
|
25
|
+
"HTMLOptionsCollection",
|
|
26
|
+
"DOMStringMap",
|
|
27
|
+
"DOMTokenList",
|
|
28
|
+
"StyleSheetList",
|
|
29
|
+
"HTMLElement",
|
|
30
|
+
"HTMLHeadElement",
|
|
31
|
+
"HTMLTitleElement",
|
|
32
|
+
"HTMLBaseElement",
|
|
33
|
+
"HTMLLinkElement",
|
|
34
|
+
"HTMLMetaElement",
|
|
35
|
+
"HTMLStyleElement",
|
|
36
|
+
"HTMLBodyElement",
|
|
37
|
+
"HTMLHeadingElement",
|
|
38
|
+
"HTMLParagraphElement",
|
|
39
|
+
"HTMLHRElement",
|
|
40
|
+
"HTMLPreElement",
|
|
41
|
+
"HTMLUListElement",
|
|
42
|
+
"HTMLOListElement",
|
|
43
|
+
"HTMLLIElement",
|
|
44
|
+
"HTMLMenuElement",
|
|
45
|
+
"HTMLDListElement",
|
|
46
|
+
"HTMLDivElement",
|
|
47
|
+
"HTMLAnchorElement",
|
|
48
|
+
"HTMLAreaElement",
|
|
49
|
+
"HTMLBRElement",
|
|
50
|
+
"HTMLButtonElement",
|
|
51
|
+
"HTMLCanvasElement",
|
|
52
|
+
"HTMLDataElement",
|
|
53
|
+
"HTMLDataListElement",
|
|
54
|
+
"HTMLDetailsElement",
|
|
55
|
+
"HTMLDialogElement",
|
|
56
|
+
"HTMLDirectoryElement",
|
|
57
|
+
"HTMLFieldSetElement",
|
|
58
|
+
"HTMLFontElement",
|
|
59
|
+
"HTMLFormElement",
|
|
60
|
+
"HTMLHtmlElement",
|
|
61
|
+
"HTMLImageElement",
|
|
62
|
+
"HTMLInputElement",
|
|
63
|
+
"HTMLLabelElement",
|
|
64
|
+
"HTMLLegendElement",
|
|
65
|
+
"HTMLMapElement",
|
|
66
|
+
"HTMLMarqueeElement",
|
|
67
|
+
"HTMLMediaElement",
|
|
68
|
+
"HTMLMeterElement",
|
|
69
|
+
"HTMLModElement",
|
|
70
|
+
"HTMLOptGroupElement",
|
|
71
|
+
"HTMLOptionElement",
|
|
72
|
+
"HTMLOutputElement",
|
|
73
|
+
"HTMLPictureElement",
|
|
74
|
+
"HTMLProgressElement",
|
|
75
|
+
"HTMLQuoteElement",
|
|
76
|
+
"HTMLScriptElement",
|
|
77
|
+
"HTMLSelectElement",
|
|
78
|
+
"HTMLSlotElement",
|
|
79
|
+
"HTMLSourceElement",
|
|
80
|
+
"HTMLSpanElement",
|
|
81
|
+
"HTMLTableCaptionElement",
|
|
82
|
+
"HTMLTableCellElement",
|
|
83
|
+
"HTMLTableColElement",
|
|
84
|
+
"HTMLTableElement",
|
|
85
|
+
"HTMLTimeElement",
|
|
86
|
+
"HTMLTableRowElement",
|
|
87
|
+
"HTMLTableSectionElement",
|
|
88
|
+
"HTMLTemplateElement",
|
|
89
|
+
"HTMLTextAreaElement",
|
|
90
|
+
"HTMLUnknownElement",
|
|
91
|
+
"HTMLFrameElement",
|
|
92
|
+
"HTMLFrameSetElement",
|
|
93
|
+
"HTMLIFrameElement",
|
|
94
|
+
"HTMLEmbedElement",
|
|
95
|
+
"HTMLObjectElement",
|
|
96
|
+
"HTMLParamElement",
|
|
97
|
+
"HTMLVideoElement",
|
|
98
|
+
"HTMLAudioElement",
|
|
99
|
+
"HTMLTrackElement",
|
|
100
|
+
"HTMLFormControlsCollection",
|
|
101
|
+
"SVGElement",
|
|
102
|
+
"SVGGraphicsElement",
|
|
103
|
+
"SVGSVGElement",
|
|
104
|
+
"SVGTitleElement",
|
|
105
|
+
"SVGAnimatedString",
|
|
106
|
+
"SVGNumber",
|
|
107
|
+
"SVGStringList",
|
|
108
|
+
"Event",
|
|
109
|
+
"CloseEvent",
|
|
110
|
+
"CustomEvent",
|
|
111
|
+
"MessageEvent",
|
|
112
|
+
"ErrorEvent",
|
|
113
|
+
"HashChangeEvent",
|
|
114
|
+
"PopStateEvent",
|
|
115
|
+
"StorageEvent",
|
|
116
|
+
"ProgressEvent",
|
|
117
|
+
"PageTransitionEvent",
|
|
118
|
+
"SubmitEvent",
|
|
119
|
+
"UIEvent",
|
|
120
|
+
"FocusEvent",
|
|
121
|
+
"InputEvent",
|
|
122
|
+
"MouseEvent",
|
|
123
|
+
"KeyboardEvent",
|
|
124
|
+
"TouchEvent",
|
|
125
|
+
"CompositionEvent",
|
|
126
|
+
"WheelEvent",
|
|
127
|
+
"BarProp",
|
|
128
|
+
"External",
|
|
129
|
+
"Location",
|
|
130
|
+
"History",
|
|
131
|
+
"Screen",
|
|
132
|
+
"Crypto",
|
|
133
|
+
"Performance",
|
|
134
|
+
"Navigator",
|
|
135
|
+
"PluginArray",
|
|
136
|
+
"MimeTypeArray",
|
|
137
|
+
"Plugin",
|
|
138
|
+
"MimeType",
|
|
139
|
+
"FileReader",
|
|
140
|
+
"Blob",
|
|
141
|
+
"File",
|
|
142
|
+
"FileList",
|
|
143
|
+
"ValidityState",
|
|
144
|
+
"DOMParser",
|
|
145
|
+
"XMLSerializer",
|
|
146
|
+
"FormData",
|
|
147
|
+
"XMLHttpRequestEventTarget",
|
|
148
|
+
"XMLHttpRequestUpload",
|
|
149
|
+
"XMLHttpRequest",
|
|
150
|
+
"WebSocket",
|
|
151
|
+
"NodeFilter",
|
|
152
|
+
"NodeIterator",
|
|
153
|
+
"TreeWalker",
|
|
154
|
+
"AbstractRange",
|
|
155
|
+
"Range",
|
|
156
|
+
"StaticRange",
|
|
157
|
+
"Selection",
|
|
158
|
+
"Storage",
|
|
159
|
+
"CustomElementRegistry",
|
|
160
|
+
"ShadowRoot",
|
|
161
|
+
"MutationObserver",
|
|
162
|
+
"MutationRecord",
|
|
163
|
+
"Headers",
|
|
164
|
+
"AbortController",
|
|
165
|
+
"AbortSignal",
|
|
166
|
+
"Uint8Array",
|
|
167
|
+
"Uint16Array",
|
|
168
|
+
"Uint32Array",
|
|
169
|
+
"Uint8ClampedArray",
|
|
170
|
+
"Int8Array",
|
|
171
|
+
"Int16Array",
|
|
172
|
+
"Int32Array",
|
|
173
|
+
"Float32Array",
|
|
174
|
+
"Float64Array",
|
|
175
|
+
"ArrayBuffer",
|
|
176
|
+
"DOMRectReadOnly",
|
|
177
|
+
"DOMRect",
|
|
178
|
+
"Image",
|
|
179
|
+
"Audio",
|
|
180
|
+
"Option",
|
|
181
|
+
"CSS"
|
|
182
|
+
];
|
|
183
|
+
const OTHER_KEYS = [
|
|
184
|
+
"addEventListener",
|
|
185
|
+
"alert",
|
|
186
|
+
"blur",
|
|
187
|
+
"cancelAnimationFrame",
|
|
188
|
+
"close",
|
|
189
|
+
"confirm",
|
|
190
|
+
"createPopup",
|
|
191
|
+
"dispatchEvent",
|
|
192
|
+
"document",
|
|
193
|
+
"focus",
|
|
194
|
+
"frames",
|
|
195
|
+
"getComputedStyle",
|
|
196
|
+
"history",
|
|
197
|
+
"innerHeight",
|
|
198
|
+
"innerWidth",
|
|
199
|
+
"length",
|
|
200
|
+
"location",
|
|
201
|
+
"matchMedia",
|
|
202
|
+
"moveBy",
|
|
203
|
+
"moveTo",
|
|
204
|
+
"name",
|
|
205
|
+
"navigator",
|
|
206
|
+
"open",
|
|
207
|
+
"outerHeight",
|
|
208
|
+
"outerWidth",
|
|
209
|
+
"pageXOffset",
|
|
210
|
+
"pageYOffset",
|
|
211
|
+
"parent",
|
|
212
|
+
"postMessage",
|
|
213
|
+
"print",
|
|
214
|
+
"prompt",
|
|
215
|
+
"removeEventListener",
|
|
216
|
+
"requestAnimationFrame",
|
|
217
|
+
"resizeBy",
|
|
218
|
+
"resizeTo",
|
|
219
|
+
"screen",
|
|
220
|
+
"screenLeft",
|
|
221
|
+
"screenTop",
|
|
222
|
+
"screenX",
|
|
223
|
+
"screenY",
|
|
224
|
+
"scroll",
|
|
225
|
+
"scrollBy",
|
|
226
|
+
"scrollLeft",
|
|
227
|
+
"scrollTo",
|
|
228
|
+
"scrollTop",
|
|
229
|
+
"scrollX",
|
|
230
|
+
"scrollY",
|
|
231
|
+
"self",
|
|
232
|
+
"stop",
|
|
233
|
+
"top",
|
|
234
|
+
"Window",
|
|
235
|
+
"window"
|
|
236
|
+
];
|
|
237
|
+
const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
|
|
238
|
+
|
|
239
|
+
const skipKeys = [
|
|
240
|
+
"window",
|
|
241
|
+
"self",
|
|
242
|
+
"top",
|
|
243
|
+
"parent"
|
|
244
|
+
];
|
|
245
|
+
function getWindowKeys(global, win, additionalKeys = []) {
|
|
246
|
+
const keysArray = [...additionalKeys, ...KEYS];
|
|
247
|
+
const keys = new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
|
|
248
|
+
if (skipKeys.includes(k)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
if (k in global) {
|
|
252
|
+
return keysArray.includes(k);
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}));
|
|
256
|
+
return keys;
|
|
257
|
+
}
|
|
258
|
+
function isClassLikeName(name) {
|
|
259
|
+
return name[0] === name[0].toUpperCase();
|
|
260
|
+
}
|
|
261
|
+
function populateGlobal(global, win, options = {}) {
|
|
262
|
+
const { bindFunctions = false } = options;
|
|
263
|
+
const keys = getWindowKeys(global, win, options.additionalKeys);
|
|
264
|
+
const originals = new Map();
|
|
265
|
+
const overrideObject = new Map();
|
|
266
|
+
for (const key of keys) {
|
|
267
|
+
const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
|
|
268
|
+
if (KEYS.includes(key) && key in global) {
|
|
269
|
+
originals.set(key, global[key]);
|
|
270
|
+
}
|
|
271
|
+
Object.defineProperty(global, key, {
|
|
272
|
+
get() {
|
|
273
|
+
if (overrideObject.has(key)) {
|
|
274
|
+
return overrideObject.get(key);
|
|
275
|
+
}
|
|
276
|
+
if (boundFunction) {
|
|
277
|
+
return boundFunction;
|
|
278
|
+
}
|
|
279
|
+
return win[key];
|
|
280
|
+
},
|
|
281
|
+
set(v) {
|
|
282
|
+
overrideObject.set(key, v);
|
|
283
|
+
},
|
|
284
|
+
configurable: true
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
global.window = global;
|
|
288
|
+
global.self = global;
|
|
289
|
+
global.top = global;
|
|
290
|
+
global.parent = global;
|
|
291
|
+
if (global.global) {
|
|
292
|
+
global.global = global;
|
|
293
|
+
}
|
|
294
|
+
if (global.document && global.document.defaultView) {
|
|
295
|
+
Object.defineProperty(global.document, "defaultView", {
|
|
296
|
+
get: () => global,
|
|
297
|
+
enumerable: true,
|
|
298
|
+
configurable: true
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
skipKeys.forEach((k) => keys.add(k));
|
|
302
|
+
return {
|
|
303
|
+
keys,
|
|
304
|
+
skipKeys,
|
|
305
|
+
originals
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
var edge = {
|
|
310
|
+
name: "edge-runtime",
|
|
311
|
+
transformMode: "ssr",
|
|
312
|
+
async setupVM() {
|
|
313
|
+
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
314
|
+
const vm = new EdgeVM({ extend: (context) => {
|
|
315
|
+
context.global = context;
|
|
316
|
+
context.Buffer = Buffer;
|
|
317
|
+
return context;
|
|
318
|
+
} });
|
|
319
|
+
return {
|
|
320
|
+
getVmContext() {
|
|
321
|
+
return vm.context;
|
|
322
|
+
},
|
|
323
|
+
teardown() {}
|
|
324
|
+
};
|
|
325
|
+
},
|
|
326
|
+
async setup(global) {
|
|
327
|
+
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
328
|
+
const vm = new EdgeVM({ extend: (context) => {
|
|
329
|
+
context.global = context;
|
|
330
|
+
context.Buffer = Buffer;
|
|
331
|
+
KEYS.forEach((key) => {
|
|
332
|
+
if (key in global) {
|
|
333
|
+
context[key] = global[key];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
return context;
|
|
337
|
+
} });
|
|
338
|
+
const { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
|
|
339
|
+
return { teardown(global) {
|
|
340
|
+
keys.forEach((key) => delete global[key]);
|
|
341
|
+
originals.forEach((v, k) => global[k] = v);
|
|
342
|
+
} };
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
async function teardownWindow(win) {
|
|
347
|
+
if (win.close && win.happyDOM.abort) {
|
|
348
|
+
await win.happyDOM.abort();
|
|
349
|
+
win.close();
|
|
350
|
+
} else {
|
|
351
|
+
win.happyDOM.cancelAsync();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
var happy = {
|
|
355
|
+
name: "happy-dom",
|
|
356
|
+
transformMode: "web",
|
|
357
|
+
async setupVM({ happyDOM = {} }) {
|
|
358
|
+
const { Window } = await import('happy-dom');
|
|
359
|
+
let win = new Window({
|
|
360
|
+
...happyDOM,
|
|
361
|
+
console: console && globalThis.console ? globalThis.console : undefined,
|
|
362
|
+
url: happyDOM.url || "http://localhost:3000",
|
|
363
|
+
settings: {
|
|
364
|
+
...happyDOM.settings,
|
|
365
|
+
disableErrorCapturing: true
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
win.Buffer = Buffer;
|
|
369
|
+
if (typeof structuredClone !== "undefined" && !win.structuredClone) {
|
|
370
|
+
win.structuredClone = structuredClone;
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
getVmContext() {
|
|
374
|
+
return win;
|
|
375
|
+
},
|
|
376
|
+
async teardown() {
|
|
377
|
+
await teardownWindow(win);
|
|
378
|
+
win = undefined;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
},
|
|
382
|
+
async setup(global, { happyDOM = {} }) {
|
|
383
|
+
const { Window, GlobalWindow } = await import('happy-dom');
|
|
384
|
+
const win = new (GlobalWindow || Window)({
|
|
385
|
+
...happyDOM,
|
|
386
|
+
console: console && global.console ? global.console : undefined,
|
|
387
|
+
url: happyDOM.url || "http://localhost:3000",
|
|
388
|
+
settings: {
|
|
389
|
+
...happyDOM.settings,
|
|
390
|
+
disableErrorCapturing: true
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
const { keys, originals } = populateGlobal(global, win, {
|
|
394
|
+
bindFunctions: true,
|
|
395
|
+
additionalKeys: [
|
|
396
|
+
"Request",
|
|
397
|
+
"Response",
|
|
398
|
+
"MessagePort",
|
|
399
|
+
"fetch"
|
|
400
|
+
]
|
|
401
|
+
});
|
|
402
|
+
return { async teardown(global) {
|
|
403
|
+
await teardownWindow(win);
|
|
404
|
+
keys.forEach((key) => delete global[key]);
|
|
405
|
+
originals.forEach((v, k) => global[k] = v);
|
|
406
|
+
} };
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
function catchWindowErrors(window) {
|
|
411
|
+
let userErrorListenerCount = 0;
|
|
412
|
+
function throwUnhandlerError(e) {
|
|
413
|
+
if (userErrorListenerCount === 0 && e.error != null) {
|
|
414
|
+
process.emit("uncaughtException", e.error);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const addEventListener = window.addEventListener.bind(window);
|
|
418
|
+
const removeEventListener = window.removeEventListener.bind(window);
|
|
419
|
+
window.addEventListener("error", throwUnhandlerError);
|
|
420
|
+
window.addEventListener = function(...args) {
|
|
421
|
+
if (args[0] === "error") {
|
|
422
|
+
userErrorListenerCount++;
|
|
423
|
+
}
|
|
424
|
+
return addEventListener.apply(this, args);
|
|
425
|
+
};
|
|
426
|
+
window.removeEventListener = function(...args) {
|
|
427
|
+
if (args[0] === "error" && userErrorListenerCount) {
|
|
428
|
+
userErrorListenerCount--;
|
|
429
|
+
}
|
|
430
|
+
return removeEventListener.apply(this, args);
|
|
431
|
+
};
|
|
432
|
+
return function clearErrorHandlers() {
|
|
433
|
+
window.removeEventListener("error", throwUnhandlerError);
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
var jsdom = {
|
|
437
|
+
name: "jsdom",
|
|
438
|
+
transformMode: "web",
|
|
439
|
+
async setupVM({ jsdom = {} }) {
|
|
440
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
|
|
441
|
+
const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
|
|
442
|
+
let dom = new JSDOM(html, {
|
|
443
|
+
pretendToBeVisual,
|
|
444
|
+
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : undefined),
|
|
445
|
+
runScripts,
|
|
446
|
+
url,
|
|
447
|
+
virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : undefined,
|
|
448
|
+
cookieJar: cookieJar ? new CookieJar() : undefined,
|
|
449
|
+
includeNodeLocations,
|
|
450
|
+
contentType,
|
|
451
|
+
userAgent,
|
|
452
|
+
...restOptions
|
|
453
|
+
});
|
|
454
|
+
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
455
|
+
dom.window.Buffer = Buffer;
|
|
456
|
+
dom.window.jsdom = dom;
|
|
457
|
+
const globalNames = [
|
|
458
|
+
"structuredClone",
|
|
459
|
+
"fetch",
|
|
460
|
+
"Request",
|
|
461
|
+
"Response",
|
|
462
|
+
"BroadcastChannel",
|
|
463
|
+
"MessageChannel",
|
|
464
|
+
"MessagePort",
|
|
465
|
+
"TextEncoder",
|
|
466
|
+
"TextDecoder"
|
|
467
|
+
];
|
|
468
|
+
for (const name of globalNames) {
|
|
469
|
+
const value = globalThis[name];
|
|
470
|
+
if (typeof value !== "undefined" && typeof dom.window[name] === "undefined") {
|
|
471
|
+
dom.window[name] = value;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return {
|
|
475
|
+
getVmContext() {
|
|
476
|
+
return dom.getInternalVMContext();
|
|
477
|
+
},
|
|
478
|
+
teardown() {
|
|
479
|
+
clearWindowErrors();
|
|
480
|
+
dom.window.close();
|
|
481
|
+
dom = undefined;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
},
|
|
485
|
+
async setup(global, { jsdom = {} }) {
|
|
486
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
|
|
487
|
+
const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
|
|
488
|
+
const dom = new JSDOM(html, {
|
|
489
|
+
pretendToBeVisual,
|
|
490
|
+
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : undefined),
|
|
491
|
+
runScripts,
|
|
492
|
+
url,
|
|
493
|
+
virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : undefined,
|
|
494
|
+
cookieJar: cookieJar ? new CookieJar() : undefined,
|
|
495
|
+
includeNodeLocations,
|
|
496
|
+
contentType,
|
|
497
|
+
userAgent,
|
|
498
|
+
...restOptions
|
|
499
|
+
});
|
|
500
|
+
const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
|
|
501
|
+
const clearWindowErrors = catchWindowErrors(global);
|
|
502
|
+
global.jsdom = dom;
|
|
503
|
+
return { teardown(global) {
|
|
504
|
+
clearWindowErrors();
|
|
505
|
+
dom.window.close();
|
|
506
|
+
delete global.jsdom;
|
|
507
|
+
keys.forEach((key) => delete global[key]);
|
|
508
|
+
originals.forEach((v, k) => global[k] = v);
|
|
509
|
+
} };
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const denyList = new Set([
|
|
514
|
+
"GLOBAL",
|
|
515
|
+
"root",
|
|
516
|
+
"global",
|
|
517
|
+
"Buffer",
|
|
518
|
+
"ArrayBuffer",
|
|
519
|
+
"Uint8Array"
|
|
520
|
+
]);
|
|
521
|
+
const nodeGlobals = new Map(Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
|
|
522
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, nodeGlobalsKey);
|
|
523
|
+
if (!descriptor) {
|
|
524
|
+
throw new Error(`No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`);
|
|
525
|
+
}
|
|
526
|
+
return [nodeGlobalsKey, descriptor];
|
|
527
|
+
}));
|
|
528
|
+
var node = {
|
|
529
|
+
name: "node",
|
|
530
|
+
transformMode: "ssr",
|
|
531
|
+
async setupVM() {
|
|
532
|
+
const vm = await import('node:vm');
|
|
533
|
+
let context = vm.createContext();
|
|
534
|
+
let global = vm.runInContext("this", context);
|
|
535
|
+
const contextGlobals = new Set(Object.getOwnPropertyNames(global));
|
|
536
|
+
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) {
|
|
537
|
+
if (!contextGlobals.has(nodeGlobalsKey)) {
|
|
538
|
+
if (descriptor.configurable) {
|
|
539
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
540
|
+
configurable: true,
|
|
541
|
+
enumerable: descriptor.enumerable,
|
|
542
|
+
get() {
|
|
543
|
+
const val = globalThis[nodeGlobalsKey];
|
|
544
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
545
|
+
configurable: true,
|
|
546
|
+
enumerable: descriptor.enumerable,
|
|
547
|
+
value: val,
|
|
548
|
+
writable: descriptor.writable === true || nodeGlobalsKey === "performance"
|
|
549
|
+
});
|
|
550
|
+
return val;
|
|
551
|
+
},
|
|
552
|
+
set(val) {
|
|
553
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
554
|
+
configurable: true,
|
|
555
|
+
enumerable: descriptor.enumerable,
|
|
556
|
+
value: val,
|
|
557
|
+
writable: true
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
} else if ("value" in descriptor) {
|
|
562
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
563
|
+
configurable: false,
|
|
564
|
+
enumerable: descriptor.enumerable,
|
|
565
|
+
value: descriptor.value,
|
|
566
|
+
writable: descriptor.writable
|
|
567
|
+
});
|
|
568
|
+
} else {
|
|
569
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
570
|
+
configurable: false,
|
|
571
|
+
enumerable: descriptor.enumerable,
|
|
572
|
+
get: descriptor.get,
|
|
573
|
+
set: descriptor.set
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
global.global = global;
|
|
579
|
+
global.Buffer = Buffer;
|
|
580
|
+
global.ArrayBuffer = ArrayBuffer;
|
|
581
|
+
global.Uint8Array = Uint8Array;
|
|
582
|
+
return {
|
|
583
|
+
getVmContext() {
|
|
584
|
+
return context;
|
|
585
|
+
},
|
|
586
|
+
teardown() {
|
|
587
|
+
context = undefined;
|
|
588
|
+
global = undefined;
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
},
|
|
592
|
+
async setup(global) {
|
|
593
|
+
global.console.Console = Console;
|
|
594
|
+
return { teardown(global) {
|
|
595
|
+
delete global.console.Console;
|
|
596
|
+
} };
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
const environments = {
|
|
601
|
+
node,
|
|
602
|
+
jsdom,
|
|
603
|
+
"happy-dom": happy,
|
|
604
|
+
"edge-runtime": edge
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
export { environments as e, populateGlobal as p };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as chai from 'chai';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.DEGDGBiA.js';
|
|
4
|
+
import { distDir } from '../path.js';
|
|
5
|
+
import { r as rpc } from './rpc.DGgL5dw7.js';
|
|
6
|
+
import { g as getWorkerState } from './utils.CtocqOoE.js';
|
|
7
|
+
|
|
8
|
+
function setupChaiConfig(config) {
|
|
9
|
+
Object.assign(chai.config, config);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function resolveSnapshotEnvironment(config, executor) {
|
|
13
|
+
if (!config.snapshotEnvironment) {
|
|
14
|
+
const { VitestNodeSnapshotEnvironment } = await import('./node.IqGoMrm4.js');
|
|
15
|
+
return new VitestNodeSnapshotEnvironment();
|
|
16
|
+
}
|
|
17
|
+
const mod = await executor.executeId(config.snapshotEnvironment);
|
|
18
|
+
if (typeof mod.default !== "object" || !mod.default) {
|
|
19
|
+
throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
|
|
20
|
+
}
|
|
21
|
+
return mod.default;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const runnersFile = resolve(distDir, "runners.js");
|
|
25
|
+
async function getTestRunnerConstructor(config, executor) {
|
|
26
|
+
if (!config.runner) {
|
|
27
|
+
const { VitestTestRunner, NodeBenchmarkRunner } = await executor.executeFile(runnersFile);
|
|
28
|
+
return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
29
|
+
}
|
|
30
|
+
const mod = await executor.executeId(config.runner);
|
|
31
|
+
if (!mod.default && typeof mod.default !== "function") {
|
|
32
|
+
throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
|
|
33
|
+
}
|
|
34
|
+
return mod.default;
|
|
35
|
+
}
|
|
36
|
+
async function resolveTestRunner(config, executor) {
|
|
37
|
+
const TestRunner = await getTestRunnerConstructor(config, executor);
|
|
38
|
+
const testRunner = new TestRunner(config);
|
|
39
|
+
Object.defineProperty(testRunner, "__vitest_executor", {
|
|
40
|
+
value: executor,
|
|
41
|
+
enumerable: false,
|
|
42
|
+
configurable: false
|
|
43
|
+
});
|
|
44
|
+
if (!testRunner.config) {
|
|
45
|
+
testRunner.config = config;
|
|
46
|
+
}
|
|
47
|
+
if (!testRunner.importFile) {
|
|
48
|
+
throw new Error("Runner must implement \"importFile\" method.");
|
|
49
|
+
}
|
|
50
|
+
const [diffOptions] = await Promise.all([loadDiffConfig(config, executor), loadSnapshotSerializers(config, executor)]);
|
|
51
|
+
testRunner.config.diffOptions = diffOptions;
|
|
52
|
+
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
53
|
+
testRunner.onTaskUpdate = async (task, events) => {
|
|
54
|
+
const p = rpc().onTaskUpdate(task, events);
|
|
55
|
+
await originalOnTaskUpdate?.call(testRunner, task, events);
|
|
56
|
+
return p;
|
|
57
|
+
};
|
|
58
|
+
const originalOnCollectStart = testRunner.onCollectStart;
|
|
59
|
+
testRunner.onCollectStart = async (file) => {
|
|
60
|
+
await rpc().onQueued(file);
|
|
61
|
+
await originalOnCollectStart?.call(testRunner, file);
|
|
62
|
+
};
|
|
63
|
+
const originalOnCollected = testRunner.onCollected;
|
|
64
|
+
testRunner.onCollected = async (files) => {
|
|
65
|
+
const state = getWorkerState();
|
|
66
|
+
files.forEach((file) => {
|
|
67
|
+
file.prepareDuration = state.durations.prepare;
|
|
68
|
+
file.environmentLoad = state.durations.environment;
|
|
69
|
+
state.durations.prepare = 0;
|
|
70
|
+
state.durations.environment = 0;
|
|
71
|
+
});
|
|
72
|
+
rpc().onCollected(files);
|
|
73
|
+
await originalOnCollected?.call(testRunner, files);
|
|
74
|
+
};
|
|
75
|
+
const originalOnAfterRun = testRunner.onAfterRunFiles;
|
|
76
|
+
testRunner.onAfterRunFiles = async (files) => {
|
|
77
|
+
const state = getWorkerState();
|
|
78
|
+
const coverage = await takeCoverageInsideWorker(config.coverage, executor);
|
|
79
|
+
if (coverage) {
|
|
80
|
+
rpc().onAfterSuiteRun({
|
|
81
|
+
coverage,
|
|
82
|
+
testFiles: files.map((file) => file.name).sort(),
|
|
83
|
+
transformMode: state.environment.transformMode,
|
|
84
|
+
projectName: state.ctx.projectName
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
await originalOnAfterRun?.call(testRunner, files);
|
|
88
|
+
};
|
|
89
|
+
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
90
|
+
testRunner.onAfterRunTask = async (test) => {
|
|
91
|
+
if (config.bail && test.result?.state === "fail") {
|
|
92
|
+
const previousFailures = await rpc().getCountOfFailedTests();
|
|
93
|
+
const currentFailures = 1 + previousFailures;
|
|
94
|
+
if (currentFailures >= config.bail) {
|
|
95
|
+
rpc().onCancel("test-failure");
|
|
96
|
+
testRunner.onCancel?.("test-failure");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
await originalOnAfterRunTask?.call(testRunner, test);
|
|
100
|
+
};
|
|
101
|
+
return testRunner;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
|