vitest 0.18.1 → 0.19.0

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