vitest 0.32.4 → 0.34.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 (49) hide show
  1. package/LICENSE.md +0 -83
  2. package/dist/browser.d.ts +3 -2
  3. package/dist/browser.js +4 -8
  4. package/dist/child.js +43 -29
  5. package/dist/{chunk-api-setup.8f785c4a.js → chunk-api-setup.644415c3.js} +13 -7
  6. package/dist/{chunk-install-pkg.3fc886f2.js → chunk-install-pkg.dd70081b.js} +14 -13
  7. package/dist/{chunk-integrations-globals.0093e2ed.js → chunk-integrations-globals.877c84db.js} +7 -6
  8. package/dist/chunk-runtime-console.ea222ffb.js +108 -0
  9. package/dist/cli.js +15 -16
  10. package/dist/config.cjs +6 -5
  11. package/dist/config.d.ts +15 -19
  12. package/dist/config.js +6 -5
  13. package/dist/coverage.d.ts +3 -2
  14. package/dist/entry-vm.js +60 -0
  15. package/dist/entry.js +34 -213
  16. package/dist/environments.d.ts +3 -2
  17. package/dist/environments.js +4 -2
  18. package/dist/execute.js +15 -0
  19. package/dist/index.d.ts +12 -7
  20. package/dist/index.js +8 -7
  21. package/dist/loader.js +6 -4
  22. package/dist/node.d.ts +6 -53
  23. package/dist/node.js +17 -20
  24. package/dist/runners.d.ts +3 -2
  25. package/dist/runners.js +6 -5
  26. package/dist/{types-198fd1d9.d.ts → types-3c7dbfa5.d.ts} +139 -121
  27. package/dist/vendor-base.9c08bbd0.js +96 -0
  28. package/dist/{vendor-coverage.2e41927a.js → vendor-coverage.78040316.js} +1 -2
  29. package/dist/vendor-date.6e993429.js +50 -0
  30. package/dist/{vendor-environments.75f2b63d.js → vendor-environments.443ecd82.js} +202 -3
  31. package/dist/vendor-execute.9ab1c1a7.js +978 -0
  32. package/dist/{vendor-global.6795f91f.js → vendor-global.97e4527c.js} +2 -1
  33. package/dist/{vendor-index.23ac4e13.js → vendor-index.087d1af7.js} +2 -20
  34. package/dist/vendor-index.9378c9a4.js +89 -0
  35. package/dist/vendor-index.b271ebe4.js +92 -0
  36. package/dist/{vendor-index.2af39fbb.js → vendor-index.eff408fd.js} +2 -3
  37. package/dist/{vendor-cli-api.cb31e1db.js → vendor-node.00226ab1.js} +1671 -1882
  38. package/dist/{vendor-rpc.ad5b08c7.js → vendor-rpc.cbd8e972.js} +7 -4
  39. package/dist/{vendor-run-once.1fa85ba7.js → vendor-run-once.3e5ef7d7.js} +1 -2
  40. package/dist/vendor-source-map.e6c1997b.js +747 -0
  41. package/dist/{vendor-vi.dd6706cb.js → vendor-vi.271667ef.js} +26 -59
  42. package/dist/vm.js +114 -0
  43. package/dist/worker.js +39 -27
  44. package/execute.d.ts +1 -0
  45. package/package.json +14 -11
  46. package/suppress-warnings.cjs +2 -0
  47. package/dist/vendor-execute.3576af13.js +0 -421
  48. package/dist/vendor-index.cc463d9e.js +0 -189
  49. package/dist/vendor-tasks.f9d75aed.js +0 -14
@@ -1,8 +1,96 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ import { resolve, normalize } from 'pathe';
3
+ import { importModule, resolveModule } from 'local-pkg';
1
4
  import { Console } from 'node:console';
2
- import { importModule } from 'local-pkg';
3
5
 
6
+ const denyList = /* @__PURE__ */ new Set([
7
+ "GLOBAL",
8
+ "root",
9
+ "global",
10
+ "Buffer",
11
+ "ArrayBuffer",
12
+ "Uint8Array"
13
+ ]);
14
+ const nodeGlobals = new Map(
15
+ Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
16
+ const descriptor = Object.getOwnPropertyDescriptor(
17
+ globalThis,
18
+ nodeGlobalsKey
19
+ );
20
+ if (!descriptor) {
21
+ throw new Error(
22
+ `No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`
23
+ );
24
+ }
25
+ return [nodeGlobalsKey, descriptor];
26
+ })
27
+ );
4
28
  var node = {
5
29
  name: "node",
30
+ transformMode: "ssr",
31
+ // this is largely copied from jest's node environment
32
+ async setupVM() {
33
+ const vm = await import('node:vm');
34
+ const context = vm.createContext();
35
+ const global = vm.runInContext(
36
+ "this",
37
+ context
38
+ );
39
+ const contextGlobals = new Set(Object.getOwnPropertyNames(global));
40
+ for (const [nodeGlobalsKey, descriptor] of nodeGlobals) {
41
+ if (!contextGlobals.has(nodeGlobalsKey)) {
42
+ if (descriptor.configurable) {
43
+ Object.defineProperty(global, nodeGlobalsKey, {
44
+ configurable: true,
45
+ enumerable: descriptor.enumerable,
46
+ get() {
47
+ const val = globalThis[nodeGlobalsKey];
48
+ Object.defineProperty(global, nodeGlobalsKey, {
49
+ configurable: true,
50
+ enumerable: descriptor.enumerable,
51
+ value: val,
52
+ writable: descriptor.writable === true || nodeGlobalsKey === "performance"
53
+ });
54
+ return val;
55
+ },
56
+ set(val) {
57
+ Object.defineProperty(global, nodeGlobalsKey, {
58
+ configurable: true,
59
+ enumerable: descriptor.enumerable,
60
+ value: val,
61
+ writable: true
62
+ });
63
+ }
64
+ });
65
+ } else if ("value" in descriptor) {
66
+ Object.defineProperty(global, nodeGlobalsKey, {
67
+ configurable: false,
68
+ enumerable: descriptor.enumerable,
69
+ value: descriptor.value,
70
+ writable: descriptor.writable
71
+ });
72
+ } else {
73
+ Object.defineProperty(global, nodeGlobalsKey, {
74
+ configurable: false,
75
+ enumerable: descriptor.enumerable,
76
+ get: descriptor.get,
77
+ set: descriptor.set
78
+ });
79
+ }
80
+ }
81
+ }
82
+ global.global = global;
83
+ global.Buffer = Buffer;
84
+ global.ArrayBuffer = ArrayBuffer;
85
+ global.Uint8Array = Uint8Array;
86
+ return {
87
+ getVmContext() {
88
+ return context;
89
+ },
90
+ teardown() {
91
+ }
92
+ };
93
+ },
6
94
  async setup(global) {
7
95
  global.console.Console = Console;
8
96
  return {
@@ -128,6 +216,7 @@ const LIVING_KEYS = [
128
216
  "StorageEvent",
129
217
  "ProgressEvent",
130
218
  "PageTransitionEvent",
219
+ "SubmitEvent",
131
220
  "UIEvent",
132
221
  "FocusEvent",
133
222
  "InputEvent",
@@ -176,6 +265,8 @@ const LIVING_KEYS = [
176
265
  "AbortController",
177
266
  "AbortSignal",
178
267
  "ArrayBuffer",
268
+ "DOMRectReadOnly",
269
+ "DOMRect",
179
270
  // not specified in docs, but is available
180
271
  "Image",
181
272
  "Audio",
@@ -249,7 +340,8 @@ const skipKeys = [
249
340
  "window",
250
341
  "self",
251
342
  "top",
252
- "parent"
343
+ "parent",
344
+ "URL"
253
345
  ];
254
346
  function getWindowKeys(global, win) {
255
347
  const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
@@ -333,6 +425,57 @@ function catchWindowErrors(window) {
333
425
  }
334
426
  var jsdom = {
335
427
  name: "jsdom",
428
+ transformMode: "web",
429
+ async setupVM({ jsdom = {} }) {
430
+ const {
431
+ CookieJar,
432
+ JSDOM,
433
+ ResourceLoader,
434
+ VirtualConsole
435
+ } = await importModule("jsdom");
436
+ const {
437
+ html = "<!DOCTYPE html>",
438
+ userAgent,
439
+ url = "http://localhost:3000",
440
+ contentType = "text/html",
441
+ pretendToBeVisual = true,
442
+ includeNodeLocations = false,
443
+ runScripts = "dangerously",
444
+ resources,
445
+ console = false,
446
+ cookieJar = false,
447
+ ...restOptions
448
+ } = jsdom;
449
+ const dom = new JSDOM(
450
+ html,
451
+ {
452
+ pretendToBeVisual,
453
+ resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
454
+ runScripts,
455
+ url,
456
+ virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : void 0,
457
+ cookieJar: cookieJar ? new CookieJar() : void 0,
458
+ includeNodeLocations,
459
+ contentType,
460
+ userAgent,
461
+ ...restOptions
462
+ }
463
+ );
464
+ const clearWindowErrors = catchWindowErrors(dom.window);
465
+ dom.window.Buffer = Buffer;
466
+ dom.window.Uint8Array = Uint8Array;
467
+ if (typeof structuredClone !== "undefined" && !dom.window.structuredClone)
468
+ dom.window.structuredClone = structuredClone;
469
+ return {
470
+ getVmContext() {
471
+ return dom.getInternalVMContext();
472
+ },
473
+ teardown() {
474
+ clearWindowErrors();
475
+ dom.window.close();
476
+ }
477
+ };
478
+ },
336
479
  async setup(global, { jsdom = {} }) {
337
480
  const {
338
481
  CookieJar,
@@ -383,6 +526,23 @@ var jsdom = {
383
526
 
384
527
  var happy = {
385
528
  name: "happy-dom",
529
+ transformMode: "web",
530
+ async setupVM() {
531
+ const { Window } = await importModule("happy-dom");
532
+ const win = new Window();
533
+ win.Buffer = Buffer;
534
+ win.Uint8Array = Uint8Array;
535
+ if (typeof structuredClone !== "undefined" && !win.structuredClone)
536
+ win.structuredClone = structuredClone;
537
+ return {
538
+ getVmContext() {
539
+ return win;
540
+ },
541
+ teardown() {
542
+ win.happyDOM.cancelAsync();
543
+ }
544
+ };
545
+ },
386
546
  async setup(global) {
387
547
  const { Window, GlobalWindow } = await importModule("happy-dom");
388
548
  const win = new (GlobalWindow || Window)();
@@ -399,6 +559,24 @@ var happy = {
399
559
 
400
560
  var edge = {
401
561
  name: "edge-runtime",
562
+ transformMode: "ssr",
563
+ async setupVM() {
564
+ const { EdgeVM } = await importModule("@edge-runtime/vm");
565
+ const vm = new EdgeVM({
566
+ extend: (context) => {
567
+ context.global = context;
568
+ context.Buffer = Buffer;
569
+ return context;
570
+ }
571
+ });
572
+ return {
573
+ getVmContext() {
574
+ return vm.context;
575
+ },
576
+ teardown() {
577
+ }
578
+ };
579
+ },
402
580
  async setup(global) {
403
581
  const { EdgeVM } = await importModule("@edge-runtime/vm");
404
582
  const vm = new EdgeVM({
@@ -429,6 +607,9 @@ const envPackageNames = {
429
607
  "happy-dom": "happy-dom",
430
608
  "edge-runtime": "@edge-runtime/vm"
431
609
  };
610
+ function isBuiltinEnvironment(env) {
611
+ return env in environments;
612
+ }
432
613
  function getEnvPackageName(env) {
433
614
  if (env === "node")
434
615
  return null;
@@ -436,5 +617,23 @@ function getEnvPackageName(env) {
436
617
  return envPackageNames[env];
437
618
  return `vitest-environment-${env}`;
438
619
  }
620
+ async function loadEnvironment(name, root) {
621
+ if (isBuiltinEnvironment(name))
622
+ return environments[name];
623
+ const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : resolveModule(`vitest-environment-${name}`, { paths: [root] }) ?? resolve(root, name);
624
+ const pkg = await import(pathToFileURL(normalize(packageId)).href);
625
+ if (!pkg || !pkg.default || typeof pkg.default !== "object") {
626
+ throw new TypeError(
627
+ `Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`
628
+ );
629
+ }
630
+ const environment = pkg.default;
631
+ if (environment.transformMode !== "web" && environment.transformMode !== "ssr") {
632
+ throw new TypeError(
633
+ `Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web".`
634
+ );
635
+ }
636
+ return environment;
637
+ }
439
638
 
440
- export { environments as e, getEnvPackageName as g, populateGlobal as p };
639
+ export { environments as e, getEnvPackageName as g, loadEnvironment as l, populateGlobal as p };