vitest 4.0.0-beta.1 → 4.0.0-beta.11

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 (90) hide show
  1. package/LICENSE.md +83 -2
  2. package/dist/browser.d.ts +19 -16
  3. package/dist/browser.js +11 -7
  4. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.LXhJ0F0X.js} +7 -9
  5. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  6. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.Dx7DO_Ce.d.ts} +5 -5
  7. package/dist/chunks/{cac.D3EzDDZd.js → cac.elvK37c9.js} +71 -153
  8. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.C7plPyhs.js} +1376 -1693
  9. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  10. package/dist/chunks/{console.CtFJOzRO.js → console.CiTi59Jy.js} +35 -71
  11. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  12. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.CG6Uhorw.js} +522 -792
  13. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  14. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  15. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  16. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  17. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  18. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  19. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  20. package/dist/chunks/{globals.Cxal6MLI.js → globals.BjvYA-AD.js} +11 -9
  21. package/dist/chunks/{index.BWf_gE5n.js → index.AZOjjqWP.js} +7 -6
  22. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  23. package/dist/chunks/{index.TfbsX-3I.js → index.BhY64fF0.js} +16 -26
  24. package/dist/chunks/{index.CZI_8rVt.js → index.BwBttQPf.js} +340 -663
  25. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  26. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  27. package/dist/chunks/moduleRunner.d.BNa-CL9e.d.ts +201 -0
  28. package/dist/chunks/{node.fjCdwEIl.js → node.BsdMi6DV.js} +2 -2
  29. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.C5phQR6o.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.CVzhsTvK.d.ts} +1233 -1293
  31. package/dist/chunks/resolveSnapshotEnvironment.DQVamkje.js +81 -0
  32. package/dist/chunks/rpc.jKGRSXIH.js +65 -0
  33. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.NAWRuMRP.js} +18 -30
  34. package/dist/chunks/startModuleRunner.oAuCu1yL.js +682 -0
  35. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  36. package/dist/chunks/test.KC5tH8hC.js +214 -0
  37. package/dist/chunks/typechecker.gXq-5P3n.js +1438 -0
  38. package/dist/chunks/{utils.XdZDrNZV.js → utils.DGKhod2J.js} +9 -28
  39. package/dist/chunks/{vi.bdSIJ99Y.js → vi.CiJ0Laa6.js} +159 -306
  40. package/dist/chunks/worker.d.B_Fd9M_w.d.ts +100 -0
  41. package/dist/chunks/worker.rPGLlbkW.js +200 -0
  42. package/dist/cli.js +8 -6
  43. package/dist/config.cjs +3 -9
  44. package/dist/config.d.ts +49 -54
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +27 -26
  47. package/dist/coverage.js +6 -8
  48. package/dist/environments.d.ts +9 -13
  49. package/dist/environments.js +1 -1
  50. package/dist/index.d.ts +38 -45
  51. package/dist/index.js +10 -10
  52. package/dist/module-evaluator.d.ts +13 -0
  53. package/dist/module-evaluator.js +276 -0
  54. package/dist/module-runner.js +15 -0
  55. package/dist/node.d.ts +44 -42
  56. package/dist/node.js +30 -36
  57. package/dist/reporters.d.ts +12 -13
  58. package/dist/reporters.js +7 -5
  59. package/dist/runners.d.ts +3 -3
  60. package/dist/runners.js +15 -232
  61. package/dist/snapshot.js +3 -3
  62. package/dist/suite.d.ts +2 -2
  63. package/dist/suite.js +4 -3
  64. package/dist/worker-base.js +203 -0
  65. package/dist/{chunks/vm.BThCzidc.js → worker-vm.js} +179 -228
  66. package/dist/workers/runVmTests.js +39 -56
  67. package/globals.d.ts +17 -17
  68. package/package.json +40 -38
  69. package/browser.d.ts +0 -1
  70. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  71. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  72. package/dist/chunks/index.D-VkfKhf.js +0 -105
  73. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  74. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  75. package/dist/chunks/typechecker.CVytUJuF.js +0 -874
  76. package/dist/chunks/utils.CAioKnHs.js +0 -61
  77. package/dist/chunks/worker.d.CmvJfRGs.d.ts +0 -8
  78. package/dist/chunks/worker.d.DoNjFAiv.d.ts +0 -169
  79. package/dist/execute.d.ts +0 -148
  80. package/dist/execute.js +0 -13
  81. package/dist/worker.js +0 -124
  82. package/dist/workers/forks.js +0 -43
  83. package/dist/workers/threads.js +0 -31
  84. package/dist/workers/vmForks.js +0 -47
  85. package/dist/workers/vmThreads.js +0 -37
  86. package/dist/workers.d.ts +0 -37
  87. package/dist/workers.js +0 -30
  88. package/execute.d.ts +0 -1
  89. package/utils.d.ts +0 -1
  90. package/workers.d.ts +0 -1
@@ -3,8 +3,6 @@ import { Console } from 'node:console';
3
3
  // SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
4
4
  const LIVING_KEYS = [
5
5
  "DOMException",
6
- "URL",
7
- "URLSearchParams",
8
6
  "EventTarget",
9
7
  "NamedNodeMap",
10
8
  "Node",
@@ -161,9 +159,6 @@ const LIVING_KEYS = [
161
159
  "ShadowRoot",
162
160
  "MutationObserver",
163
161
  "MutationRecord",
164
- "Headers",
165
- "AbortController",
166
- "AbortSignal",
167
162
  "Uint8Array",
168
163
  "Uint16Array",
169
164
  "Uint32Array",
@@ -180,8 +175,7 @@ const LIVING_KEYS = [
180
175
  "Audio",
181
176
  "Option",
182
177
  "CSS"
183
- ];
184
- const OTHER_KEYS = [
178
+ ], OTHER_KEYS = [
185
179
  "addEventListener",
186
180
  "alert",
187
181
  "blur",
@@ -244,11 +238,8 @@ const skipKeys = [
244
238
  "parent"
245
239
  ];
246
240
  function getWindowKeys(global, win, additionalKeys = []) {
247
- const keysArray = [...additionalKeys, ...KEYS];
248
- const keys = new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
249
- if (skipKeys.includes(k)) return false;
250
- if (k in global) return keysArray.includes(k);
251
- return true;
241
+ const keysArray = [...additionalKeys, ...KEYS], keys = new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
242
+ return skipKeys.includes(k) ? false : k in global ? keysArray.includes(k) : true;
252
243
  }));
253
244
  return keys;
254
245
  }
@@ -256,18 +247,13 @@ function isClassLikeName(name) {
256
247
  return name[0] === name[0].toUpperCase();
257
248
  }
258
249
  function populateGlobal(global, win, options = {}) {
259
- const { bindFunctions = false } = options;
260
- const keys = getWindowKeys(global, win, options.additionalKeys);
261
- const originals = /* @__PURE__ */ new Map();
262
- const overrideObject = /* @__PURE__ */ new Map();
250
+ const { bindFunctions = false } = options, keys = getWindowKeys(global, win, options.additionalKeys), originals = /* @__PURE__ */ new Map(), overrideObject = /* @__PURE__ */ new Map();
263
251
  for (const key of keys) {
264
252
  const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
265
253
  if (KEYS.includes(key) && key in global) originals.set(key, global[key]);
266
254
  Object.defineProperty(global, key, {
267
255
  get() {
268
- if (overrideObject.has(key)) return overrideObject.get(key);
269
- if (boundFunction) return boundFunction;
270
- return win[key];
256
+ return overrideObject.has(key) ? overrideObject.get(key) : boundFunction || win[key];
271
257
  },
272
258
  set(v) {
273
259
  overrideObject.set(key, v);
@@ -275,19 +261,14 @@ function populateGlobal(global, win, options = {}) {
275
261
  configurable: true
276
262
  });
277
263
  }
278
- global.window = global;
279
- global.self = global;
280
- global.top = global;
281
- global.parent = global;
282
- if (global.global) global.global = global;
264
+ if (global.window = global, global.self = global, global.top = global, global.parent = global, global.global) global.global = global;
283
265
  // rewrite defaultView to reference the same global context
284
266
  if (global.document && global.document.defaultView) Object.defineProperty(global.document, "defaultView", {
285
267
  get: () => global,
286
268
  enumerable: true,
287
269
  configurable: true
288
270
  });
289
- skipKeys.forEach((k) => keys.add(k));
290
- return {
271
+ return skipKeys.forEach((k) => keys.add(k)), {
291
272
  keys,
292
273
  skipKeys,
293
274
  originals
@@ -296,13 +277,10 @@ function populateGlobal(global, win, options = {}) {
296
277
 
297
278
  var edge = {
298
279
  name: "edge-runtime",
299
- transformMode: "ssr",
280
+ viteEnvironment: "ssr",
300
281
  async setupVM() {
301
- const { EdgeVM } = await import('@edge-runtime/vm');
302
- const vm = new EdgeVM({ extend: (context) => {
303
- context.global = context;
304
- context.Buffer = Buffer;
305
- return context;
282
+ const { EdgeVM } = await import('@edge-runtime/vm'), vm = new EdgeVM({ extend: (context) => {
283
+ return context.global = context, context.Buffer = Buffer, context;
306
284
  } });
307
285
  return {
308
286
  getVmContext() {
@@ -314,32 +292,24 @@ var edge = {
314
292
  };
315
293
  },
316
294
  async setup(global) {
317
- const { EdgeVM } = await import('@edge-runtime/vm');
318
- const vm = new EdgeVM({ extend: (context) => {
319
- context.global = context;
320
- context.Buffer = Buffer;
321
- KEYS.forEach((key) => {
295
+ const { EdgeVM } = await import('@edge-runtime/vm'), vm = new EdgeVM({ extend: (context) => {
296
+ return context.global = context, context.Buffer = Buffer, KEYS.forEach((key) => {
322
297
  if (key in global) context[key] = global[key];
323
- });
324
- return context;
325
- } });
326
- const { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
298
+ }), context;
299
+ } }), { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
327
300
  return { teardown(global) {
328
- keys.forEach((key) => delete global[key]);
329
- originals.forEach((v, k) => global[k] = v);
301
+ keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
330
302
  } };
331
303
  }
332
304
  };
333
305
 
334
306
  async function teardownWindow(win) {
335
- if (win.close && win.happyDOM.abort) {
336
- await win.happyDOM.abort();
337
- win.close();
338
- } else win.happyDOM.cancelAsync();
307
+ if (win.close && win.happyDOM.abort) await win.happyDOM.abort(), win.close();
308
+ else win.happyDOM.cancelAsync();
339
309
  }
340
310
  var happy = {
341
311
  name: "happy-dom",
342
- transformMode: "web",
312
+ viteEnvironment: "client",
343
313
  async setupVM({ happyDOM = {} }) {
344
314
  const { Window } = await import('happy-dom');
345
315
  let win = new Window({
@@ -351,25 +321,21 @@ var happy = {
351
321
  disableErrorCapturing: true
352
322
  }
353
323
  });
354
- // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
355
- win.Buffer = Buffer;
356
324
  // inject structuredClone if it exists
357
- if (typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
325
+ if (win.Buffer = Buffer, typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
358
326
  return {
359
327
  getVmContext() {
360
328
  return win;
361
329
  },
362
330
  async teardown() {
363
- await teardownWindow(win);
364
- win = void 0;
331
+ await teardownWindow(win), win = void 0;
365
332
  }
366
333
  };
367
334
  },
368
335
  async setup(global, { happyDOM = {} }) {
369
336
  // happy-dom v3 introduced a breaking change to Window, but
370
337
  // provides GlobalWindow as a way to use previous behaviour
371
- const { Window, GlobalWindow } = await import('happy-dom');
372
- const win = new (GlobalWindow || Window)({
338
+ const { Window, GlobalWindow } = await import('happy-dom'), win = new (GlobalWindow || Window)({
373
339
  ...happyDOM,
374
340
  console: console && global.console ? global.console : void 0,
375
341
  url: happyDOM.url || "http://localhost:3000",
@@ -377,8 +343,7 @@ var happy = {
377
343
  ...happyDOM.settings,
378
344
  disableErrorCapturing: true
379
345
  }
380
- });
381
- const { keys, originals } = populateGlobal(global, win, {
346
+ }), { keys, originals } = populateGlobal(global, win, {
382
347
  bindFunctions: true,
383
348
  additionalKeys: [
384
349
  "Request",
@@ -388,9 +353,7 @@ var happy = {
388
353
  ]
389
354
  });
390
355
  return { async teardown(global) {
391
- await teardownWindow(win);
392
- keys.forEach((key) => delete global[key]);
393
- originals.forEach((v, k) => global[k] = v);
356
+ await teardownWindow(win), keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
394
357
  } };
395
358
  }
396
359
  };
@@ -400,27 +363,22 @@ function catchWindowErrors(window) {
400
363
  function throwUnhandlerError(e) {
401
364
  if (userErrorListenerCount === 0 && e.error != null) process.emit("uncaughtException", e.error);
402
365
  }
403
- const addEventListener = window.addEventListener.bind(window);
404
- const removeEventListener = window.removeEventListener.bind(window);
405
- window.addEventListener("error", throwUnhandlerError);
406
- window.addEventListener = function(...args) {
366
+ const addEventListener = window.addEventListener.bind(window), removeEventListener = window.removeEventListener.bind(window);
367
+ return window.addEventListener("error", throwUnhandlerError), window.addEventListener = function(...args) {
407
368
  if (args[0] === "error") userErrorListenerCount++;
408
369
  return addEventListener.apply(this, args);
409
- };
410
- window.removeEventListener = function(...args) {
370
+ }, window.removeEventListener = function(...args) {
411
371
  if (args[0] === "error" && userErrorListenerCount) userErrorListenerCount--;
412
372
  return removeEventListener.apply(this, args);
413
- };
414
- return function clearErrorHandlers() {
373
+ }, function clearErrorHandlers() {
415
374
  window.removeEventListener("error", throwUnhandlerError);
416
375
  };
417
376
  }
418
377
  var jsdom = {
419
378
  name: "jsdom",
420
- transformMode: "web",
379
+ viteEnvironment: "client",
421
380
  async setupVM({ jsdom = {} }) {
422
- const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
423
- const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
381
+ const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom'), { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
424
382
  let dom = new JSDOM(html, {
425
383
  pretendToBeVisual,
426
384
  resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
@@ -434,16 +392,11 @@ var jsdom = {
434
392
  ...restOptions
435
393
  });
436
394
  const clearWindowErrors = catchWindowErrors(dom.window);
437
- // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
438
- dom.window.Buffer = Buffer;
439
- dom.window.jsdom = dom;
395
+ dom.window.Buffer = Buffer, dom.window.jsdom = dom;
440
396
  // inject web globals if they missing in JSDOM but otherwise available in Nodejs
441
397
  // https://nodejs.org/dist/latest/docs/api/globals.html
442
398
  const globalNames = [
443
399
  "structuredClone",
444
- "fetch",
445
- "Request",
446
- "Response",
447
400
  "BroadcastChannel",
448
401
  "MessageChannel",
449
402
  "MessagePort",
@@ -454,21 +407,33 @@ var jsdom = {
454
407
  const value = globalThis[name];
455
408
  if (typeof value !== "undefined" && typeof dom.window[name] === "undefined") dom.window[name] = value;
456
409
  }
410
+ // since we are providing Node.js's Fetch API,
411
+ // we also should override other APIs they use
412
+ const overrideGlobals = [
413
+ "fetch",
414
+ "Request",
415
+ "Response",
416
+ "Headers",
417
+ "AbortController",
418
+ "AbortSignal",
419
+ "URL",
420
+ "URLSearchParams"
421
+ ];
422
+ for (const name of overrideGlobals) {
423
+ const value = globalThis[name];
424
+ if (typeof value !== "undefined") dom.window[name] = value;
425
+ }
457
426
  return {
458
427
  getVmContext() {
459
428
  return dom.getInternalVMContext();
460
429
  },
461
430
  teardown() {
462
- clearWindowErrors();
463
- dom.window.close();
464
- dom = void 0;
431
+ clearWindowErrors(), dom.window.close(), dom = void 0;
465
432
  }
466
433
  };
467
434
  },
468
435
  async setup(global, { jsdom = {} }) {
469
- const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
470
- const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
471
- const dom = new JSDOM(html, {
436
+ const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom'), { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom, dom = new JSDOM(html, {
472
437
  pretendToBeVisual,
473
438
  resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
474
439
  runScripts,
@@ -479,16 +444,9 @@ var jsdom = {
479
444
  contentType,
480
445
  userAgent,
481
446
  ...restOptions
482
- });
483
- const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
484
- const clearWindowErrors = catchWindowErrors(global);
485
- global.jsdom = dom;
486
- return { teardown(global) {
487
- clearWindowErrors();
488
- dom.window.close();
489
- delete global.jsdom;
490
- keys.forEach((key) => delete global[key]);
491
- originals.forEach((v, k) => global[k] = v);
447
+ }), { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true }), clearWindowErrors = catchWindowErrors(global);
448
+ return global.jsdom = dom, { teardown(global) {
449
+ clearWindowErrors(), dom.window.close(), delete global.jsdom, keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
492
450
  } };
493
451
  }
494
452
  };
@@ -501,19 +459,26 @@ const denyList = new Set([
501
459
  "Buffer",
502
460
  "ArrayBuffer",
503
461
  "Uint8Array"
504
- ]);
505
- const nodeGlobals = new Map(Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
506
- const descriptor = Object.getOwnPropertyDescriptor(globalThis, nodeGlobalsKey);
507
- if (!descriptor) throw new Error(`No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`);
508
- return [nodeGlobalsKey, descriptor];
509
- }));
462
+ ]), nodeGlobals = /* @__PURE__ */ new Map();
463
+ function populateNodeGlobals() {
464
+ if (nodeGlobals.size !== 0) return;
465
+ const names = Object.getOwnPropertyNames(globalThis), length = names.length;
466
+ for (let i = 0; i < length; i++) {
467
+ const globalName = names[i];
468
+ if (!denyList.has(globalName)) {
469
+ const descriptor = Object.getOwnPropertyDescriptor(globalThis, globalName);
470
+ if (!descriptor) throw new Error(`No property descriptor for ${globalName}, this is a bug in Vitest.`);
471
+ nodeGlobals.set(globalName, descriptor);
472
+ }
473
+ }
474
+ }
510
475
  var node = {
511
476
  name: "node",
512
- transformMode: "ssr",
477
+ viteEnvironment: "ssr",
513
478
  async setupVM() {
479
+ populateNodeGlobals();
514
480
  const vm = await import('node:vm');
515
- let context = vm.createContext();
516
- let global = vm.runInContext("this", context);
481
+ let context = vm.createContext(), global = vm.runInContext("this", context);
517
482
  const contextGlobals = new Set(Object.getOwnPropertyNames(global));
518
483
  for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
519
484
  configurable: true,
@@ -521,14 +486,12 @@ var node = {
521
486
  get() {
522
487
  // @ts-expect-error: no index signature
523
488
  const val = globalThis[nodeGlobalsKey];
524
- // override lazy getter
525
- Object.defineProperty(global, nodeGlobalsKey, {
489
+ return Object.defineProperty(global, nodeGlobalsKey, {
526
490
  configurable: true,
527
491
  enumerable: descriptor.enumerable,
528
492
  value: val,
529
493
  writable: descriptor.writable === true || nodeGlobalsKey === "performance"
530
- });
531
- return val;
494
+ }), val;
532
495
  },
533
496
  set(val) {
534
497
  // override lazy getter
@@ -552,26 +515,17 @@ var node = {
552
515
  get: descriptor.get,
553
516
  set: descriptor.set
554
517
  });
555
- global.global = global;
556
- global.Buffer = Buffer;
557
- global.ArrayBuffer = ArrayBuffer;
558
- // TextEncoder (global or via 'util') references a Uint8Array constructor
559
- // different than the global one used by users in tests. This makes sure the
560
- // same constructor is referenced by both.
561
- global.Uint8Array = Uint8Array;
562
- return {
518
+ return global.global = global, global.Buffer = Buffer, global.ArrayBuffer = ArrayBuffer, global.Uint8Array = Uint8Array, {
563
519
  getVmContext() {
564
520
  return context;
565
521
  },
566
522
  teardown() {
567
- context = void 0;
568
- global = void 0;
523
+ context = void 0, global = void 0;
569
524
  }
570
525
  };
571
526
  },
572
527
  async setup(global) {
573
- global.console.Console = Console;
574
- return { teardown(global) {
528
+ return global.console.Console = Console, { teardown(global) {
575
529
  delete global.console.Console;
576
530
  } };
577
531
  }
@@ -2,55 +2,40 @@ import { createRequire } from 'node:module';
2
2
  import { pathToFileURL } from 'node:url';
3
3
 
4
4
  const __require = createRequire(import.meta.url);
5
- let inspector;
6
- let session;
5
+ let inspector, session;
7
6
  /**
8
7
  * Enables debugging inside `worker_threads` and `child_process`.
9
8
  * Should be called as early as possible when worker/process has been set up.
10
9
  */
11
10
  function setupInspect(ctx) {
12
- const config = ctx.config;
13
- const isEnabled = config.inspector.enabled;
11
+ const config = ctx.config, isEnabled = config.inspector.enabled;
14
12
  if (isEnabled) {
15
13
  inspector = __require("node:inspector");
16
14
  // Inspector may be open already if "isolate: false" is used
17
15
  const isOpen = inspector.url() !== void 0;
18
16
  if (!isOpen) {
19
- inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger);
20
- if (config.inspectBrk) {
17
+ if (inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger), config.inspectBrk) {
21
18
  const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
22
19
  // Stop at first test file
23
- if (firstTestFile) {
24
- session = new inspector.Session();
25
- session.connect();
26
- session.post("Debugger.enable");
27
- session.post("Debugger.setBreakpointByUrl", {
28
- lineNumber: 0,
29
- url: pathToFileURL(firstTestFile)
30
- });
31
- }
20
+ if (firstTestFile) session = new inspector.Session(), session.connect(), session.post("Debugger.enable"), session.post("Debugger.setBreakpointByUrl", {
21
+ lineNumber: 0,
22
+ url: pathToFileURL(firstTestFile)
23
+ });
32
24
  }
33
25
  }
34
26
  }
35
27
  const keepOpen = shouldKeepOpen(config);
36
28
  return function cleanup() {
37
- if (isEnabled && !keepOpen && inspector) {
38
- inspector.close();
39
- session?.disconnect();
40
- }
29
+ if (isEnabled && !keepOpen && inspector) inspector.close(), session?.disconnect();
41
30
  };
42
31
  }
43
32
  function closeInspector(config) {
44
33
  const keepOpen = shouldKeepOpen(config);
45
- if (inspector && !keepOpen) {
46
- inspector.close();
47
- session?.disconnect();
48
- }
34
+ if (inspector && !keepOpen) inspector.close(), session?.disconnect();
49
35
  }
50
36
  function shouldKeepOpen(config) {
51
37
  // In watch mode the inspector can persist re-runs if isolation is disabled and a single worker is used
52
- const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread;
53
- const isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
38
+ const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread, isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
54
39
  return config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
55
40
  }
56
41
 
@@ -0,0 +1,201 @@
1
+ import * as _vitest_spy from '@vitest/spy';
2
+ import vm from 'node:vm';
3
+ import * as viteModuleRunner from 'vite/module-runner';
4
+ import { ModuleEvaluator, ModuleRunnerImportMeta, ModuleRunnerContext, EvaluatedModuleNode, FetchFunction, EvaluatedModules } from 'vite/module-runner';
5
+ import { a as RuntimeRPC, W as WorkerGlobalState } from './worker.d.B_Fd9M_w.js';
6
+ import { R as ResolveFunctionResult } from './environment.d.BsToaxti.js';
7
+ import { MockedModule, MockedModuleType } from '@vitest/mocker';
8
+ import { P as PendingSuiteMock, b as MockFactory, a as MockOptions } from './mocker.d.BE_2ls6u.js';
9
+
10
+ declare class FileMap {
11
+ private fsCache;
12
+ private fsBufferCache;
13
+ readFileAsync(path: string): Promise<string>;
14
+ readFile(path: string): string;
15
+ readBuffer(path: string): Buffer<ArrayBuffer>;
16
+ }
17
+
18
+ interface ModuleEvaluateOptions {
19
+ timeout?: vm.RunningScriptOptions["timeout"] | undefined;
20
+ breakOnSigint?: vm.RunningScriptOptions["breakOnSigint"] | undefined;
21
+ }
22
+ type ModuleLinker = (specifier: string, referencingModule: VMModule, extra: {
23
+ assert: object;
24
+ }) => VMModule | Promise<VMModule>;
25
+ type ModuleStatus = "unlinked" | "linking" | "linked" | "evaluating" | "evaluated" | "errored";
26
+ declare class VMModule {
27
+ dependencySpecifiers: readonly string[];
28
+ error: any;
29
+ identifier: string;
30
+ context: vm.Context;
31
+ namespace: object;
32
+ status: ModuleStatus;
33
+ evaluate(options?: ModuleEvaluateOptions): Promise<void>;
34
+ link(linker: ModuleLinker): Promise<void>;
35
+ }
36
+
37
+ interface ExternalModulesExecutorOptions {
38
+ context: vm.Context;
39
+ fileMap: FileMap;
40
+ packageCache: Map<string, any>;
41
+ transform: RuntimeRPC["transform"];
42
+ interopDefault?: boolean;
43
+ viteClientModule: Record<string, unknown>;
44
+ }
45
+ declare class ExternalModulesExecutor {
46
+ #private;
47
+ private options;
48
+ private cjs;
49
+ private esm;
50
+ private vite;
51
+ private context;
52
+ private fs;
53
+ private resolvers;
54
+ constructor(options: ExternalModulesExecutorOptions);
55
+ import(identifier: string): Promise<object>;
56
+ require(identifier: string): any;
57
+ createRequire(identifier: string): NodeJS.Require;
58
+ importModuleDynamically: (specifier: string, referencer: VMModule) => Promise<VMModule>;
59
+ resolveModule: (specifier: string, referencer: string) => Promise<VMModule>;
60
+ resolve(specifier: string, parent: string): string;
61
+ private getModuleInformation;
62
+ private createModule;
63
+ private get isNetworkSupported();
64
+ }
65
+
66
+ type ModuleExecutionInfo = Map<string, ModuleExecutionInfoEntry>;
67
+ interface ModuleExecutionInfoEntry {
68
+ startOffset: number;
69
+ /** The duration that was spent executing the module. */
70
+ duration: number;
71
+ /** The time that was spent executing the module itself and externalized imports. */
72
+ selfTime: number;
73
+ }
74
+
75
+ interface VitestModuleEvaluatorOptions {
76
+ interopDefault?: boolean | undefined;
77
+ moduleExecutionInfo?: ModuleExecutionInfo;
78
+ getCurrentTestFilepath?: () => string | undefined;
79
+ compiledFunctionArgumentsNames?: string[];
80
+ compiledFunctionArgumentsValues?: unknown[];
81
+ }
82
+ declare class VitestModuleEvaluator implements ModuleEvaluator {
83
+ private options;
84
+ stubs: Record<string, any>;
85
+ env: ModuleRunnerImportMeta["env"];
86
+ private vm;
87
+ private compiledFunctionArgumentsNames?;
88
+ private compiledFunctionArgumentsValues;
89
+ private primitives;
90
+ private debug;
91
+ constructor(vmOptions?: VitestVmOptions | undefined, options?: VitestModuleEvaluatorOptions);
92
+ private convertIdToImportUrl;
93
+ runExternalModule(id: string): Promise<any>;
94
+ runInlinedModule(context: ModuleRunnerContext, code: string, module: Readonly<EvaluatedModuleNode>): Promise<any>;
95
+ private createRequire;
96
+ private shouldInterop;
97
+ }
98
+ declare function createImportMetaEnvProxy(): ModuleRunnerImportMeta["env"];
99
+ declare function getDefaultRequestStubs(context?: vm.Context): Record<string, any>;
100
+ declare function isPrimitive(v: any): boolean;
101
+ declare function wrapId(id: string): string;
102
+ declare function unwrapId(id: string): string;
103
+
104
+ interface VitestTransportOptions {
105
+ fetchModule: FetchFunction;
106
+ resolveId: (id: string, importer?: string) => Promise<ResolveFunctionResult | null>;
107
+ }
108
+
109
+ interface MockContext {
110
+ /**
111
+ * When mocking with a factory, this refers to the module that imported the mock.
112
+ */
113
+ callstack: null | string[];
114
+ }
115
+ interface VitestMockerOptions {
116
+ context?: vm.Context;
117
+ spyModule?: typeof _vitest_spy;
118
+ root: string;
119
+ moduleDirectories: string[];
120
+ resolveId: (id: string, importer?: string) => Promise<{
121
+ id: string;
122
+ file: string;
123
+ url: string;
124
+ } | null>;
125
+ getCurrentTestFilepath: () => string | undefined;
126
+ }
127
+ declare class VitestMocker {
128
+ moduleRunner: VitestModuleRunner;
129
+ private options;
130
+ static pendingIds: PendingSuiteMock[];
131
+ private spyModule?;
132
+ private primitives;
133
+ private filterPublicKeys;
134
+ private registries;
135
+ private mockContext;
136
+ constructor(moduleRunner: VitestModuleRunner, options: VitestMockerOptions);
137
+ private get root();
138
+ private get evaluatedModules();
139
+ private get moduleDirectories();
140
+ initializeSpyModule(): Promise<void>;
141
+ private getMockerRegistry;
142
+ reset(): void;
143
+ private invalidateModuleById;
144
+ private isModuleDirectory;
145
+ getSuiteFilepath(): string;
146
+ private createError;
147
+ resolveId(rawId: string, importer?: string): Promise<{
148
+ id: string;
149
+ url: string;
150
+ external: string | null;
151
+ }>;
152
+ resolveMocks(): Promise<void>;
153
+ private ensureModule;
154
+ private callFunctionMock;
155
+ getMockContext(): MockContext;
156
+ getMockPath(dep: string): string;
157
+ getDependencyMock(id: string): MockedModule | undefined;
158
+ findMockRedirect(mockPath: string, external: string | null): string | null;
159
+ mockObject(object: Record<string | symbol, any>, mockExports?: Record<string | symbol, any>, behavior?: "automock" | "autospy"): Record<string | symbol, any>;
160
+ unmockPath(id: string): void;
161
+ mockPath(originalId: string, id: string, url: string, external: string | null, mockType: MockedModuleType | undefined, factory: MockFactory | undefined): void;
162
+ importActual<T>(rawId: string, importer: string, callstack?: string[] | null): Promise<T>;
163
+ importMock(rawId: string, importer: string): Promise<any>;
164
+ requestWithMockedModule(url: string, evaluatedNode: EvaluatedModuleNode, callstack: string[], mock: MockedModule): Promise<any>;
165
+ mockedRequest(url: string, evaluatedNode: EvaluatedModuleNode, callstack: string[]): Promise<any>;
166
+ queueMock(id: string, importer: string, factoryOrOptions?: MockFactory | MockOptions): void;
167
+ queueUnmock(id: string, importer: string): void;
168
+ }
169
+ declare module "vite/module-runner" {
170
+ interface EvaluatedModuleNode {
171
+ mockedExports?: Record<string, any>;
172
+ }
173
+ }
174
+
175
+ type CreateImportMeta = NonNullable<viteModuleRunner.ModuleRunnerOptions["createImportMeta"]>;
176
+ declare class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
177
+ private vitestOptions;
178
+ mocker: VitestMocker;
179
+ moduleExecutionInfo: ModuleExecutionInfo;
180
+ constructor(vitestOptions: VitestModuleRunnerOptions);
181
+ import(rawId: string): Promise<any>;
182
+ fetchModule(url: string, importer?: string): Promise<EvaluatedModuleNode>;
183
+ private _cachedRequest;
184
+ }
185
+ interface VitestModuleRunnerOptions {
186
+ transport: VitestTransportOptions;
187
+ evaluator: VitestModuleEvaluator;
188
+ evaluatedModules: EvaluatedModules;
189
+ getWorkerState: () => WorkerGlobalState;
190
+ mocker?: VitestMocker;
191
+ vm?: VitestVmOptions;
192
+ spyModule?: typeof _vitest_spy;
193
+ createImportMeta?: CreateImportMeta;
194
+ }
195
+ interface VitestVmOptions {
196
+ context: vm.Context;
197
+ externalModulesExecutor: ExternalModulesExecutor;
198
+ }
199
+
200
+ export { VitestModuleRunner as V, VitestModuleEvaluator as b, createImportMetaEnvProxy as c, getDefaultRequestStubs as g, isPrimitive as i, unwrapId as u, wrapId as w };
201
+ export type { VitestModuleEvaluatorOptions as a };
@@ -1,6 +1,6 @@
1
1
  import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
2
- import { g as getWorkerState } from './utils.XdZDrNZV.js';
3
- import '@vitest/utils';
2
+ import { g as getWorkerState } from './utils.DGKhod2J.js';
3
+ import '@vitest/utils/timers';
4
4
 
5
5
  class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
6
6
  getHeader() {
@@ -1,4 +1,4 @@
1
- import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.DxZg19fy.js';
1
+ import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.CVzhsTvK.js';
2
2
 
3
3
  interface VitestPluginContext {
4
4
  vitest: Vitest;