vitest 4.0.6 → 4.0.8

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 (65) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +2 -2
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/base.BgTO2qAg.js +156 -0
  5. package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
  6. package/dist/chunks/{browser.d.ScGeWTou.d.ts → browser.d.DTTM2PTh.d.ts} +1 -1
  7. package/dist/chunks/{cac.BBqWH4nd.js → cac.CfkWq8Qy.js} +117 -43
  8. package/dist/chunks/{cli-api.UL3SwFUb.js → cli-api.BQ-bjcRi.js} +1870 -847
  9. package/dist/chunks/console.Cf-YriPC.js +146 -0
  10. package/dist/chunks/{coverage.DuCn_Tmx.js → coverage.NVjCOln1.js} +281 -103
  11. package/dist/chunks/{creator.cqqifzG7.js → creator.fzVyoMf3.js} +74 -30
  12. package/dist/chunks/{date.-jtEtIeV.js → date.Bq6ZW5rf.js} +17 -6
  13. package/dist/chunks/{git.BFNcloKD.js → git.Bm2pzPAa.js} +3 -3
  14. package/dist/chunks/{global.d.DdOkMiVb.d.ts → global.d.DVdCfKp5.d.ts} +1 -1
  15. package/dist/chunks/{globals.BGT_RUsD.js → globals.DOh96BiR.js} +5 -5
  16. package/dist/chunks/{resolveSnapshotEnvironment.BZzLjzkh.js → index.BY4-tcno.js} +42 -25
  17. package/dist/chunks/{index.Bgo3tNWt.js → index.DAL392Ss.js} +40 -15
  18. package/dist/chunks/{index.RwjEGCQ0.js → index.DIFZf73e.js} +2 -2
  19. package/dist/chunks/{index.DV0mQLEO.js → index.DfKyPFVi.js} +195 -64
  20. package/dist/chunks/{index.BL8Hg4Uk.js → index.kotH7DY7.js} +837 -380
  21. package/dist/chunks/{index.CpdwpN7L.js → index.op2Re5rn.js} +22 -12
  22. package/dist/chunks/{init-forks.CSGFj9zN.js → init-forks.2hx7cf78.js} +16 -5
  23. package/dist/chunks/{init-threads.CIJLeFO8.js → init-threads.Cm4OCIWA.js} +3 -2
  24. package/dist/chunks/{init.DUeOfNO9.js → init.DMDG-idf.js} +124 -54
  25. package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
  26. package/dist/chunks/{moduleRunner.d.TP-w6tIQ.d.ts → moduleRunner.d.CzOZ_4wC.d.ts} +1 -1
  27. package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
  28. package/dist/chunks/{plugin.d.lctzD3Wk.d.ts → plugin.d.D4RrtywJ.d.ts} +1 -1
  29. package/dist/chunks/{reporters.d.PEs0tXod.d.ts → reporters.d.Da1D1VbQ.d.ts} +19 -9
  30. package/dist/chunks/rpc.BUV7uWKJ.js +76 -0
  31. package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.LGjNSzXp.js} +20 -8
  32. package/dist/chunks/{startModuleRunner.Di-EZqh0.js → startModuleRunner.BOmUtLIO.js} +228 -105
  33. package/dist/chunks/{test.CnspO-X4.js → test.ClrAtjMv.js} +48 -22
  34. package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
  35. package/dist/chunks/{vi.BZvkKVkM.js → vi.Bgcdy3bQ.js} +261 -111
  36. package/dist/chunks/{vm.Co_lR2NL.js → vm.BIkCDs68.js} +177 -70
  37. package/dist/chunks/{worker.d.B4Hthdvt.d.ts → worker.d.DadbA89M.d.ts} +52 -6
  38. package/dist/cli.js +2 -2
  39. package/dist/config.d.ts +5 -5
  40. package/dist/coverage.d.ts +3 -3
  41. package/dist/coverage.js +1 -1
  42. package/dist/environments.js +2 -1
  43. package/dist/index.d.ts +5 -5
  44. package/dist/index.js +5 -5
  45. package/dist/module-evaluator.d.ts +2 -2
  46. package/dist/module-evaluator.js +85 -35
  47. package/dist/module-runner.js +2 -2
  48. package/dist/node.d.ts +7 -7
  49. package/dist/node.js +16 -12
  50. package/dist/reporters.d.ts +3 -3
  51. package/dist/reporters.js +2 -2
  52. package/dist/runners.js +7 -7
  53. package/dist/snapshot.js +2 -2
  54. package/dist/suite.js +2 -2
  55. package/dist/worker.d.ts +2 -1
  56. package/dist/worker.js +27 -27
  57. package/dist/workers/forks.js +34 -31
  58. package/dist/workers/runVmTests.js +41 -22
  59. package/dist/workers/threads.js +34 -31
  60. package/dist/workers/vmForks.js +14 -14
  61. package/dist/workers/vmThreads.js +14 -14
  62. package/package.json +20 -20
  63. package/dist/chunks/base.BAf_bYeI.js +0 -128
  64. package/dist/chunks/console.CTJL2nuH.js +0 -115
  65. package/dist/chunks/rpc.Dv1Jt3i2.js +0 -66
@@ -1,3 +1,4 @@
1
+ import { URL } from 'node:url';
1
2
  import { Console } from 'node:console';
2
3
 
3
4
  // SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
@@ -136,6 +137,7 @@ const LIVING_KEYS = [
136
137
  "Plugin",
137
138
  "MimeType",
138
139
  "FileReader",
140
+ "FormData",
139
141
  "Blob",
140
142
  "File",
141
143
  "FileList",
@@ -174,7 +176,8 @@ const LIVING_KEYS = [
174
176
  "Audio",
175
177
  "Option",
176
178
  "CSS"
177
- ], OTHER_KEYS = [
179
+ ];
180
+ const OTHER_KEYS = [
178
181
  "addEventListener",
179
182
  "alert",
180
183
  "blur",
@@ -239,20 +242,28 @@ const skipKeys = [
239
242
  function getWindowKeys(global, win, additionalKeys = []) {
240
243
  const keysArray = [...additionalKeys, ...KEYS];
241
244
  return new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
242
- return skipKeys.includes(k) ? false : k in global ? keysArray.includes(k) : true;
245
+ if (skipKeys.includes(k)) return false;
246
+ if (k in global) return keysArray.includes(k);
247
+ return true;
243
248
  }));
244
249
  }
245
250
  function isClassLikeName(name) {
246
251
  return name[0] === name[0].toUpperCase();
247
252
  }
248
253
  function populateGlobal(global, win, options = {}) {
249
- const { bindFunctions = false } = options, keys = getWindowKeys(global, win, options.additionalKeys), originals = /* @__PURE__ */ new Map(), overridenKeys = new Set([...KEYS, ...options.additionalKeys || []]), overrideObject = /* @__PURE__ */ new Map();
254
+ const { bindFunctions = false } = options;
255
+ const keys = getWindowKeys(global, win, options.additionalKeys);
256
+ const originals = /* @__PURE__ */ new Map();
257
+ const overridenKeys = new Set([...KEYS, ...options.additionalKeys || []]);
258
+ const overrideObject = /* @__PURE__ */ new Map();
250
259
  for (const key of keys) {
251
260
  const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
252
261
  if (overridenKeys.has(key) && key in global) originals.set(key, global[key]);
253
262
  Object.defineProperty(global, key, {
254
263
  get() {
255
- return overrideObject.has(key) ? overrideObject.get(key) : boundFunction || win[key];
264
+ if (overrideObject.has(key)) return overrideObject.get(key);
265
+ if (boundFunction) return boundFunction;
266
+ return win[key];
256
267
  },
257
268
  set(v) {
258
269
  overrideObject.set(key, v);
@@ -260,14 +271,19 @@ function populateGlobal(global, win, options = {}) {
260
271
  configurable: true
261
272
  });
262
273
  }
263
- if (global.window = global, global.self = global, global.top = global, global.parent = global, global.global) global.global = global;
274
+ global.window = global;
275
+ global.self = global;
276
+ global.top = global;
277
+ global.parent = global;
278
+ if (global.global) global.global = global;
264
279
  // rewrite defaultView to reference the same global context
265
280
  if (global.document && global.document.defaultView) Object.defineProperty(global.document, "defaultView", {
266
281
  get: () => global,
267
282
  enumerable: true,
268
283
  configurable: true
269
284
  });
270
- return skipKeys.forEach((k) => keys.add(k)), {
285
+ skipKeys.forEach((k) => keys.add(k));
286
+ return {
271
287
  keys,
272
288
  skipKeys,
273
289
  originals
@@ -278,8 +294,11 @@ var edge = {
278
294
  name: "edge-runtime",
279
295
  viteEnvironment: "ssr",
280
296
  async setupVM() {
281
- const { EdgeVM } = await import('@edge-runtime/vm'), vm = new EdgeVM({ extend: (context) => {
282
- return context.global = context, context.Buffer = Buffer, context;
297
+ const { EdgeVM } = await import('@edge-runtime/vm');
298
+ const vm = new EdgeVM({ extend: (context) => {
299
+ context.global = context;
300
+ context.Buffer = Buffer;
301
+ return context;
283
302
  } });
284
303
  return {
285
304
  getVmContext() {
@@ -291,20 +310,27 @@ var edge = {
291
310
  };
292
311
  },
293
312
  async setup(global) {
294
- const { EdgeVM } = await import('@edge-runtime/vm'), vm = new EdgeVM({ extend: (context) => {
295
- return context.global = context, context.Buffer = Buffer, KEYS.forEach((key) => {
313
+ const { EdgeVM } = await import('@edge-runtime/vm');
314
+ const { keys, originals } = populateGlobal(global, new EdgeVM({ extend: (context) => {
315
+ context.global = context;
316
+ context.Buffer = Buffer;
317
+ KEYS.forEach((key) => {
296
318
  if (key in global) context[key] = global[key];
297
- }), context;
298
- } }), { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
319
+ });
320
+ return context;
321
+ } }).context, { bindFunctions: true });
299
322
  return { teardown(global) {
300
- keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
323
+ keys.forEach((key) => delete global[key]);
324
+ originals.forEach((v, k) => global[k] = v);
301
325
  } };
302
326
  }
303
327
  };
304
328
 
305
329
  async function teardownWindow(win) {
306
- if (win.close && win.happyDOM.abort) await win.happyDOM.abort(), win.close();
307
- else win.happyDOM.cancelAsync();
330
+ if (win.close && win.happyDOM.abort) {
331
+ await win.happyDOM.abort();
332
+ win.close();
333
+ } else win.happyDOM.cancelAsync();
308
334
  }
309
335
  var happy = {
310
336
  name: "happy-dom",
@@ -320,21 +346,25 @@ var happy = {
320
346
  disableErrorCapturing: true
321
347
  }
322
348
  });
349
+ // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
350
+ win.Buffer = Buffer;
323
351
  // inject structuredClone if it exists
324
- if (win.Buffer = Buffer, typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
352
+ if (typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
325
353
  return {
326
354
  getVmContext() {
327
355
  return win;
328
356
  },
329
357
  async teardown() {
330
- await teardownWindow(win), win = void 0;
358
+ await teardownWindow(win);
359
+ win = void 0;
331
360
  }
332
361
  };
333
362
  },
334
363
  async setup(global, { happyDOM = {} }) {
335
364
  // happy-dom v3 introduced a breaking change to Window, but
336
365
  // provides GlobalWindow as a way to use previous behaviour
337
- const { Window, GlobalWindow } = await import('happy-dom'), win = new (GlobalWindow || Window)({
366
+ const { Window, GlobalWindow } = await import('happy-dom');
367
+ const win = new (GlobalWindow || Window)({
338
368
  ...happyDOM,
339
369
  console: console && global.console ? global.console : void 0,
340
370
  url: happyDOM.url || "http://localhost:3000",
@@ -342,7 +372,8 @@ var happy = {
342
372
  ...happyDOM.settings,
343
373
  disableErrorCapturing: true
344
374
  }
345
- }), { keys, originals } = populateGlobal(global, win, {
375
+ });
376
+ const { keys, originals } = populateGlobal(global, win, {
346
377
  bindFunctions: true,
347
378
  additionalKeys: [
348
379
  "Request",
@@ -358,7 +389,9 @@ var happy = {
358
389
  ]
359
390
  });
360
391
  return { async teardown(global) {
361
- await teardownWindow(win), keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
392
+ await teardownWindow(win);
393
+ keys.forEach((key) => delete global[key]);
394
+ originals.forEach((v, k) => global[k] = v);
362
395
  } };
363
396
  }
364
397
  };
@@ -366,41 +399,66 @@ var happy = {
366
399
  function catchWindowErrors(window) {
367
400
  let userErrorListenerCount = 0;
368
401
  function throwUnhandlerError(e) {
369
- if (userErrorListenerCount === 0 && e.error != null) process.emit("uncaughtException", e.error);
402
+ if (userErrorListenerCount === 0 && e.error != null) {
403
+ e.preventDefault();
404
+ process.emit("uncaughtException", e.error);
405
+ }
370
406
  }
371
- const addEventListener = window.addEventListener.bind(window), removeEventListener = window.removeEventListener.bind(window);
372
- return window.addEventListener("error", throwUnhandlerError), window.addEventListener = function(...args) {
407
+ const addEventListener = window.addEventListener.bind(window);
408
+ const removeEventListener = window.removeEventListener.bind(window);
409
+ window.addEventListener("error", throwUnhandlerError);
410
+ window.addEventListener = function(...args) {
373
411
  if (args[0] === "error") userErrorListenerCount++;
374
412
  return addEventListener.apply(this, args);
375
- }, window.removeEventListener = function(...args) {
413
+ };
414
+ window.removeEventListener = function(...args) {
376
415
  if (args[0] === "error" && userErrorListenerCount) userErrorListenerCount--;
377
416
  return removeEventListener.apply(this, args);
378
- }, function clearErrorHandlers() {
417
+ };
418
+ return function clearErrorHandlers() {
379
419
  window.removeEventListener("error", throwUnhandlerError);
380
420
  };
381
421
  }
382
- let _FormData;
422
+ let NodeFormData_;
423
+ let NodeBlob_;
424
+ let NodeRequest_;
383
425
  var jsdom = {
384
426
  name: "jsdom",
385
427
  viteEnvironment: "client",
386
428
  async setupVM({ jsdom = {} }) {
387
429
  // delay initialization because it takes ~1s
388
- _FormData = globalThis.FormData;
389
- 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;
430
+ NodeFormData_ = globalThis.FormData;
431
+ NodeBlob_ = globalThis.Blob;
432
+ NodeRequest_ = globalThis.Request;
433
+ const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
434
+ 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;
435
+ let virtualConsole;
436
+ if (console && globalThis.console) {
437
+ virtualConsole = new VirtualConsole();
438
+ // jsdom <27
439
+ if ("sendTo" in virtualConsole) virtualConsole.sendTo(globalThis.console);
440
+ else virtualConsole.forwardTo(globalThis.console);
441
+ }
390
442
  let dom = new JSDOM(html, {
391
443
  pretendToBeVisual,
392
444
  resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
393
445
  runScripts,
394
446
  url,
395
- virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : void 0,
447
+ virtualConsole,
396
448
  cookieJar: cookieJar ? new CookieJar() : void 0,
397
449
  includeNodeLocations,
398
450
  contentType,
399
451
  userAgent,
400
452
  ...restOptions
401
453
  });
402
- const clearAddEventListenerPatch = patchAddEventListener(dom.window), clearWindowErrors = catchWindowErrors(dom.window);
403
- dom.window.Buffer = Buffer, dom.window.jsdom = dom, dom.window.FormData = createFormData(dom.window);
454
+ const clearAddEventListenerPatch = patchAddEventListener(dom.window);
455
+ const clearWindowErrors = catchWindowErrors(dom.window);
456
+ const utils = createCompatUtils(dom.window);
457
+ // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
458
+ dom.window.Buffer = Buffer;
459
+ dom.window.jsdom = dom;
460
+ dom.window.Request = createCompatRequest(utils);
461
+ dom.window.URL = createJSDOMCompatURL(utils);
404
462
  for (const name of [
405
463
  "structuredClone",
406
464
  "BroadcastChannel",
@@ -414,12 +472,10 @@ var jsdom = {
414
472
  }
415
473
  for (const name of [
416
474
  "fetch",
417
- "Request",
418
475
  "Response",
419
476
  "Headers",
420
477
  "AbortController",
421
478
  "AbortSignal",
422
- "URL",
423
479
  "URLSearchParams"
424
480
  ]) {
425
481
  const value = globalThis[name];
@@ -430,48 +486,106 @@ var jsdom = {
430
486
  return dom.getInternalVMContext();
431
487
  },
432
488
  teardown() {
433
- clearAddEventListenerPatch(), clearWindowErrors(), dom.window.close(), dom = void 0;
489
+ clearAddEventListenerPatch();
490
+ clearWindowErrors();
491
+ dom.window.close();
492
+ dom = void 0;
434
493
  }
435
494
  };
436
495
  },
437
496
  async setup(global, { jsdom = {} }) {
438
497
  // delay initialization because it takes ~1s
439
- _FormData = globalThis.FormData;
440
- 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, {
498
+ NodeFormData_ = globalThis.FormData;
499
+ NodeBlob_ = globalThis.Blob;
500
+ NodeRequest_ = globalThis.Request;
501
+ const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
502
+ 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;
503
+ let virtualConsole;
504
+ if (console && globalThis.console) {
505
+ virtualConsole = new VirtualConsole();
506
+ // jsdom <27
507
+ if ("sendTo" in virtualConsole) virtualConsole.sendTo(globalThis.console);
508
+ else virtualConsole.forwardTo(globalThis.console);
509
+ }
510
+ const dom = new JSDOM(html, {
441
511
  pretendToBeVisual,
442
512
  resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
443
513
  runScripts,
444
514
  url,
445
- virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
515
+ virtualConsole,
446
516
  cookieJar: cookieJar ? new CookieJar() : void 0,
447
517
  includeNodeLocations,
448
518
  contentType,
449
519
  userAgent,
450
520
  ...restOptions
451
- }), clearAddEventListenerPatch = patchAddEventListener(dom.window), { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true }), clearWindowErrors = catchWindowErrors(global);
452
- return global.jsdom = dom, global.FormData = createFormData(dom.window), { teardown(global) {
453
- clearAddEventListenerPatch(), clearWindowErrors(), dom.window.close(), delete global.jsdom, keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
521
+ });
522
+ const clearAddEventListenerPatch = patchAddEventListener(dom.window);
523
+ const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
524
+ const clearWindowErrors = catchWindowErrors(global);
525
+ const utils = createCompatUtils(dom.window);
526
+ global.jsdom = dom;
527
+ global.Request = createCompatRequest(utils);
528
+ global.URL = createJSDOMCompatURL(utils);
529
+ return { teardown(global) {
530
+ clearAddEventListenerPatch();
531
+ clearWindowErrors();
532
+ dom.window.close();
533
+ delete global.jsdom;
534
+ keys.forEach((key) => delete global[key]);
535
+ originals.forEach((v, k) => global[k] = v);
454
536
  } };
455
537
  }
456
538
  };
457
- // Node.js 24 has a global FormData that Request accepts
458
- // FormData is not used anywhere else in JSDOM, so we can safely
459
- // override it with Node.js implementation, but keep the DOM behaviour
460
- // this is required because Request (and other fetch API)
461
- // are not implemented by JSDOM
462
- function createFormData(window) {
463
- const JSDOMFormData = window.FormData;
464
- return _FormData ? class FormData extends _FormData {
539
+ function createCompatRequest(utils) {
540
+ return class Request extends NodeRequest_ {
465
541
  constructor(...args) {
466
- super(), new JSDOMFormData(...args).forEach((value, key) => {
467
- this.append(key, value);
542
+ const [input, init] = args;
543
+ if (init?.body != null) {
544
+ const compatInit = { ...init };
545
+ if (init.body instanceof utils.window.Blob) compatInit.body = utils.makeCompatBlob(init.body);
546
+ if (init.body instanceof utils.window.FormData) compatInit.body = utils.makeCompatFormData(init.body);
547
+ super(input, compatInit);
548
+ } else super(...args);
549
+ }
550
+ };
551
+ }
552
+ function createJSDOMCompatURL(utils) {
553
+ return class URL$1 extends URL {
554
+ static createObjectURL(blob) {
555
+ if (blob instanceof utils.window.Blob) {
556
+ const compatBlob = utils.makeCompatBlob(blob);
557
+ return URL.createObjectURL(compatBlob);
558
+ }
559
+ return URL.createObjectURL(blob);
560
+ }
561
+ };
562
+ }
563
+ function createCompatUtils(window) {
564
+ // this returns a hidden Symbol(impl)
565
+ // this is cursed, and jsdom should just implement fetch API itself
566
+ const implSymbol = Object.getOwnPropertySymbols(Object.getOwnPropertyDescriptors(new window.Blob()))[0];
567
+ const utils = {
568
+ window,
569
+ makeCompatFormData(formData) {
570
+ const nodeFormData = new NodeFormData_();
571
+ formData.forEach((value, key) => {
572
+ if (value instanceof window.Blob) nodeFormData.append(key, utils.makeCompatBlob(value));
573
+ else nodeFormData.append(key, value);
468
574
  });
575
+ return nodeFormData;
576
+ },
577
+ makeCompatBlob(blob) {
578
+ const buffer = blob[implSymbol]._buffer;
579
+ return new NodeBlob_([buffer], { type: blob.type });
469
580
  }
470
- } : JSDOMFormData;
581
+ };
582
+ return utils;
471
583
  }
472
584
  function patchAddEventListener(window) {
473
- const JSDOMAbortSignal = window.AbortSignal, JSDOMAbortController = window.AbortController, originalAddEventListener = window.EventTarget.prototype.addEventListener;
474
- return window.EventTarget.prototype.addEventListener = function addEventListener(type, callback, options) {
585
+ const JSDOMAbortSignal = window.AbortSignal;
586
+ const JSDOMAbortController = window.AbortController;
587
+ const originalAddEventListener = window.EventTarget.prototype.addEventListener;
588
+ window.EventTarget.prototype.addEventListener = function addEventListener(type, callback, options) {
475
589
  if (typeof options === "object" && options.signal != null) {
476
590
  const { signal,...otherOptions } = options;
477
591
  // - this happens because AbortSignal is provided by Node.js,
@@ -484,13 +598,16 @@ function patchAddEventListener(window) {
484
598
  // use jsdom-native abort controller instead and forward the
485
599
  // previous one with `addEventListener`
486
600
  const jsdomAbortController = new JSDOMAbortController();
487
- return signal.addEventListener("abort", () => {
601
+ signal.addEventListener("abort", () => {
488
602
  jsdomAbortController.abort(signal.reason);
489
- }), jsdomCompatOptions.signal = jsdomAbortController.signal, originalAddEventListener.call(this, type, callback, jsdomCompatOptions);
603
+ });
604
+ jsdomCompatOptions.signal = jsdomAbortController.signal;
605
+ return originalAddEventListener.call(this, type, callback, jsdomCompatOptions);
490
606
  }
491
607
  }
492
608
  return originalAddEventListener.call(this, type, callback, options);
493
- }, () => {
609
+ };
610
+ return () => {
494
611
  window.EventTarget.prototype.addEventListener = originalAddEventListener;
495
612
  };
496
613
  }
@@ -503,10 +620,12 @@ const denyList = new Set([
503
620
  "Buffer",
504
621
  "ArrayBuffer",
505
622
  "Uint8Array"
506
- ]), nodeGlobals = /* @__PURE__ */ new Map();
623
+ ]);
624
+ const nodeGlobals = /* @__PURE__ */ new Map();
507
625
  function populateNodeGlobals() {
508
626
  if (nodeGlobals.size !== 0) return;
509
- const names = Object.getOwnPropertyNames(globalThis), length = names.length;
627
+ const names = Object.getOwnPropertyNames(globalThis);
628
+ const length = names.length;
510
629
  for (let i = 0; i < length; i++) {
511
630
  const globalName = names[i];
512
631
  if (!denyList.has(globalName)) {
@@ -522,7 +641,8 @@ var node = {
522
641
  async setupVM() {
523
642
  populateNodeGlobals();
524
643
  const vm = await import('node:vm');
525
- let context = vm.createContext(), global = vm.runInContext("this", context);
644
+ let context = vm.createContext();
645
+ let global = vm.runInContext("this", context);
526
646
  const contextGlobals = new Set(Object.getOwnPropertyNames(global));
527
647
  for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
528
648
  configurable: true,
@@ -530,12 +650,14 @@ var node = {
530
650
  get() {
531
651
  // @ts-expect-error: no index signature
532
652
  const val = globalThis[nodeGlobalsKey];
533
- return Object.defineProperty(global, nodeGlobalsKey, {
653
+ // override lazy getter
654
+ Object.defineProperty(global, nodeGlobalsKey, {
534
655
  configurable: true,
535
656
  enumerable: descriptor.enumerable,
536
657
  value: val,
537
658
  writable: descriptor.writable === true || nodeGlobalsKey === "performance"
538
- }), val;
659
+ });
660
+ return val;
539
661
  },
540
662
  set(val) {
541
663
  // override lazy getter
@@ -559,17 +681,26 @@ var node = {
559
681
  get: descriptor.get,
560
682
  set: descriptor.set
561
683
  });
562
- return global.global = global, global.Buffer = Buffer, global.ArrayBuffer = ArrayBuffer, global.Uint8Array = Uint8Array, {
684
+ global.global = global;
685
+ global.Buffer = Buffer;
686
+ global.ArrayBuffer = ArrayBuffer;
687
+ // TextEncoder (global or via 'util') references a Uint8Array constructor
688
+ // different than the global one used by users in tests. This makes sure the
689
+ // same constructor is referenced by both.
690
+ global.Uint8Array = Uint8Array;
691
+ return {
563
692
  getVmContext() {
564
693
  return context;
565
694
  },
566
695
  teardown() {
567
- context = void 0, global = void 0;
696
+ context = void 0;
697
+ global = void 0;
568
698
  }
569
699
  };
570
700
  },
571
701
  async setup(global) {
572
- return global.console.Console = Console, { teardown(global) {
702
+ global.console.Console = Console;
703
+ return { teardown(global) {
573
704
  delete global.console.Console;
574
705
  } };
575
706
  }