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