vitest 3.2.0-beta.2 → 3.2.0-beta.3

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 (67) hide show
  1. package/dist/browser.d.ts +3 -3
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{base.DwtwORaC.js → base.D4119yLM.js} +4 -3
  4. package/dist/chunks/{benchmark.BoF7jW0Q.js → benchmark.Cf_PACH1.js} +1 -1
  5. package/dist/chunks/{cac.I9MLYfT-.js → cac.DWaWHIIE.js} +18 -15
  6. package/dist/chunks/{cli-api.d6IK1pnk.js → cli-api.CnmEXkxs.js} +250 -49
  7. package/dist/chunks/{config.d.UqE-KR0o.d.ts → config.d.D2ROskhv.d.ts} +2 -0
  8. package/dist/chunks/{console.K1NMVOSc.js → console.Cwr-MFPV.js} +3 -2
  9. package/dist/chunks/{constants.BZZyIeIE.js → constants.DnKduX2e.js} +1 -0
  10. package/dist/chunks/{coverage.OGU09Jbh.js → coverage.C73DaDgS.js} +116 -12
  11. package/dist/chunks/{creator.DGAdZ4Hj.js → creator.C8WKy2eW.js} +10 -7
  12. package/dist/chunks/{date.CDOsz-HY.js → date.ByMsSlOr.js} +25 -0
  13. package/dist/chunks/{defaults.DSxsTG0h.js → defaults.DpVH7vbg.js} +1 -0
  14. package/dist/chunks/{environment.d.D8YDy2v5.d.ts → environment.d.cL3nLXbE.d.ts} +1 -0
  15. package/dist/chunks/{execute.JlGHLJZT.js → execute.B3q-2LPV.js} +25 -0
  16. package/dist/chunks/{global.d.BPa1eL3O.d.ts → global.d.BNLIi6yo.d.ts} +3 -1
  17. package/dist/chunks/{globals.CpxW8ccg.js → globals.CI21aWXF.js} +7 -6
  18. package/dist/chunks/{index.DFXFpH3w.js → index.2jgTs_Q5.js} +19 -1
  19. package/dist/chunks/{index.CV36oG_L.js → index.Bter3jj9.js} +83 -16
  20. package/dist/chunks/{index.DswW_LEs.js → index.CbT4iuwc.js} +7 -4
  21. package/dist/chunks/index.D3XRDfWc.js +213 -0
  22. package/dist/chunks/{index.CfXMNXHg.js → index.DNgLEKsQ.js} +4 -2
  23. package/dist/chunks/{index.CmC5OK9L.js → index.JOzufsrU.js} +2 -1
  24. package/dist/chunks/{inspector.DbDkSkFn.js → inspector.BFsh5KO0.js} +3 -0
  25. package/dist/chunks/{node.3xsWotC9.js → node.Be-ntJnD.js} +1 -1
  26. package/dist/chunks/{reporters.d.CLC9rhKy.d.ts → reporters.d.Bt4IGtsa.d.ts} +24 -6
  27. package/dist/chunks/{rpc.D9_013TY.js → rpc.BKExFSRG.js} +2 -1
  28. package/dist/chunks/{runBaseTests.Dn2vyej_.js → runBaseTests.B_M1TTsK.js} +19 -10
  29. package/dist/chunks/{setup-common.CYo3Y0dD.js → setup-common.CF-O-dZX.js} +2 -1
  30. package/dist/chunks/{typechecker.DnTrplSJ.js → typechecker.BgzF-6iO.js} +78 -21
  31. package/dist/chunks/{utils.CgTj3MsC.js → utils.BlI4TC7Y.js} +1 -0
  32. package/dist/chunks/{utils.BfxieIyZ.js → utils.DPCq3gzW.js} +3 -0
  33. package/dist/chunks/{vi.BFR5YIgu.js → vi.pkoYCV6A.js} +25 -2
  34. package/dist/chunks/{vite.d.CBZ3M_ru.d.ts → vite.d.B-Kx3KCF.d.ts} +3 -1
  35. package/dist/chunks/{vm.C1HHjtNS.js → vm.DPYem2so.js} +72 -4
  36. package/dist/chunks/{worker.d.CoCI7hzP.d.ts → worker.d.BKbBp2ga.d.ts} +2 -2
  37. package/dist/chunks/{worker.d.D5Xdi-Zr.d.ts → worker.d.Bl1O4kuf.d.ts} +1 -1
  38. package/dist/cli.js +4 -4
  39. package/dist/config.cjs +2 -0
  40. package/dist/config.d.ts +7 -6
  41. package/dist/config.js +2 -2
  42. package/dist/coverage.d.ts +4 -4
  43. package/dist/coverage.js +5 -5
  44. package/dist/environments.d.ts +6 -2
  45. package/dist/environments.js +1 -1
  46. package/dist/execute.d.ts +9 -3
  47. package/dist/execute.js +1 -1
  48. package/dist/index.d.ts +24 -12
  49. package/dist/index.js +5 -5
  50. package/dist/node.d.ts +18 -10
  51. package/dist/node.js +14 -12
  52. package/dist/reporters.d.ts +4 -4
  53. package/dist/reporters.js +3 -3
  54. package/dist/runners.d.ts +1 -1
  55. package/dist/runners.js +13 -5
  56. package/dist/snapshot.js +2 -2
  57. package/dist/suite.js +2 -2
  58. package/dist/worker.js +9 -5
  59. package/dist/workers/forks.js +6 -4
  60. package/dist/workers/runVmTests.js +14 -9
  61. package/dist/workers/threads.js +4 -4
  62. package/dist/workers/vmForks.js +6 -6
  63. package/dist/workers/vmThreads.js +6 -6
  64. package/dist/workers.d.ts +4 -4
  65. package/dist/workers.js +10 -10
  66. package/package.json +18 -18
  67. package/dist/chunks/index.CK1YOQaa.js +0 -143
@@ -1,11 +1,11 @@
1
1
  import { existsSync, writeFileSync, readFileSync } from 'node:fs';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
  import { resolve, dirname, relative } from 'node:path';
4
- import { detectPackageManager, installPackage } from './index.CK1YOQaa.js';
4
+ import { detectPackageManager, installPackage } from './index.D3XRDfWc.js';
5
5
  import { p as prompt, f as findUp } from './index.X0nbfr6-.js';
6
6
  import { x } from 'tinyexec';
7
7
  import c from 'tinyrainbow';
8
- import { c as configFiles } from './constants.BZZyIeIE.js';
8
+ import { c as configFiles } from './constants.DnKduX2e.js';
9
9
  import 'node:process';
10
10
  import 'node:url';
11
11
  import './_commonjsHelpers.BFTU3MAI.js';
@@ -236,14 +236,14 @@ test('renders name', () => {
236
236
  };
237
237
  function getExampleTest(framework) {
238
238
  switch (framework) {
239
- case "solid":
240
- case "preact": return {
239
+ case "solid": return {
241
240
  ...jsxExample,
242
241
  test: jsxExample.test.replace("@testing-library/jsx", `@testing-library/${framework}`)
243
242
  };
243
+ case "preact":
244
244
  case "react": return {
245
245
  ...jsxExample,
246
- test: jsxExample.test.replace("@testing-library/jsx", "vitest-browser-react")
246
+ test: jsxExample.test.replace("@testing-library/jsx", `vitest-browser-${framework}`)
247
247
  };
248
248
  case "vue": return vueExample;
249
249
  case "svelte": return svelteExample;
@@ -273,6 +273,7 @@ async function generateExampleFiles(framework, lang) {
273
273
  return testPath;
274
274
  }
275
275
 
276
+ // eslint-disable-next-line no-console
276
277
  const log = console.log;
277
278
  function getProviderOptions() {
278
279
  const providers = {
@@ -376,7 +377,7 @@ function getFrameworkTestPackage(framework) {
376
377
  case "svelte": return "vitest-browser-svelte";
377
378
  case "react": return "vitest-browser-react";
378
379
  case "lit": return "vitest-browser-lit";
379
- case "preact": return "@testing-library/preact";
380
+ case "preact": return "vitest-browser-preact";
380
381
  case "solid": return "@solidjs/testing-library";
381
382
  case "marko": return "@marko/testing-library";
382
383
  }
@@ -469,6 +470,7 @@ function getPossibleProvider(dependencies) {
469
470
  if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) {
470
471
  return "webdriverio";
471
472
  }
473
+ // playwright is the default recommendation
472
474
  return "playwright";
473
475
  }
474
476
  function getProviderDocsLink(provider) {
@@ -639,7 +641,7 @@ async function create() {
639
641
  "\nSince you already have a Vitest config file, it is recommended to copy the contents of the new file ",
640
642
  "into your existing config located at ",
641
643
  c.bold(relative(process.cwd(), rootConfig))
642
- );
644
+ );
643
645
  } else {
644
646
  const configPath = resolve(process.cwd(), `vitest.config.${lang}`);
645
647
  await generateFrameworkConfigFile({
@@ -670,6 +672,7 @@ async function create() {
670
672
  "inherit"
671
673
  ] } });
672
674
  }
675
+ // TODO: can we do this ourselves?
673
676
  if (lang === "ts") {
674
677
  await updateTsConfig(providerPkg?.types);
675
678
  }
@@ -1,3 +1,27 @@
1
+ /* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
2
+ /*
3
+ The MIT License (MIT)
4
+
5
+ Copyright (c) 2014 Bob Lauer
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ */
1
25
  const RealDate = Date;
2
26
  let now = null;
3
27
  class MockDate extends RealDate {
@@ -43,6 +67,7 @@ function mockDate(date) {
43
67
  if (Number.isNaN(dateObj.getTime())) {
44
68
  throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
45
69
  }
70
+ // @ts-expect-error global
46
71
  globalThis.Date = MockDate;
47
72
  now = dateObj.valueOf();
48
73
  }
@@ -36,6 +36,7 @@ const defaultCoverageExcludes = [
36
36
  "**/vitest.{workspace,projects}.[jt]s?(on)",
37
37
  "**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}"
38
38
  ];
39
+ // These are the generic defaults for coverage. Providers may also set some provider specific defaults.
39
40
  const coverageConfigDefaults = {
40
41
  provider: "v8",
41
42
  enabled: false,
@@ -36,6 +36,7 @@ interface ModuleGraphData {
36
36
  inlined: string[];
37
37
  }
38
38
  interface ProvidedContext {}
39
+ // These need to be compatible with Tinyrainbow's bg-colors, and CSS's background-color
39
40
  type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
40
41
 
41
42
  type HappyDOMOptions = Omit<NonNullable<ConstructorParameters<typeof happyDomTypes.Window>[0]>, "console">;
@@ -187,6 +187,8 @@ const basename = function(p, extension) {
187
187
  const { existsSync, readdirSync, statSync } = fs;
188
188
  function findMockRedirect(root, mockPath, external) {
189
189
  const path = external || mockPath;
190
+ // it's a node_module alias
191
+ // all mocks should be inside <root>/__mocks__
190
192
  if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
191
193
  const mockDirname = dirname(path);
192
194
  const mockFolder = join(root, "__mocks__", mockDirname);
@@ -200,9 +202,11 @@ function findMockRedirect(root, mockPath, external) {
200
202
  const baseFile = basename(file, extname(file));
201
203
  if (baseFile === baseOriginal) {
202
204
  const path = resolve(mockFolder, file);
205
+ // if the same name, return the file
203
206
  if (statSync(path).isFile()) {
204
207
  return path;
205
208
  } else {
209
+ // find folder/index.{js,ts}
206
210
  const indexFile = findFile(path, "index");
207
211
  if (indexFile) {
208
212
  return indexFile;
@@ -235,6 +239,7 @@ const builtins = new Set([
235
239
  "util/types",
236
240
  "wasi"
237
241
  ]);
242
+ // https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
238
243
  const prefixedBuiltins = new Set([
239
244
  "node:sea",
240
245
  "node:sqlite",
@@ -337,6 +342,7 @@ class VitestMocker {
337
342
  try {
338
343
  [id, fsPath] = await this.executor.originalResolveUrl(rawId, importer);
339
344
  } catch (error) {
345
+ // it's allowed to mock unresolved modules
340
346
  if (error.code === "ERR_MODULE_NOT_FOUND") {
341
347
  const { id: unresolvedId } = error[Symbol.for("vitest.error.not_found.data")];
342
348
  id = unresolvedId;
@@ -345,6 +351,8 @@ class VitestMocker {
345
351
  throw error;
346
352
  }
347
353
  }
354
+ // external is node_module or unresolved module
355
+ // for example, some people mock "vscode" and don't have it installed
348
356
  const external = !isAbsolute$1(fsPath) || this.isModuleDirectory(fsPath) ? rawId : null;
349
357
  return {
350
358
  id,
@@ -375,6 +383,7 @@ class VitestMocker {
375
383
  const exports = await mock.resolve();
376
384
  const moduleExports = new Proxy(exports, { get: (target, prop) => {
377
385
  const val = target[prop];
386
+ // 'then' can exist on non-Promise objects, need nested instanceof check for logic to work
378
387
  if (prop === "then") {
379
388
  if (target instanceof Promise) {
380
389
  return target.then.bind(target);
@@ -396,9 +405,11 @@ class VitestMocker {
396
405
  this.moduleCache.set(dep, { exports: moduleExports });
397
406
  return moduleExports;
398
407
  }
408
+ // public method to avoid circular dependency
399
409
  getMockContext() {
400
410
  return this.mockContext;
401
411
  }
412
+ // path used to store mocked dependencies
402
413
  getMockPath(dep) {
403
414
  return `mock:${dep}`;
404
415
  }
@@ -444,6 +455,7 @@ class VitestMocker {
444
455
  registry.register("automock", originalId, id, id);
445
456
  }
446
457
  }
458
+ // every time the mock is registered, we remove the previous one from the cache
447
459
  this.deleteCachedItem(id);
448
460
  }
449
461
  async importActual(rawId, importer, callstack) {
@@ -485,6 +497,7 @@ class VitestMocker {
485
497
  return cache.exports;
486
498
  }
487
499
  const exports = {};
500
+ // Assign the empty exports object early to allow for cycles to work. The object will be filled by mockObject()
488
501
  this.moduleCache.set(mockPath, { exports });
489
502
  const mod = await this.executor.directRequest(url, url, callstack);
490
503
  this.mockObject(mod, exports, mock.type);
@@ -493,6 +506,9 @@ class VitestMocker {
493
506
  if (mock.type === "manual" && !callstack.includes(mockPath) && !callstack.includes(url)) {
494
507
  try {
495
508
  callstack.push(mockPath);
509
+ // this will not work if user does Promise.all(import(), import())
510
+ // we can also use AsyncLocalStorage to store callstack, but this won't work in the browser
511
+ // maybe we should improve mock API in the future?
496
512
  this.mockContext.callstack = callstack;
497
513
  return await this.callFunctionMock(mockPath, mock);
498
514
  } finally {
@@ -549,6 +565,8 @@ function listenForErrors(state) {
549
565
  function catchError(err, type, event) {
550
566
  const worker = state();
551
567
  const listeners = process.listeners(event);
568
+ // if there is another listener, assume that it's handled by user code
569
+ // one is Vitest's own listener
552
570
  if (listeners.length > 1) {
553
571
  return;
554
572
  }
@@ -576,6 +594,8 @@ function getVitestImport(id, state) {
576
594
  if (externalizeMap.has(id)) {
577
595
  return { externalize: externalizeMap.get(id) };
578
596
  }
597
+ // always externalize Vitest because we import from there before running tests
598
+ // so we already have it cached by Node.js
579
599
  const root = state().config.root;
580
600
  const relativeRoot = relativeIds[root] ?? (relativeIds[root] = normalizedDistDir.slice(root.length));
581
601
  if (id.includes(distDir) || id.includes(normalizedDistDir) || relativeRoot && relativeRoot !== "/" && id.startsWith(relativeRoot)) {
@@ -713,6 +733,7 @@ class VitestExecutor extends ViteNodeRunner {
713
733
  return this.primitives;
714
734
  }
715
735
  get state() {
736
+ // @ts-expect-error injected untyped global
716
737
  return globalThis.__vitest_worker__ || this.options.state;
717
738
  }
718
739
  get moduleExecutionInfo() {
@@ -723,6 +744,8 @@ class VitestExecutor extends ViteNodeRunner {
723
744
  return false;
724
745
  }
725
746
  const transformMode = this.state.environment?.transformMode ?? "ssr";
747
+ // do not try and resolve node builtins in Node
748
+ // import('url') returns Node internal even if 'url' package is installed
726
749
  return transformMode === "ssr" ? !isNodeBuiltin$1(id) : !id.startsWith("node:");
727
750
  }
728
751
  async originalResolveUrl(id, importer) {
@@ -754,6 +777,7 @@ class VitestExecutor extends ViteNodeRunner {
754
777
  if (!vmContext || !this.externalModules) {
755
778
  return super.runModule(context, transformed);
756
779
  }
780
+ // add 'use strict' since ESM enables it by default
757
781
  const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
758
782
  const code = `${codeDefinition}${transformed}\n}}`;
759
783
  const options = {
@@ -785,6 +809,7 @@ class VitestExecutor extends ViteNodeRunner {
785
809
  return super.dependencyRequest(id, fsPath, callstack);
786
810
  }
787
811
  prepareContext(context) {
812
+ // support `import.meta.vitest` for test entry
788
813
  if (this.state.filepath && normalize$1(this.state.filepath) === normalize$1(context.__filename)) {
789
814
  const globalNamespace = this.options.context || globalThis;
790
815
  Object.defineProperty(context.__vite_ssr_import_meta__, "vitest", { get: () => globalNamespace.__vitest_index__ });
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
2
2
  import { Plugin } from '@vitest/pretty-format';
3
3
  import { SnapshotState } from '@vitest/snapshot';
4
4
  import { B as BenchmarkResult } from './benchmark.d.BwvBVTda.js';
5
- import { U as UserConsoleLog } from './environment.d.D8YDy2v5.js';
5
+ import { U as UserConsoleLog } from './environment.d.cL3nLXbE.js';
6
6
 
7
7
  type RawErrsMap = Map<string, TscErrorInfo[]>;
8
8
  interface TscErrorInfo {
@@ -29,6 +29,7 @@ type Context = RootAndTarget & {
29
29
  };
30
30
 
31
31
  declare global {
32
+ // eslint-disable-next-line ts/no-namespace
32
33
  namespace Chai {
33
34
  interface Assertion {
34
35
  containSubset: (expected: any) => Assertion;
@@ -66,6 +67,7 @@ declare module "@vitest/expect" {
66
67
  addSnapshotSerializer: (plugin: Plugin) => void;
67
68
  }
68
69
  interface Assertion<T> {
70
+ // Snapshots are extended in @vitest/snapshot and are not part of @vitest/expect
69
71
  matchSnapshot: SnapshotMatcher<T>;
70
72
  toMatchSnapshot: SnapshotMatcher<T>;
71
73
  toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
@@ -1,23 +1,24 @@
1
- import { g as globalApis } from './constants.BZZyIeIE.js';
2
- import { V as VitestIndex } from './index.CfXMNXHg.js';
3
- import './vi.BFR5YIgu.js';
1
+ import { g as globalApis } from './constants.DnKduX2e.js';
2
+ import { V as VitestIndex } from './index.DNgLEKsQ.js';
3
+ import './vi.pkoYCV6A.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';
7
7
  import 'chai';
8
- import './utils.CgTj3MsC.js';
8
+ import './utils.BlI4TC7Y.js';
9
9
  import '@vitest/utils';
10
10
  import './_commonjsHelpers.BFTU3MAI.js';
11
11
  import '@vitest/snapshot';
12
12
  import '@vitest/utils/error';
13
13
  import '@vitest/spy';
14
14
  import '@vitest/utils/source-map';
15
- import './date.CDOsz-HY.js';
16
- import './benchmark.BoF7jW0Q.js';
15
+ import './date.ByMsSlOr.js';
16
+ import './benchmark.Cf_PACH1.js';
17
17
  import 'expect-type';
18
18
 
19
19
  function registerApiGlobally() {
20
20
  globalApis.forEach((api) => {
21
+ // @ts-expect-error I know what I am doing :P
21
22
  globalThis[api] = VitestIndex[api];
22
23
  });
23
24
  }
@@ -1,5 +1,6 @@
1
1
  import { Console } from 'node:console';
2
2
 
3
+ // SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
3
4
  const LIVING_KEYS = [
4
5
  "DOMException",
5
6
  "URL",
@@ -291,6 +292,7 @@ function populateGlobal(global, win, options = {}) {
291
292
  if (global.global) {
292
293
  global.global = global;
293
294
  }
295
+ // rewrite defaultView to reference the same global context
294
296
  if (global.document && global.document.defaultView) {
295
297
  Object.defineProperty(global.document, "defaultView", {
296
298
  get: () => global,
@@ -320,7 +322,9 @@ var edge = {
320
322
  getVmContext() {
321
323
  return vm.context;
322
324
  },
323
- teardown() {}
325
+ teardown() {
326
+ // nothing to teardown
327
+ }
324
328
  };
325
329
  },
326
330
  async setup(global) {
@@ -365,7 +369,9 @@ var happy = {
365
369
  disableErrorCapturing: true
366
370
  }
367
371
  });
372
+ // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
368
373
  win.Buffer = Buffer;
374
+ // inject structuredClone if it exists
369
375
  if (typeof structuredClone !== "undefined" && !win.structuredClone) {
370
376
  win.structuredClone = structuredClone;
371
377
  }
@@ -380,6 +386,8 @@ var happy = {
380
386
  };
381
387
  },
382
388
  async setup(global, { happyDOM = {} }) {
389
+ // happy-dom v3 introduced a breaking change to Window, but
390
+ // provides GlobalWindow as a way to use previous behaviour
383
391
  const { Window, GlobalWindow } = await import('happy-dom');
384
392
  const win = new (GlobalWindow || Window)({
385
393
  ...happyDOM,
@@ -452,8 +460,11 @@ var jsdom = {
452
460
  ...restOptions
453
461
  });
454
462
  const clearWindowErrors = catchWindowErrors(dom.window);
463
+ // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
455
464
  dom.window.Buffer = Buffer;
456
465
  dom.window.jsdom = dom;
466
+ // inject web globals if they missing in JSDOM but otherwise available in Nodejs
467
+ // https://nodejs.org/dist/latest/docs/api/globals.html
457
468
  const globalNames = [
458
469
  "structuredClone",
459
470
  "fetch",
@@ -510,6 +521,7 @@ var jsdom = {
510
521
  }
511
522
  };
512
523
 
524
+ // some globals we do not want, either because deprecated or we set it ourselves
513
525
  const denyList = new Set([
514
526
  "GLOBAL",
515
527
  "root",
@@ -540,7 +552,9 @@ var node = {
540
552
  configurable: true,
541
553
  enumerable: descriptor.enumerable,
542
554
  get() {
555
+ // @ts-expect-error: no index signature
543
556
  const val = globalThis[nodeGlobalsKey];
557
+ // override lazy getter
544
558
  Object.defineProperty(global, nodeGlobalsKey, {
545
559
  configurable: true,
546
560
  enumerable: descriptor.enumerable,
@@ -550,6 +564,7 @@ var node = {
550
564
  return val;
551
565
  },
552
566
  set(val) {
567
+ // override lazy getter
553
568
  Object.defineProperty(global, nodeGlobalsKey, {
554
569
  configurable: true,
555
570
  enumerable: descriptor.enumerable,
@@ -578,6 +593,9 @@ var node = {
578
593
  global.global = global;
579
594
  global.Buffer = Buffer;
580
595
  global.ArrayBuffer = ArrayBuffer;
596
+ // TextEncoder (global or via 'util') references a Uint8Array constructor
597
+ // different than the global one used by users in tests. This makes sure the
598
+ // same constructor is referenced by both.
581
599
  global.Uint8Array = Uint8Array;
582
600
  return {
583
601
  getVmContext() {