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
|
@@ -1,658 +0,0 @@
|
|
|
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
|
-
// not specified in docs, but is available
|
|
179
|
-
"Image",
|
|
180
|
-
"Audio",
|
|
181
|
-
"Option",
|
|
182
|
-
"CSS"
|
|
183
|
-
];
|
|
184
|
-
const OTHER_KEYS = [
|
|
185
|
-
"addEventListener",
|
|
186
|
-
"alert",
|
|
187
|
-
// 'atob',
|
|
188
|
-
"blur",
|
|
189
|
-
// 'btoa',
|
|
190
|
-
"cancelAnimationFrame",
|
|
191
|
-
/* 'clearInterval', */
|
|
192
|
-
/* 'clearTimeout', */
|
|
193
|
-
"close",
|
|
194
|
-
"confirm",
|
|
195
|
-
/* 'console', */
|
|
196
|
-
"createPopup",
|
|
197
|
-
"dispatchEvent",
|
|
198
|
-
"document",
|
|
199
|
-
"focus",
|
|
200
|
-
"frames",
|
|
201
|
-
"getComputedStyle",
|
|
202
|
-
"history",
|
|
203
|
-
"innerHeight",
|
|
204
|
-
"innerWidth",
|
|
205
|
-
"length",
|
|
206
|
-
"location",
|
|
207
|
-
"matchMedia",
|
|
208
|
-
"moveBy",
|
|
209
|
-
"moveTo",
|
|
210
|
-
"name",
|
|
211
|
-
"navigator",
|
|
212
|
-
"open",
|
|
213
|
-
"outerHeight",
|
|
214
|
-
"outerWidth",
|
|
215
|
-
"pageXOffset",
|
|
216
|
-
"pageYOffset",
|
|
217
|
-
"parent",
|
|
218
|
-
"postMessage",
|
|
219
|
-
"print",
|
|
220
|
-
"prompt",
|
|
221
|
-
"removeEventListener",
|
|
222
|
-
"requestAnimationFrame",
|
|
223
|
-
"resizeBy",
|
|
224
|
-
"resizeTo",
|
|
225
|
-
"screen",
|
|
226
|
-
"screenLeft",
|
|
227
|
-
"screenTop",
|
|
228
|
-
"screenX",
|
|
229
|
-
"screenY",
|
|
230
|
-
"scroll",
|
|
231
|
-
"scrollBy",
|
|
232
|
-
"scrollLeft",
|
|
233
|
-
"scrollTo",
|
|
234
|
-
"scrollTop",
|
|
235
|
-
"scrollX",
|
|
236
|
-
"scrollY",
|
|
237
|
-
"self",
|
|
238
|
-
/* 'setInterval', */
|
|
239
|
-
/* 'setTimeout', */
|
|
240
|
-
"stop",
|
|
241
|
-
/* 'toString', */
|
|
242
|
-
"top",
|
|
243
|
-
"Window",
|
|
244
|
-
"window"
|
|
245
|
-
];
|
|
246
|
-
const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
|
|
247
|
-
|
|
248
|
-
const skipKeys = ["window", "self", "top", "parent"];
|
|
249
|
-
function getWindowKeys(global, win, additionalKeys = []) {
|
|
250
|
-
const keysArray = [...additionalKeys, ...KEYS];
|
|
251
|
-
const keys = new Set(
|
|
252
|
-
keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
|
|
253
|
-
if (skipKeys.includes(k)) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
if (k in global) {
|
|
257
|
-
return keysArray.includes(k);
|
|
258
|
-
}
|
|
259
|
-
return true;
|
|
260
|
-
})
|
|
261
|
-
);
|
|
262
|
-
return keys;
|
|
263
|
-
}
|
|
264
|
-
function isClassLikeName(name) {
|
|
265
|
-
return name[0] === name[0].toUpperCase();
|
|
266
|
-
}
|
|
267
|
-
function populateGlobal(global, win, options = {}) {
|
|
268
|
-
const { bindFunctions = false } = options;
|
|
269
|
-
const keys = getWindowKeys(global, win, options.additionalKeys);
|
|
270
|
-
const originals = /* @__PURE__ */ new Map();
|
|
271
|
-
const overrideObject = /* @__PURE__ */ new Map();
|
|
272
|
-
for (const key of keys) {
|
|
273
|
-
const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
|
|
274
|
-
if (KEYS.includes(key) && key in global) {
|
|
275
|
-
originals.set(key, global[key]);
|
|
276
|
-
}
|
|
277
|
-
Object.defineProperty(global, key, {
|
|
278
|
-
get() {
|
|
279
|
-
if (overrideObject.has(key)) {
|
|
280
|
-
return overrideObject.get(key);
|
|
281
|
-
}
|
|
282
|
-
if (boundFunction) {
|
|
283
|
-
return boundFunction;
|
|
284
|
-
}
|
|
285
|
-
return win[key];
|
|
286
|
-
},
|
|
287
|
-
set(v) {
|
|
288
|
-
overrideObject.set(key, v);
|
|
289
|
-
},
|
|
290
|
-
configurable: true
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
global.window = global;
|
|
294
|
-
global.self = global;
|
|
295
|
-
global.top = global;
|
|
296
|
-
global.parent = global;
|
|
297
|
-
if (global.global) {
|
|
298
|
-
global.global = global;
|
|
299
|
-
}
|
|
300
|
-
if (global.document && global.document.defaultView) {
|
|
301
|
-
Object.defineProperty(global.document, "defaultView", {
|
|
302
|
-
get: () => global,
|
|
303
|
-
enumerable: true,
|
|
304
|
-
configurable: true
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
skipKeys.forEach((k) => keys.add(k));
|
|
308
|
-
return {
|
|
309
|
-
keys,
|
|
310
|
-
skipKeys,
|
|
311
|
-
originals
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
var edge = {
|
|
316
|
-
name: "edge-runtime",
|
|
317
|
-
transformMode: "ssr",
|
|
318
|
-
async setupVM() {
|
|
319
|
-
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
320
|
-
const vm = new EdgeVM({
|
|
321
|
-
extend: (context) => {
|
|
322
|
-
context.global = context;
|
|
323
|
-
context.Buffer = Buffer;
|
|
324
|
-
return context;
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
return {
|
|
328
|
-
getVmContext() {
|
|
329
|
-
return vm.context;
|
|
330
|
-
},
|
|
331
|
-
teardown() {
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
},
|
|
335
|
-
async setup(global) {
|
|
336
|
-
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
337
|
-
const vm = new EdgeVM({
|
|
338
|
-
extend: (context) => {
|
|
339
|
-
context.global = context;
|
|
340
|
-
context.Buffer = Buffer;
|
|
341
|
-
KEYS.forEach((key) => {
|
|
342
|
-
if (key in global) {
|
|
343
|
-
context[key] = global[key];
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
return context;
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
const { keys, originals } = populateGlobal(global, vm.context, {
|
|
350
|
-
bindFunctions: true
|
|
351
|
-
});
|
|
352
|
-
return {
|
|
353
|
-
teardown(global2) {
|
|
354
|
-
keys.forEach((key) => delete global2[key]);
|
|
355
|
-
originals.forEach((v, k) => global2[k] = v);
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
async function teardownWindow(win) {
|
|
362
|
-
if (win.close && win.happyDOM.abort) {
|
|
363
|
-
await win.happyDOM.abort();
|
|
364
|
-
win.close();
|
|
365
|
-
} else {
|
|
366
|
-
win.happyDOM.cancelAsync();
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
var happy = {
|
|
370
|
-
name: "happy-dom",
|
|
371
|
-
transformMode: "web",
|
|
372
|
-
async setupVM({ happyDOM = {} }) {
|
|
373
|
-
const { Window } = await import('happy-dom');
|
|
374
|
-
let win = new Window({
|
|
375
|
-
...happyDOM,
|
|
376
|
-
console: console && globalThis.console ? globalThis.console : void 0,
|
|
377
|
-
url: happyDOM.url || "http://localhost:3000",
|
|
378
|
-
settings: {
|
|
379
|
-
...happyDOM.settings,
|
|
380
|
-
disableErrorCapturing: true
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
win.Buffer = Buffer;
|
|
384
|
-
if (typeof structuredClone !== "undefined" && !win.structuredClone) {
|
|
385
|
-
win.structuredClone = structuredClone;
|
|
386
|
-
}
|
|
387
|
-
return {
|
|
388
|
-
getVmContext() {
|
|
389
|
-
return win;
|
|
390
|
-
},
|
|
391
|
-
async teardown() {
|
|
392
|
-
await teardownWindow(win);
|
|
393
|
-
win = void 0;
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
},
|
|
397
|
-
async setup(global, { happyDOM = {} }) {
|
|
398
|
-
const { Window, GlobalWindow } = await import('happy-dom');
|
|
399
|
-
const win = new (GlobalWindow || Window)({
|
|
400
|
-
...happyDOM,
|
|
401
|
-
console: console && global.console ? global.console : void 0,
|
|
402
|
-
url: happyDOM.url || "http://localhost:3000",
|
|
403
|
-
settings: {
|
|
404
|
-
...happyDOM.settings,
|
|
405
|
-
disableErrorCapturing: true
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
const { keys, originals } = populateGlobal(global, win, {
|
|
409
|
-
bindFunctions: true,
|
|
410
|
-
// jsdom doesn't support Request and Response, but happy-dom does
|
|
411
|
-
additionalKeys: ["Request", "Response", "MessagePort", "fetch"]
|
|
412
|
-
});
|
|
413
|
-
return {
|
|
414
|
-
async teardown(global2) {
|
|
415
|
-
await teardownWindow(win);
|
|
416
|
-
keys.forEach((key) => delete global2[key]);
|
|
417
|
-
originals.forEach((v, k) => global2[k] = v);
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
function catchWindowErrors(window) {
|
|
424
|
-
let userErrorListenerCount = 0;
|
|
425
|
-
function throwUnhandlerError(e) {
|
|
426
|
-
if (userErrorListenerCount === 0 && e.error != null) {
|
|
427
|
-
process.emit("uncaughtException", e.error);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
const addEventListener = window.addEventListener.bind(window);
|
|
431
|
-
const removeEventListener = window.removeEventListener.bind(window);
|
|
432
|
-
window.addEventListener("error", throwUnhandlerError);
|
|
433
|
-
window.addEventListener = function(...args) {
|
|
434
|
-
if (args[0] === "error") {
|
|
435
|
-
userErrorListenerCount++;
|
|
436
|
-
}
|
|
437
|
-
return addEventListener.apply(this, args);
|
|
438
|
-
};
|
|
439
|
-
window.removeEventListener = function(...args) {
|
|
440
|
-
if (args[0] === "error" && userErrorListenerCount) {
|
|
441
|
-
userErrorListenerCount--;
|
|
442
|
-
}
|
|
443
|
-
return removeEventListener.apply(this, args);
|
|
444
|
-
};
|
|
445
|
-
return function clearErrorHandlers() {
|
|
446
|
-
window.removeEventListener("error", throwUnhandlerError);
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
var jsdom = {
|
|
450
|
-
name: "jsdom",
|
|
451
|
-
transformMode: "web",
|
|
452
|
-
async setupVM({ jsdom = {} }) {
|
|
453
|
-
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
|
|
454
|
-
const {
|
|
455
|
-
html = "<!DOCTYPE html>",
|
|
456
|
-
userAgent,
|
|
457
|
-
url = "http://localhost:3000",
|
|
458
|
-
contentType = "text/html",
|
|
459
|
-
pretendToBeVisual = true,
|
|
460
|
-
includeNodeLocations = false,
|
|
461
|
-
runScripts = "dangerously",
|
|
462
|
-
resources,
|
|
463
|
-
console = false,
|
|
464
|
-
cookieJar = false,
|
|
465
|
-
...restOptions
|
|
466
|
-
} = jsdom;
|
|
467
|
-
let dom = new JSDOM(html, {
|
|
468
|
-
pretendToBeVisual,
|
|
469
|
-
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
|
|
470
|
-
runScripts,
|
|
471
|
-
url,
|
|
472
|
-
virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : void 0,
|
|
473
|
-
cookieJar: cookieJar ? new CookieJar() : void 0,
|
|
474
|
-
includeNodeLocations,
|
|
475
|
-
contentType,
|
|
476
|
-
userAgent,
|
|
477
|
-
...restOptions
|
|
478
|
-
});
|
|
479
|
-
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
480
|
-
dom.window.Buffer = Buffer;
|
|
481
|
-
dom.window.jsdom = dom;
|
|
482
|
-
const globalNames = [
|
|
483
|
-
"structuredClone",
|
|
484
|
-
"fetch",
|
|
485
|
-
"Request",
|
|
486
|
-
"Response",
|
|
487
|
-
"BroadcastChannel",
|
|
488
|
-
"MessageChannel",
|
|
489
|
-
"MessagePort",
|
|
490
|
-
"TextEncoder",
|
|
491
|
-
"TextDecoder"
|
|
492
|
-
];
|
|
493
|
-
for (const name of globalNames) {
|
|
494
|
-
const value = globalThis[name];
|
|
495
|
-
if (typeof value !== "undefined" && typeof dom.window[name] === "undefined") {
|
|
496
|
-
dom.window[name] = value;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
return {
|
|
500
|
-
getVmContext() {
|
|
501
|
-
return dom.getInternalVMContext();
|
|
502
|
-
},
|
|
503
|
-
teardown() {
|
|
504
|
-
clearWindowErrors();
|
|
505
|
-
dom.window.close();
|
|
506
|
-
dom = void 0;
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
},
|
|
510
|
-
async setup(global, { jsdom = {} }) {
|
|
511
|
-
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
|
|
512
|
-
const {
|
|
513
|
-
html = "<!DOCTYPE html>",
|
|
514
|
-
userAgent,
|
|
515
|
-
url = "http://localhost:3000",
|
|
516
|
-
contentType = "text/html",
|
|
517
|
-
pretendToBeVisual = true,
|
|
518
|
-
includeNodeLocations = false,
|
|
519
|
-
runScripts = "dangerously",
|
|
520
|
-
resources,
|
|
521
|
-
console = false,
|
|
522
|
-
cookieJar = false,
|
|
523
|
-
...restOptions
|
|
524
|
-
} = jsdom;
|
|
525
|
-
const dom = new JSDOM(html, {
|
|
526
|
-
pretendToBeVisual,
|
|
527
|
-
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
|
|
528
|
-
runScripts,
|
|
529
|
-
url,
|
|
530
|
-
virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
|
|
531
|
-
cookieJar: cookieJar ? new CookieJar() : void 0,
|
|
532
|
-
includeNodeLocations,
|
|
533
|
-
contentType,
|
|
534
|
-
userAgent,
|
|
535
|
-
...restOptions
|
|
536
|
-
});
|
|
537
|
-
const { keys, originals } = populateGlobal(global, dom.window, {
|
|
538
|
-
bindFunctions: true
|
|
539
|
-
});
|
|
540
|
-
const clearWindowErrors = catchWindowErrors(global);
|
|
541
|
-
global.jsdom = dom;
|
|
542
|
-
return {
|
|
543
|
-
teardown(global2) {
|
|
544
|
-
clearWindowErrors();
|
|
545
|
-
dom.window.close();
|
|
546
|
-
delete global2.jsdom;
|
|
547
|
-
keys.forEach((key) => delete global2[key]);
|
|
548
|
-
originals.forEach((v, k) => global2[k] = v);
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
const denyList = /* @__PURE__ */ new Set([
|
|
555
|
-
"GLOBAL",
|
|
556
|
-
"root",
|
|
557
|
-
"global",
|
|
558
|
-
"Buffer",
|
|
559
|
-
"ArrayBuffer",
|
|
560
|
-
"Uint8Array"
|
|
561
|
-
]);
|
|
562
|
-
const nodeGlobals = new Map(
|
|
563
|
-
Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
|
|
564
|
-
const descriptor = Object.getOwnPropertyDescriptor(
|
|
565
|
-
globalThis,
|
|
566
|
-
nodeGlobalsKey
|
|
567
|
-
);
|
|
568
|
-
if (!descriptor) {
|
|
569
|
-
throw new Error(
|
|
570
|
-
`No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
return [nodeGlobalsKey, descriptor];
|
|
574
|
-
})
|
|
575
|
-
);
|
|
576
|
-
var node = {
|
|
577
|
-
name: "node",
|
|
578
|
-
transformMode: "ssr",
|
|
579
|
-
// this is largely copied from jest's node environment
|
|
580
|
-
async setupVM() {
|
|
581
|
-
const vm = await import('node:vm');
|
|
582
|
-
let context = vm.createContext();
|
|
583
|
-
let global = vm.runInContext("this", context);
|
|
584
|
-
const contextGlobals = new Set(Object.getOwnPropertyNames(global));
|
|
585
|
-
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) {
|
|
586
|
-
if (!contextGlobals.has(nodeGlobalsKey)) {
|
|
587
|
-
if (descriptor.configurable) {
|
|
588
|
-
Object.defineProperty(global, nodeGlobalsKey, {
|
|
589
|
-
configurable: true,
|
|
590
|
-
enumerable: descriptor.enumerable,
|
|
591
|
-
get() {
|
|
592
|
-
const val = globalThis[nodeGlobalsKey];
|
|
593
|
-
Object.defineProperty(global, nodeGlobalsKey, {
|
|
594
|
-
configurable: true,
|
|
595
|
-
enumerable: descriptor.enumerable,
|
|
596
|
-
value: val,
|
|
597
|
-
writable: descriptor.writable === true || nodeGlobalsKey === "performance"
|
|
598
|
-
});
|
|
599
|
-
return val;
|
|
600
|
-
},
|
|
601
|
-
set(val) {
|
|
602
|
-
Object.defineProperty(global, nodeGlobalsKey, {
|
|
603
|
-
configurable: true,
|
|
604
|
-
enumerable: descriptor.enumerable,
|
|
605
|
-
value: val,
|
|
606
|
-
writable: true
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
|
-
} else if ("value" in descriptor) {
|
|
611
|
-
Object.defineProperty(global, nodeGlobalsKey, {
|
|
612
|
-
configurable: false,
|
|
613
|
-
enumerable: descriptor.enumerable,
|
|
614
|
-
value: descriptor.value,
|
|
615
|
-
writable: descriptor.writable
|
|
616
|
-
});
|
|
617
|
-
} else {
|
|
618
|
-
Object.defineProperty(global, nodeGlobalsKey, {
|
|
619
|
-
configurable: false,
|
|
620
|
-
enumerable: descriptor.enumerable,
|
|
621
|
-
get: descriptor.get,
|
|
622
|
-
set: descriptor.set
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
global.global = global;
|
|
628
|
-
global.Buffer = Buffer;
|
|
629
|
-
global.ArrayBuffer = ArrayBuffer;
|
|
630
|
-
global.Uint8Array = Uint8Array;
|
|
631
|
-
return {
|
|
632
|
-
getVmContext() {
|
|
633
|
-
return context;
|
|
634
|
-
},
|
|
635
|
-
teardown() {
|
|
636
|
-
context = void 0;
|
|
637
|
-
global = void 0;
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
},
|
|
641
|
-
async setup(global) {
|
|
642
|
-
global.console.Console = Console;
|
|
643
|
-
return {
|
|
644
|
-
teardown(global2) {
|
|
645
|
-
delete global2.console.Console;
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
const environments = {
|
|
652
|
-
node,
|
|
653
|
-
jsdom,
|
|
654
|
-
"happy-dom": happy,
|
|
655
|
-
"edge-runtime": edge
|
|
656
|
-
};
|
|
657
|
-
|
|
658
|
-
export { environments as e, populateGlobal as p };
|