vitest 0.18.0 → 0.19.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.
Files changed (36) hide show
  1. package/LICENSE.md +6 -6
  2. package/dist/browser.d.ts +1850 -0
  3. package/dist/browser.mjs +20 -0
  4. package/dist/{chunk-api-setup.63babd7c.mjs → chunk-api-setup.0cf2c96a.mjs} +37 -11
  5. package/dist/{chunk-constants.8eb2ed35.mjs → chunk-constants.38b43a44.mjs} +3 -3
  6. package/dist/{chunk-env-node.26c72624.mjs → chunk-defaults.ed196a9a.mjs} +458 -455
  7. package/dist/{chunk-install-pkg.2dcb2c04.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
  8. package/dist/chunk-integrations-globals.1018e651.mjs +24 -0
  9. package/dist/chunk-node-git.9058b82a.mjs +1139 -0
  10. package/dist/chunk-runtime-chain.f2e00f4c.mjs +2039 -0
  11. package/dist/{vendor-entry.78de67ab.mjs → chunk-runtime-error.606e0393.mjs} +167 -183
  12. package/dist/{chunk-runtime-chain.eb764dff.mjs → chunk-runtime-hooks.d4cadf47.mjs} +33 -2012
  13. package/dist/{chunk-runtime-mocker.79ccc3de.mjs → chunk-runtime-mocker.dfdfd57b.mjs} +70 -22
  14. package/dist/{chunk-runtime-rpc.cc6a06a2.mjs → chunk-runtime-rpc.45d8ee19.mjs} +1 -1
  15. package/dist/{chunk-utils-global.1b22c4fd.mjs → chunk-utils-global.2aa95025.mjs} +11 -6
  16. package/dist/{chunk-utils-source-map.957e7756.mjs → chunk-utils-source-map.8b066ce2.mjs} +2 -2
  17. package/dist/{chunk-vite-node-externalize.0791f2ed.mjs → chunk-vite-node-externalize.e9af6472.mjs} +105 -1174
  18. package/dist/chunk-vite-node-utils.ad73f2ab.mjs +1433 -0
  19. package/dist/cli.mjs +9 -11
  20. package/dist/config.cjs +4 -1
  21. package/dist/config.d.ts +1 -0
  22. package/dist/config.mjs +4 -1
  23. package/dist/entry.mjs +54 -10
  24. package/dist/index.d.ts +56 -27
  25. package/dist/index.mjs +12 -9
  26. package/dist/node.d.ts +37 -18
  27. package/dist/node.mjs +10 -12
  28. package/dist/spy.mjs +102 -2
  29. package/dist/suite.mjs +13 -0
  30. package/dist/vendor-index.61438b77.mjs +335 -0
  31. package/dist/{vendor-index.4bf9c627.mjs → vendor-index.62ce5c33.mjs} +11 -343
  32. package/dist/worker.mjs +6 -6
  33. package/package.json +20 -12
  34. package/dist/chunk-integrations-globals.61e4d6ae.mjs +0 -26
  35. package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
  36. package/dist/chunk-vite-node-utils.af8ead96.mjs +0 -9195
@@ -1,392 +1,8 @@
1
- import { importModule } from 'local-pkg';
2
1
  import { existsSync, promises } from 'fs';
3
2
  import { createRequire } from 'module';
4
- import { pathToFileURL } from 'url';
5
- import { F as toArray, q as resolve } from './chunk-utils-global.1b22c4fd.mjs';
6
-
7
- var node = {
8
- name: "node",
9
- async setup() {
10
- return {
11
- teardown() {
12
- }
13
- };
14
- }
15
- };
16
-
17
- const LIVING_KEYS = [
18
- "DOMException",
19
- "URL",
20
- "URLSearchParams",
21
- "EventTarget",
22
- "NamedNodeMap",
23
- "Node",
24
- "Attr",
25
- "Element",
26
- "DocumentFragment",
27
- "DOMImplementation",
28
- "Document",
29
- "XMLDocument",
30
- "CharacterData",
31
- "Text",
32
- "CDATASection",
33
- "ProcessingInstruction",
34
- "Comment",
35
- "DocumentType",
36
- "NodeList",
37
- "HTMLCollection",
38
- "HTMLOptionsCollection",
39
- "DOMStringMap",
40
- "DOMTokenList",
41
- "StyleSheetList",
42
- "HTMLElement",
43
- "HTMLHeadElement",
44
- "HTMLTitleElement",
45
- "HTMLBaseElement",
46
- "HTMLLinkElement",
47
- "HTMLMetaElement",
48
- "HTMLStyleElement",
49
- "HTMLBodyElement",
50
- "HTMLHeadingElement",
51
- "HTMLParagraphElement",
52
- "HTMLHRElement",
53
- "HTMLPreElement",
54
- "HTMLUListElement",
55
- "HTMLOListElement",
56
- "HTMLLIElement",
57
- "HTMLMenuElement",
58
- "HTMLDListElement",
59
- "HTMLDivElement",
60
- "HTMLAnchorElement",
61
- "HTMLAreaElement",
62
- "HTMLBRElement",
63
- "HTMLButtonElement",
64
- "HTMLCanvasElement",
65
- "HTMLDataElement",
66
- "HTMLDataListElement",
67
- "HTMLDetailsElement",
68
- "HTMLDialogElement",
69
- "HTMLDirectoryElement",
70
- "HTMLFieldSetElement",
71
- "HTMLFontElement",
72
- "HTMLFormElement",
73
- "HTMLHtmlElement",
74
- "HTMLImageElement",
75
- "HTMLInputElement",
76
- "HTMLLabelElement",
77
- "HTMLLegendElement",
78
- "HTMLMapElement",
79
- "HTMLMarqueeElement",
80
- "HTMLMediaElement",
81
- "HTMLMeterElement",
82
- "HTMLModElement",
83
- "HTMLOptGroupElement",
84
- "HTMLOptionElement",
85
- "HTMLOutputElement",
86
- "HTMLPictureElement",
87
- "HTMLProgressElement",
88
- "HTMLQuoteElement",
89
- "HTMLScriptElement",
90
- "HTMLSelectElement",
91
- "HTMLSlotElement",
92
- "HTMLSourceElement",
93
- "HTMLSpanElement",
94
- "HTMLTableCaptionElement",
95
- "HTMLTableCellElement",
96
- "HTMLTableColElement",
97
- "HTMLTableElement",
98
- "HTMLTimeElement",
99
- "HTMLTableRowElement",
100
- "HTMLTableSectionElement",
101
- "HTMLTemplateElement",
102
- "HTMLTextAreaElement",
103
- "HTMLUnknownElement",
104
- "HTMLFrameElement",
105
- "HTMLFrameSetElement",
106
- "HTMLIFrameElement",
107
- "HTMLEmbedElement",
108
- "HTMLObjectElement",
109
- "HTMLParamElement",
110
- "HTMLVideoElement",
111
- "HTMLAudioElement",
112
- "HTMLTrackElement",
113
- "SVGElement",
114
- "SVGGraphicsElement",
115
- "SVGSVGElement",
116
- "SVGTitleElement",
117
- "SVGAnimatedString",
118
- "SVGNumber",
119
- "SVGStringList",
120
- "Event",
121
- "CloseEvent",
122
- "CustomEvent",
123
- "MessageEvent",
124
- "ErrorEvent",
125
- "HashChangeEvent",
126
- "PopStateEvent",
127
- "StorageEvent",
128
- "ProgressEvent",
129
- "PageTransitionEvent",
130
- "UIEvent",
131
- "FocusEvent",
132
- "InputEvent",
133
- "MouseEvent",
134
- "KeyboardEvent",
135
- "TouchEvent",
136
- "CompositionEvent",
137
- "WheelEvent",
138
- "BarProp",
139
- "External",
140
- "Location",
141
- "History",
142
- "Screen",
143
- "Performance",
144
- "Navigator",
145
- "PluginArray",
146
- "MimeTypeArray",
147
- "Plugin",
148
- "MimeType",
149
- "FileReader",
150
- "Blob",
151
- "File",
152
- "FileList",
153
- "ValidityState",
154
- "DOMParser",
155
- "XMLSerializer",
156
- "FormData",
157
- "XMLHttpRequestEventTarget",
158
- "XMLHttpRequestUpload",
159
- "XMLHttpRequest",
160
- "WebSocket",
161
- "NodeFilter",
162
- "NodeIterator",
163
- "TreeWalker",
164
- "AbstractRange",
165
- "Range",
166
- "StaticRange",
167
- "Selection",
168
- "Storage",
169
- "CustomElementRegistry",
170
- "ShadowRoot",
171
- "MutationObserver",
172
- "MutationRecord",
173
- "Headers",
174
- "AbortController",
175
- "AbortSignal",
176
- "Image",
177
- "Audio",
178
- "Option"
179
- ];
180
- const OTHER_KEYS = [
181
- "addEventListener",
182
- "alert",
183
- "atob",
184
- "blur",
185
- "btoa",
186
- "cancelAnimationFrame",
187
- "close",
188
- "confirm",
189
- "createPopup",
190
- "dispatchEvent",
191
- "document",
192
- "focus",
193
- "frames",
194
- "getComputedStyle",
195
- "history",
196
- "innerHeight",
197
- "innerWidth",
198
- "length",
199
- "location",
200
- "matchMedia",
201
- "moveBy",
202
- "moveTo",
203
- "name",
204
- "navigator",
205
- "open",
206
- "outerHeight",
207
- "outerWidth",
208
- "pageXOffset",
209
- "pageYOffset",
210
- "parent",
211
- "postMessage",
212
- "print",
213
- "prompt",
214
- "removeEventListener",
215
- "requestAnimationFrame",
216
- "resizeBy",
217
- "resizeTo",
218
- "screen",
219
- "screenLeft",
220
- "screenTop",
221
- "screenX",
222
- "screenY",
223
- "scroll",
224
- "scrollBy",
225
- "scrollLeft",
226
- "scrollTo",
227
- "scrollTop",
228
- "scrollX",
229
- "scrollY",
230
- "self",
231
- "stop",
232
- "top",
233
- "Window",
234
- "window"
235
- ];
236
- const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
237
-
238
- const allowRewrite = [
239
- "Event",
240
- "EventTarget",
241
- "MessageEvent"
242
- ];
243
- const skipKeys = [
244
- "window",
245
- "self",
246
- "top",
247
- "parent"
248
- ];
249
- function getWindowKeys(global, win) {
250
- const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
251
- if (skipKeys.includes(k))
252
- return false;
253
- if (k in global)
254
- return allowRewrite.includes(k);
255
- return true;
256
- }));
257
- return keys;
258
- }
259
- function isClassLikeName(name) {
260
- return name[0] === name[0].toUpperCase();
261
- }
262
- function populateGlobal(global, win, options = {}) {
263
- const { bindFunctions = false } = options;
264
- const keys = getWindowKeys(global, win);
265
- const originals = new Map(allowRewrite.map(([key]) => [key, global[key]]));
266
- const overrideObject = /* @__PURE__ */ new Map();
267
- for (const key of keys) {
268
- const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
269
- Object.defineProperty(global, key, {
270
- get() {
271
- if (overrideObject.has(key))
272
- return overrideObject.get(key);
273
- if (boundFunction)
274
- return boundFunction;
275
- return win[key];
276
- },
277
- set(v) {
278
- overrideObject.set(key, v);
279
- },
280
- configurable: true
281
- });
282
- }
283
- global.window = global;
284
- global.self = global;
285
- global.top = global;
286
- global.parent = global;
287
- if (global.global)
288
- global.global = global;
289
- skipKeys.forEach((k) => keys.add(k));
290
- return {
291
- keys,
292
- skipKeys,
293
- originals
294
- };
295
- }
296
-
297
- var jsdom = {
298
- name: "jsdom",
299
- async setup(global, { jsdom = {} }) {
300
- const {
301
- CookieJar,
302
- JSDOM,
303
- ResourceLoader,
304
- VirtualConsole
305
- } = await importModule("jsdom");
306
- const {
307
- html = "<!DOCTYPE html>",
308
- userAgent,
309
- url = "http://localhost:3000",
310
- contentType = "text/html",
311
- pretendToBeVisual = true,
312
- includeNodeLocations = false,
313
- runScripts = "dangerously",
314
- resources,
315
- console = false,
316
- cookieJar = false,
317
- ...restOptions
318
- } = jsdom;
319
- const dom = new JSDOM(html, {
320
- pretendToBeVisual,
321
- resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
322
- runScripts,
323
- url,
324
- virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
325
- cookieJar: cookieJar ? new CookieJar() : void 0,
326
- includeNodeLocations,
327
- contentType,
328
- userAgent,
329
- ...restOptions
330
- });
331
- const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
332
- return {
333
- teardown(global2) {
334
- keys.forEach((key) => delete global2[key]);
335
- originals.forEach((v, k) => global2[k] = v);
336
- }
337
- };
338
- }
339
- };
340
-
341
- var happy = {
342
- name: "happy-dom",
343
- async setup(global) {
344
- const { Window, GlobalWindow } = await importModule("happy-dom");
345
- const win = new (GlobalWindow || Window)();
346
- const { keys, originals } = populateGlobal(global, win, { bindFunctions: true });
347
- return {
348
- teardown(global2) {
349
- win.happyDOM.cancelAsync();
350
- keys.forEach((key) => delete global2[key]);
351
- originals.forEach((v, k) => global2[k] = v);
352
- }
353
- };
354
- }
355
- };
356
-
357
- var edge = {
358
- name: "edge-runtime",
359
- async setup(global) {
360
- const { EdgeVM } = await importModule("@edge-runtime/vm");
361
- const vm = new EdgeVM({
362
- extend: (context) => {
363
- context.global = context;
364
- context.Buffer = Buffer;
365
- return context;
366
- }
367
- });
368
- const { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
369
- return {
370
- teardown(global2) {
371
- keys.forEach((key) => delete global2[key]);
372
- originals.forEach((v, k) => global2[k] = v);
373
- }
374
- };
375
- }
376
- };
377
-
378
- const environments = {
379
- node,
380
- jsdom,
381
- "happy-dom": happy,
382
- "edge-runtime": edge
383
- };
384
- const envs = Object.keys(environments);
385
- const envPackageNames = {
386
- "jsdom": "jsdom",
387
- "happy-dom": "happy-dom",
388
- "edge-runtime": "@edge-runtime/vm"
389
- };
3
+ import _url from 'url';
4
+ import { u as toArray, C as resolve } from './chunk-utils-global.2aa95025.mjs';
5
+ import { importModule } from 'local-pkg';
390
6
 
391
7
  /*
392
8
  How it works:
@@ -527,14 +143,16 @@ const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
527
143
  const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
528
144
  const defaultCoverageExcludes = [
529
145
  "coverage/**",
146
+ "dist/**",
530
147
  "packages/*/test{,s}/**",
531
148
  "**/*.d.ts",
532
149
  "cypress/**",
533
150
  "test{,s}/**",
534
151
  "test{,-*}.{js,cjs,mjs,ts,tsx,jsx}",
535
152
  "**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}",
153
+ "**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}",
536
154
  "**/__tests__/**",
537
- "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc}.config.{js,cjs,mjs,ts}",
155
+ "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress}.config.{js,cjs,mjs,ts}",
538
156
  "**/.{eslint,mocha,prettier}rc.{js,cjs,yml}"
539
157
  ];
540
158
  const coverageConfigDefaults = {
@@ -574,6 +192,7 @@ const config = {
574
192
  exclude: defaultExclude,
575
193
  testTimeout: 5e3,
576
194
  hookTimeout: 1e4,
195
+ teardownTimeout: 1e3,
577
196
  isolate: true,
578
197
  watchExclude: ["**/node_modules/**", "**/dist/**"],
579
198
  forceRerunTriggers: [
@@ -597,79 +216,463 @@ const config = {
597
216
  };
598
217
  const configDefaults = Object.freeze(config);
599
218
 
600
- function resolveC8Options(options, root) {
601
- const resolved = {
602
- ...configDefaults.coverage,
603
- ...options
604
- };
605
- resolved.reporter = toArray(resolved.reporter);
606
- resolved.reportsDirectory = resolve(root, resolved.reportsDirectory);
607
- resolved.tempDirectory = process.env.NODE_V8_COVERAGE || resolve(resolved.reportsDirectory, "tmp");
608
- return resolved;
219
+ function resolveC8Options(options, root) {
220
+ const resolved = {
221
+ ...configDefaults.coverage,
222
+ ...options
223
+ };
224
+ resolved.reporter = toArray(resolved.reporter);
225
+ resolved.reportsDirectory = resolve(root, resolved.reportsDirectory);
226
+ resolved.tempDirectory = process.env.NODE_V8_COVERAGE || resolve(resolved.reportsDirectory, "tmp");
227
+ return resolved;
228
+ }
229
+ async function cleanCoverage(options, clean = true) {
230
+ if (clean && existsSync(options.reportsDirectory))
231
+ await promises.rm(options.reportsDirectory, { recursive: true, force: true });
232
+ if (!existsSync(options.tempDirectory))
233
+ await promises.mkdir(options.tempDirectory, { recursive: true });
234
+ }
235
+ const require = createRequire(import.meta.url);
236
+ function takeCoverage() {
237
+ const v8 = require("v8");
238
+ if (v8.takeCoverage == null)
239
+ console.warn("[Vitest] takeCoverage is not available in this NodeJs version.\nCoverage could be incomplete. Update to NodeJs 14.18.");
240
+ else
241
+ v8.takeCoverage();
242
+ }
243
+ async function reportCoverage(ctx) {
244
+ takeCoverage();
245
+ const createReport = require("c8/lib/report");
246
+ const report = createReport(ctx.config.coverage);
247
+ const sourceMapMeta = {};
248
+ await Promise.all(Array.from(ctx.vitenode.fetchCache.entries()).filter((i) => !i[0].includes("/node_modules/")).map(async ([file, { result }]) => {
249
+ const map = result.map;
250
+ if (!map)
251
+ return;
252
+ const url = _url.pathToFileURL(file).href;
253
+ let code;
254
+ try {
255
+ code = (await promises.readFile(file)).toString();
256
+ } catch {
257
+ }
258
+ const sources = [url];
259
+ sourceMapMeta[url] = {
260
+ source: result.code,
261
+ map: {
262
+ sourcesContent: code ? [code] : void 0,
263
+ ...map,
264
+ sources
265
+ }
266
+ };
267
+ }));
268
+ const offset = 224;
269
+ report._getSourceMap = (coverage) => {
270
+ const path = _url.pathToFileURL(coverage.url).href;
271
+ const data = sourceMapMeta[path];
272
+ if (!data)
273
+ return {};
274
+ return {
275
+ sourceMap: {
276
+ sourcemap: data.map
277
+ },
278
+ source: Array(offset).fill(".").join("") + data.source
279
+ };
280
+ };
281
+ await report.run();
282
+ if (ctx.config.coverage.enabled) {
283
+ if (ctx.config.coverage["100"]) {
284
+ ctx.config.coverage.lines = 100;
285
+ ctx.config.coverage.functions = 100;
286
+ ctx.config.coverage.branches = 100;
287
+ ctx.config.coverage.statements = 100;
288
+ }
289
+ const { checkCoverages } = require("c8/lib/commands/check-coverage");
290
+ await checkCoverages(ctx.config.coverage, report);
291
+ }
292
+ }
293
+
294
+ var node = {
295
+ name: "node",
296
+ async setup() {
297
+ return {
298
+ teardown() {
299
+ }
300
+ };
301
+ }
302
+ };
303
+
304
+ const LIVING_KEYS = [
305
+ "DOMException",
306
+ "URL",
307
+ "URLSearchParams",
308
+ "EventTarget",
309
+ "NamedNodeMap",
310
+ "Node",
311
+ "Attr",
312
+ "Element",
313
+ "DocumentFragment",
314
+ "DOMImplementation",
315
+ "Document",
316
+ "XMLDocument",
317
+ "CharacterData",
318
+ "Text",
319
+ "CDATASection",
320
+ "ProcessingInstruction",
321
+ "Comment",
322
+ "DocumentType",
323
+ "NodeList",
324
+ "HTMLCollection",
325
+ "HTMLOptionsCollection",
326
+ "DOMStringMap",
327
+ "DOMTokenList",
328
+ "StyleSheetList",
329
+ "HTMLElement",
330
+ "HTMLHeadElement",
331
+ "HTMLTitleElement",
332
+ "HTMLBaseElement",
333
+ "HTMLLinkElement",
334
+ "HTMLMetaElement",
335
+ "HTMLStyleElement",
336
+ "HTMLBodyElement",
337
+ "HTMLHeadingElement",
338
+ "HTMLParagraphElement",
339
+ "HTMLHRElement",
340
+ "HTMLPreElement",
341
+ "HTMLUListElement",
342
+ "HTMLOListElement",
343
+ "HTMLLIElement",
344
+ "HTMLMenuElement",
345
+ "HTMLDListElement",
346
+ "HTMLDivElement",
347
+ "HTMLAnchorElement",
348
+ "HTMLAreaElement",
349
+ "HTMLBRElement",
350
+ "HTMLButtonElement",
351
+ "HTMLCanvasElement",
352
+ "HTMLDataElement",
353
+ "HTMLDataListElement",
354
+ "HTMLDetailsElement",
355
+ "HTMLDialogElement",
356
+ "HTMLDirectoryElement",
357
+ "HTMLFieldSetElement",
358
+ "HTMLFontElement",
359
+ "HTMLFormElement",
360
+ "HTMLHtmlElement",
361
+ "HTMLImageElement",
362
+ "HTMLInputElement",
363
+ "HTMLLabelElement",
364
+ "HTMLLegendElement",
365
+ "HTMLMapElement",
366
+ "HTMLMarqueeElement",
367
+ "HTMLMediaElement",
368
+ "HTMLMeterElement",
369
+ "HTMLModElement",
370
+ "HTMLOptGroupElement",
371
+ "HTMLOptionElement",
372
+ "HTMLOutputElement",
373
+ "HTMLPictureElement",
374
+ "HTMLProgressElement",
375
+ "HTMLQuoteElement",
376
+ "HTMLScriptElement",
377
+ "HTMLSelectElement",
378
+ "HTMLSlotElement",
379
+ "HTMLSourceElement",
380
+ "HTMLSpanElement",
381
+ "HTMLTableCaptionElement",
382
+ "HTMLTableCellElement",
383
+ "HTMLTableColElement",
384
+ "HTMLTableElement",
385
+ "HTMLTimeElement",
386
+ "HTMLTableRowElement",
387
+ "HTMLTableSectionElement",
388
+ "HTMLTemplateElement",
389
+ "HTMLTextAreaElement",
390
+ "HTMLUnknownElement",
391
+ "HTMLFrameElement",
392
+ "HTMLFrameSetElement",
393
+ "HTMLIFrameElement",
394
+ "HTMLEmbedElement",
395
+ "HTMLObjectElement",
396
+ "HTMLParamElement",
397
+ "HTMLVideoElement",
398
+ "HTMLAudioElement",
399
+ "HTMLTrackElement",
400
+ "SVGElement",
401
+ "SVGGraphicsElement",
402
+ "SVGSVGElement",
403
+ "SVGTitleElement",
404
+ "SVGAnimatedString",
405
+ "SVGNumber",
406
+ "SVGStringList",
407
+ "Event",
408
+ "CloseEvent",
409
+ "CustomEvent",
410
+ "MessageEvent",
411
+ "ErrorEvent",
412
+ "HashChangeEvent",
413
+ "PopStateEvent",
414
+ "StorageEvent",
415
+ "ProgressEvent",
416
+ "PageTransitionEvent",
417
+ "UIEvent",
418
+ "FocusEvent",
419
+ "InputEvent",
420
+ "MouseEvent",
421
+ "KeyboardEvent",
422
+ "TouchEvent",
423
+ "CompositionEvent",
424
+ "WheelEvent",
425
+ "BarProp",
426
+ "External",
427
+ "Location",
428
+ "History",
429
+ "Screen",
430
+ "Performance",
431
+ "Navigator",
432
+ "PluginArray",
433
+ "MimeTypeArray",
434
+ "Plugin",
435
+ "MimeType",
436
+ "FileReader",
437
+ "Blob",
438
+ "File",
439
+ "FileList",
440
+ "ValidityState",
441
+ "DOMParser",
442
+ "XMLSerializer",
443
+ "FormData",
444
+ "XMLHttpRequestEventTarget",
445
+ "XMLHttpRequestUpload",
446
+ "XMLHttpRequest",
447
+ "WebSocket",
448
+ "NodeFilter",
449
+ "NodeIterator",
450
+ "TreeWalker",
451
+ "AbstractRange",
452
+ "Range",
453
+ "StaticRange",
454
+ "Selection",
455
+ "Storage",
456
+ "CustomElementRegistry",
457
+ "ShadowRoot",
458
+ "MutationObserver",
459
+ "MutationRecord",
460
+ "Headers",
461
+ "AbortController",
462
+ "AbortSignal",
463
+ "Image",
464
+ "Audio",
465
+ "Option"
466
+ ];
467
+ const OTHER_KEYS = [
468
+ "addEventListener",
469
+ "alert",
470
+ "atob",
471
+ "blur",
472
+ "btoa",
473
+ "cancelAnimationFrame",
474
+ "close",
475
+ "confirm",
476
+ "createPopup",
477
+ "dispatchEvent",
478
+ "document",
479
+ "focus",
480
+ "frames",
481
+ "getComputedStyle",
482
+ "history",
483
+ "innerHeight",
484
+ "innerWidth",
485
+ "length",
486
+ "location",
487
+ "matchMedia",
488
+ "moveBy",
489
+ "moveTo",
490
+ "name",
491
+ "navigator",
492
+ "open",
493
+ "outerHeight",
494
+ "outerWidth",
495
+ "pageXOffset",
496
+ "pageYOffset",
497
+ "parent",
498
+ "postMessage",
499
+ "print",
500
+ "prompt",
501
+ "removeEventListener",
502
+ "requestAnimationFrame",
503
+ "resizeBy",
504
+ "resizeTo",
505
+ "screen",
506
+ "screenLeft",
507
+ "screenTop",
508
+ "screenX",
509
+ "screenY",
510
+ "scroll",
511
+ "scrollBy",
512
+ "scrollLeft",
513
+ "scrollTo",
514
+ "scrollTop",
515
+ "scrollX",
516
+ "scrollY",
517
+ "self",
518
+ "stop",
519
+ "top",
520
+ "Window",
521
+ "window"
522
+ ];
523
+ const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
524
+
525
+ const allowRewrite = [
526
+ "Event",
527
+ "EventTarget",
528
+ "MessageEvent"
529
+ ];
530
+ const skipKeys = [
531
+ "window",
532
+ "self",
533
+ "top",
534
+ "parent"
535
+ ];
536
+ function getWindowKeys(global, win) {
537
+ const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
538
+ if (skipKeys.includes(k))
539
+ return false;
540
+ if (k in global)
541
+ return allowRewrite.includes(k);
542
+ return true;
543
+ }));
544
+ return keys;
609
545
  }
610
- async function cleanCoverage(options, clean = true) {
611
- if (clean && existsSync(options.reportsDirectory))
612
- await promises.rm(options.reportsDirectory, { recursive: true, force: true });
613
- if (!existsSync(options.tempDirectory))
614
- await promises.mkdir(options.tempDirectory, { recursive: true });
546
+ function isClassLikeName(name) {
547
+ return name[0] === name[0].toUpperCase();
615
548
  }
616
- const require = createRequire(import.meta.url);
617
- function takeCoverage() {
618
- const v8 = require("v8");
619
- if (v8.takeCoverage == null)
620
- console.warn("[Vitest] takeCoverage is not available in this NodeJs version.\nCoverage could be incomplete. Update to NodeJs 14.18.");
621
- else
622
- v8.takeCoverage();
549
+ function populateGlobal(global, win, options = {}) {
550
+ const { bindFunctions = false } = options;
551
+ const keys = getWindowKeys(global, win);
552
+ const originals = new Map(allowRewrite.map(([key]) => [key, global[key]]));
553
+ const overrideObject = /* @__PURE__ */ new Map();
554
+ for (const key of keys) {
555
+ const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
556
+ Object.defineProperty(global, key, {
557
+ get() {
558
+ if (overrideObject.has(key))
559
+ return overrideObject.get(key);
560
+ if (boundFunction)
561
+ return boundFunction;
562
+ return win[key];
563
+ },
564
+ set(v) {
565
+ overrideObject.set(key, v);
566
+ },
567
+ configurable: true
568
+ });
569
+ }
570
+ global.window = global;
571
+ global.self = global;
572
+ global.top = global;
573
+ global.parent = global;
574
+ if (global.global)
575
+ global.global = global;
576
+ skipKeys.forEach((k) => keys.add(k));
577
+ return {
578
+ keys,
579
+ skipKeys,
580
+ originals
581
+ };
623
582
  }
624
- async function reportCoverage(ctx) {
625
- takeCoverage();
626
- const createReport = require("c8/lib/report");
627
- const report = createReport(ctx.config.coverage);
628
- const sourceMapMeta = {};
629
- await Promise.all(Array.from(ctx.vitenode.fetchCache.entries()).filter((i) => !i[0].includes("/node_modules/")).map(async ([file, { result }]) => {
630
- const map = result.map;
631
- if (!map)
632
- return;
633
- const url = pathToFileURL(file).href;
634
- let code;
635
- try {
636
- code = (await promises.readFile(file)).toString();
637
- } catch {
638
- }
639
- const sources = [url];
640
- sourceMapMeta[url] = {
641
- source: result.code,
642
- map: {
643
- sourcesContent: code ? [code] : void 0,
644
- ...map,
645
- sources
583
+
584
+ var jsdom = {
585
+ name: "jsdom",
586
+ async setup(global, { jsdom = {} }) {
587
+ const {
588
+ CookieJar,
589
+ JSDOM,
590
+ ResourceLoader,
591
+ VirtualConsole
592
+ } = await importModule("jsdom");
593
+ const {
594
+ html = "<!DOCTYPE html>",
595
+ userAgent,
596
+ url = "http://localhost:3000",
597
+ contentType = "text/html",
598
+ pretendToBeVisual = true,
599
+ includeNodeLocations = false,
600
+ runScripts = "dangerously",
601
+ resources,
602
+ console = false,
603
+ cookieJar = false,
604
+ ...restOptions
605
+ } = jsdom;
606
+ const dom = new JSDOM(html, {
607
+ pretendToBeVisual,
608
+ resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
609
+ runScripts,
610
+ url,
611
+ virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
612
+ cookieJar: cookieJar ? new CookieJar() : void 0,
613
+ includeNodeLocations,
614
+ contentType,
615
+ userAgent,
616
+ ...restOptions
617
+ });
618
+ const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
619
+ return {
620
+ teardown(global2) {
621
+ keys.forEach((key) => delete global2[key]);
622
+ originals.forEach((v, k) => global2[k] = v);
646
623
  }
647
624
  };
648
- }));
649
- const offset = 224;
650
- report._getSourceMap = (coverage) => {
651
- const path = pathToFileURL(coverage.url).href;
652
- const data = sourceMapMeta[path];
653
- if (!data)
654
- return {};
625
+ }
626
+ };
627
+
628
+ var happy = {
629
+ name: "happy-dom",
630
+ async setup(global) {
631
+ const { Window, GlobalWindow } = await importModule("happy-dom");
632
+ const win = new (GlobalWindow || Window)();
633
+ const { keys, originals } = populateGlobal(global, win, { bindFunctions: true });
655
634
  return {
656
- sourceMap: {
657
- sourcemap: data.map
658
- },
659
- source: Array(offset).fill(".").join("") + data.source
635
+ teardown(global2) {
636
+ win.happyDOM.cancelAsync();
637
+ keys.forEach((key) => delete global2[key]);
638
+ originals.forEach((v, k) => global2[k] = v);
639
+ }
660
640
  };
661
- };
662
- await report.run();
663
- if (ctx.config.coverage.enabled) {
664
- if (ctx.config.coverage["100"]) {
665
- ctx.config.coverage.lines = 100;
666
- ctx.config.coverage.functions = 100;
667
- ctx.config.coverage.branches = 100;
668
- ctx.config.coverage.statements = 100;
669
- }
670
- const { checkCoverages } = require("c8/lib/commands/check-coverage");
671
- await checkCoverages(ctx.config.coverage, report);
672
641
  }
673
- }
642
+ };
643
+
644
+ var edge = {
645
+ name: "edge-runtime",
646
+ async setup(global) {
647
+ const { EdgeVM } = await importModule("@edge-runtime/vm");
648
+ const vm = new EdgeVM({
649
+ extend: (context) => {
650
+ context.global = context;
651
+ context.Buffer = Buffer;
652
+ return context;
653
+ }
654
+ });
655
+ const { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
656
+ return {
657
+ teardown(global2) {
658
+ keys.forEach((key) => delete global2[key]);
659
+ originals.forEach((v, k) => global2[k] = v);
660
+ }
661
+ };
662
+ }
663
+ };
664
+
665
+ const environments = {
666
+ node,
667
+ jsdom,
668
+ "happy-dom": happy,
669
+ "edge-runtime": edge
670
+ };
671
+ const envs = Object.keys(environments);
672
+ const envPackageNames = {
673
+ "jsdom": "jsdom",
674
+ "happy-dom": "happy-dom",
675
+ "edge-runtime": "@edge-runtime/vm"
676
+ };
674
677
 
675
- export { cleanCoverage as a, reportCoverage as b, configDefaults as c, environments as d, envPackageNames as e, envs as f, pLimit as p, resolveC8Options as r, takeCoverage as t };
678
+ export { cleanCoverage as a, reportCoverage as b, configDefaults as c, envPackageNames as d, environments as e, envs as f, pLimit as p, resolveC8Options as r, takeCoverage as t };