vitest 5.0.2 → 5.0.4

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 (79) hide show
  1. package/LICENSE.md +29 -1
  2. package/browser/context.d.ts +7 -1
  3. package/browser/context.js +5 -5
  4. package/dist/browser.d.ts +4 -4
  5. package/dist/browser.js +11 -11
  6. package/dist/chunks/{base.5tQXSzMP.js → base.CYbb9pQW.js} +39 -15
  7. package/dist/chunks/{browser.d.g5Thl309.d.ts → browser.d.FGQ9_rK6.d.ts} +3 -3
  8. package/dist/chunks/{cac.BLbEtnDd.js → cac.DTXWs6Ni.js} +21 -23
  9. package/dist/chunks/cli-api.Bx28WXzL.js +13879 -0
  10. package/dist/chunks/{config.d.CU_b-wJj.d.ts → config.d.QBNYCgFU.d.ts} +33 -24
  11. package/dist/chunks/{console.B09ye7y0.js → console.DtI4yxfN.js} +5 -4
  12. package/dist/chunks/{coverage.AipniaqB.js → coverage.-bm5IxnW.js} +1 -1
  13. package/dist/chunks/{coverage.CX7NN5s7.js → coverage.cTDc4uSS.js} +1 -1
  14. package/dist/chunks/{creator.2VTnpYzN.js → creator.CLL8QFMS.js} +44 -54
  15. package/dist/chunks/{defaults.D2ip7f-X.js → defaults.B1FCaFfh.js} +2 -2
  16. package/dist/chunks/{display.pkpxlVcY.js → display.BlTmubjj.js} +1 -1
  17. package/dist/chunks/{doctor.BCXa6-1R.js → doctor.Bqc8NDDb.js} +40 -41
  18. package/dist/chunks/{env.DzFJjrmK.js → env.BKKtU2WC.js} +1 -1
  19. package/dist/chunks/{environment.d.C6xYahWA.d.ts → environment.d.BY56MoGs.d.ts} +1 -1
  20. package/dist/chunks/{globals.Brdv9iOs.js → globals.CTWMSIPL.js} +10 -10
  21. package/dist/chunks/{index.C-uw7tH9.js → index.B8VfM7Mf.js} +8606 -20822
  22. package/dist/chunks/{index.DXQx-kDM.js → index.BoyTG_B7.js} +9 -4
  23. package/dist/chunks/{index.hTNFpC24.js → index.CPNMO3h-.js} +73 -50
  24. package/dist/chunks/{index.M2dsQ_UQ.js → index.D0heQG4v.js} +557 -183
  25. package/dist/chunks/{index.BgwtGYxD.js → index.GYMZ12wH.js} +5 -5
  26. package/dist/chunks/{index.DGdajAO2.js → index.uwTEEBsB.js} +94 -71
  27. package/dist/chunks/{init-forks.CdGu3HUy.js → init-forks.CbYYa5xq.js} +1 -1
  28. package/dist/chunks/{init-threads.2f_lsHNK.js → init-threads.DtjdvxPl.js} +1 -1
  29. package/dist/chunks/{init.IsjtLXKe.js → init.DrHtV5zd.js} +7 -7
  30. package/dist/chunks/module-dependencies.CwNPkcV4.js +71 -0
  31. package/dist/chunks/{native.CF4uT5hY.js → native.cdzHIdmv.js} +48 -34
  32. package/dist/chunks/{nativeModuleMocker.DwRB4F9R.js → nativeModuleMocker.D8f4cW4A.js} +2 -2
  33. package/dist/chunks/{nativeModuleRunner.J0QLzNtK.js → nativeModuleRunner.xi64Afb2.js} +1 -1
  34. package/dist/chunks/{node.CfQ_OGWr.js → node.uQulW0ei.js} +1 -1
  35. package/dist/chunks/{pathe.M-eThtNZ.DwEga6ro.js → pathe.M-eThtNZ.Ba-7h1rE.js} +9 -7
  36. package/dist/chunks/{plugin.d.My_z-jmU.d.ts → plugin.d.C8mmycim.d.ts} +109 -68
  37. package/dist/chunks/{plugins.Cigb0uSy.js → plugins.DPQHVT0p.js} +1 -1
  38. package/dist/chunks/{resolver.NpfwMKt9.js → resolver.CtCcxIy1.js} +1 -1
  39. package/dist/chunks/{rpc.CJVl3hZH.js → rpc.DpkUyY1N.js} +3 -2
  40. package/dist/chunks/{rpc.d.DA9Utv4e.d.ts → rpc.d.Cft1biqy.d.ts} +2 -1
  41. package/dist/chunks/{run.C5UmxDPh.js → run.Cm2sd7-x.js} +122 -97
  42. package/dist/chunks/{setup-common.Ct8rQvjH.js → setup-common.BABL3z3m.js} +3 -3
  43. package/dist/chunks/{source-map.BH0bbrs9.js → source-map.DdKI5IHB.js} +15 -10
  44. package/dist/chunks/{source-map.d.YqWNcp4e.d.ts → source-map.d.kzFtk_dj.d.ts} +1 -1
  45. package/dist/chunks/{spy.KLHgXex_.js → spy.DDMXghXv.js} +63 -32
  46. package/dist/chunks/{task-utils.d.BZm4GSQD.d.ts → task-utils.d.PFh2BV6Q.d.ts} +1 -1
  47. package/dist/chunks/tinyrainbow.Do8I1XRG.js +88 -0
  48. package/dist/chunks/{utils.CJ0JImL8.js → utils.DSfl_w8V.js} +44 -42
  49. package/dist/chunks/{vm.KI2AYADz.js → vm.Uo_C9Uld.js} +16 -13
  50. package/dist/chunks/{worker.d.MLmnzOJE.d.ts → worker.d.BH-r1bPu.d.ts} +8 -3
  51. package/dist/cli.js +4 -4
  52. package/dist/config.cjs +1 -1
  53. package/dist/config.d.ts +9 -10
  54. package/dist/config.js +2 -2
  55. package/dist/index.d.ts +10 -10
  56. package/dist/index.js +10 -10
  57. package/dist/module-evaluator.d.ts +3 -2
  58. package/dist/module-evaluator.js +8 -5
  59. package/dist/node.d.ts +9 -10
  60. package/dist/node.js +27 -26
  61. package/dist/runtime.d.ts +6 -6
  62. package/dist/runtime.js +4 -4
  63. package/dist/spy.js +1 -1
  64. package/dist/task-utils.js +7 -4
  65. package/dist/worker.d.ts +4 -4
  66. package/dist/worker.js +21 -20
  67. package/dist/workers/forks.js +19 -18
  68. package/dist/workers/runVmTests.js +23 -14
  69. package/dist/workers/threads.js +19 -18
  70. package/dist/workers/vmForks.js +13 -13
  71. package/dist/workers/vmThreads.js +13 -13
  72. package/globals.d.ts +19 -19
  73. package/index.cjs +3 -3
  74. package/optional-runtime-types.d.ts +1 -1
  75. package/optional-types.d.ts +1 -1
  76. package/package.json +35 -29
  77. package/suppress-warnings.cjs +1 -1
  78. package/dist/chunks/cli-api.DL4Bd7Vh.js +0 -528
  79. package/dist/chunks/tinyrainbow.Ht9iggcq.js +0 -95
@@ -185,15 +185,20 @@ async function installPackage(names, options = {}) {
185
185
  const [agent] = detectedAgent.split("@");
186
186
  if (!Array.isArray(names)) names = [names];
187
187
  const args = (typeof options.additionalArgs === "function" ? options.additionalArgs(agent, detectedAgent) : options.additionalArgs) || [];
188
- if (options.preferOffline) if (detectedAgent === "yarn@berry") args.unshift("--cached");
189
- else args.unshift("--prefer-offline");
188
+ if (options.preferOffline) {
189
+ if (detectedAgent === "yarn@berry") args.unshift("--cached");
190
+ else args.unshift("--prefer-offline");
191
+ }
190
192
  if (agent === "pnpm") {
191
193
  args.unshift(
192
194
  /**
193
- * Prevent pnpm from removing installed devDeps while `NODE_ENV` is `production`
195
+ * Prevent pnpm from removing installed devDeps while `NODE_ENV` is `production`.
196
+ * Uses the `--config.` escape hatch instead of `--prod=false` because pnpm >=12.4.1
197
+ * routes `install <pkg>` through its `add`-compatible parser, which rejects `--prod`.
194
198
  * @see https://pnpm.io/cli/install#--prod--p
199
+ * @see https://github.com/pnpm/pnpm/issues/14868
195
200
  */
196
- "--prod=false"
201
+ "--config.prod=false"
197
202
  );
198
203
  if (existsSync(resolve(options.cwd ?? process.cwd(), "pnpm-workspace.yaml"))) args.unshift("-w");
199
204
  }
@@ -1,5 +1,5 @@
1
1
  import fs__default from 'node:fs';
2
- import { n as normalize, k as splitFileAndPostfix$1, j as join, l as isBareImport } from './pathe.M-eThtNZ.DwEga6ro.js';
2
+ import { n as normalize, k as splitFileAndPostfix$1, j as join, l as isBareImport } from './pathe.M-eThtNZ.Ba-7h1rE.js';
3
3
  import { i as isBuiltin, a as isBrowserExternal, t as toBuiltin } from './modules.BJuCwlRJ.js';
4
4
  import { E as EnvironmentTeardownError, a as getSafeWorkerState } from './utils.DYj33du9.js';
5
5
  import { pathToFileURL, URL as URL$1 } from 'node:url';
@@ -11,6 +11,7 @@ import { MockerRegistry, mockObject, RedirectedModule, AutomockedModule } from '
11
11
  import { findMockRedirect } from '@vitest/mocker/redirect';
12
12
  import * as viteModuleRunner from 'vite/module-runner';
13
13
  import { Traces } from '../traces.js';
14
+ import { createRequire } from 'node:module';
14
15
  import { Console } from 'node:console';
15
16
 
16
17
  class BareModuleMocker {
@@ -564,6 +565,7 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
564
565
  return await this.cachedModule(url, importer);
565
566
  }
566
567
  _cachedRequest(url, module, callstack = [], metadata) {
568
+ this.vitestOptions.getWorkerState().dependencies?.add(module.id);
567
569
  // @ts-expect-error "cachedRequest" is private
568
570
  return super.cachedRequest(url, module, callstack, metadata);
569
571
  }
@@ -638,7 +640,10 @@ function getCachedVitestImport(id, state) {
638
640
  const relativeRoot = relativeIds[root] ?? (relativeIds[root] = getRelativeDistDir(root));
639
641
  if (id.includes(distDir) || id.includes(normalizedDistDir)) {
640
642
  const { file, postfix } = splitFileAndPostfix$1(id);
641
- const externalize = id.startsWith("file://") ? id : `${pathToFileURL(file)}${postfix}`;
643
+ // Vite resolves the Windows drive letter in upper case, but Node.js caches
644
+ // modules by URL, so keep the drive letter Vitest itself was loaded with
645
+ const path = file.startsWith(normalizedDistDir) ? distDir + file.slice(normalizedDistDir.length) : file;
646
+ const externalize = id.startsWith("file://") ? id : `${pathToFileURL(path)}${postfix}`;
642
647
  externalizeMap.set(id, externalize);
643
648
  return {
644
649
  externalize,
@@ -726,6 +731,7 @@ function startVitestModuleRunner(options) {
726
731
  return state().config.injectCjsGlobals;
727
732
  },
728
733
  getCurrentTestFilepath: () => state().filepath,
734
+ getEnvironmentName: environment,
729
735
  getterTracker: state().getterTracker
730
736
  });
731
737
  const moduleRunner = new VitestModuleRunner({
@@ -786,13 +792,15 @@ function startVitestModuleRunner(options) {
786
792
  // the null prototype is not preserved by the IPC serialization, so
787
793
  // ids like "constructor" must not fall through to Object.prototype
788
794
  const warmResult = warm && (Object.hasOwn(warm, id) ? warm[id] : Object.hasOwn(warm, rawId) ? warm[rawId] : void 0);
789
- if (warmResult) if ("tmp" in warmResult) try {
790
- return {
791
- code: readFileSync(warmResult.tmp, "utf-8"),
792
- ...warmResult
793
- };
794
- } catch {}
795
- else return warmResult;
795
+ if (warmResult) {
796
+ if ("tmp" in warmResult) try {
797
+ return {
798
+ code: readFileSync(warmResult.tmp, "utf-8"),
799
+ ...warmResult
800
+ };
801
+ } catch {}
802
+ else return warmResult;
803
+ }
796
804
  }
797
805
  const otelCarrier = traces?.getContextCarrier();
798
806
  const result = await trackFetchTime(rpc().fetch(id, importer, environment(), options, otelCarrier));
@@ -1419,10 +1427,22 @@ function createJSDOMCompatURL(utils) {
1419
1427
  }
1420
1428
  return URL;
1421
1429
  }
1430
+ // jsdom keeps Blob bytes on an internal "impl" object and exposes no synchronous
1431
+ // public way to read them, so this reaches into its generated bindings
1432
+ function createBlobImplGetter(window) {
1433
+ const _require = createRequire(import.meta.url);
1434
+ // jsdom 28.1 moved the generated bindings; jsdom has no "exports" map, so both subpaths resolve
1435
+ for (const id of ["jsdom/lib/generated/idl/utils.js", "jsdom/lib/jsdom/living/generated/utils.js"]) try {
1436
+ const { implForWrapper } = _require(id);
1437
+ if (typeof implForWrapper === "function") return implForWrapper;
1438
+ } catch {}
1439
+ // jsdom < 30.1 also stores the impl under an own Symbol("impl")
1440
+ const implSymbol = Object.getOwnPropertySymbols(new window.Blob())[0];
1441
+ return (blob) => blob[implSymbol];
1442
+ }
1443
+ let getBlobImpl;
1422
1444
  function createCompatUtils(window) {
1423
- // this returns a hidden Symbol(impl)
1424
- // this is cursed, and jsdom should just implement fetch API itself
1425
- const implSymbol = Object.getOwnPropertySymbols(Object.getOwnPropertyDescriptors(new window.Blob()))[0];
1445
+ getBlobImpl ??= createBlobImplGetter(window);
1426
1446
  const utils = {
1427
1447
  window,
1428
1448
  makeCompatFormData(formData) {
@@ -1434,7 +1454,8 @@ function createCompatUtils(window) {
1434
1454
  return nodeFormData;
1435
1455
  },
1436
1456
  makeCompatBlob(blob) {
1437
- const impl = blob[implSymbol];
1457
+ const impl = getBlobImpl(blob);
1458
+ if (!impl) throw new TypeError("Vitest cannot read the bytes of a jsdom Blob. This is a Vitest bug, please report it with your jsdom version.");
1438
1459
  // jsdom 28 renamed `_buffer` to `_bytes`
1439
1460
  return new NodeBlob_([impl._bytes ?? impl._buffer], { type: blob.type });
1440
1461
  }
@@ -1511,43 +1532,45 @@ var node = {
1511
1532
  let context = vm.createContext();
1512
1533
  let global = vm.runInContext("this", context);
1513
1534
  const contextGlobals = new Set(Object.getOwnPropertyNames(global));
1514
- for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
1515
- configurable: true,
1516
- enumerable: descriptor.enumerable,
1517
- get() {
1518
- // @ts-expect-error: no index signature
1519
- const val = globalThis[nodeGlobalsKey];
1520
- // override lazy getter
1521
- Object.defineProperty(global, nodeGlobalsKey, {
1522
- configurable: true,
1523
- enumerable: descriptor.enumerable,
1524
- value: val,
1525
- writable: descriptor.writable === true || nodeGlobalsKey === "performance"
1526
- });
1527
- return val;
1528
- },
1529
- set(val) {
1530
- // override lazy getter
1531
- Object.defineProperty(global, nodeGlobalsKey, {
1532
- configurable: true,
1533
- enumerable: descriptor.enumerable,
1534
- value: val,
1535
- writable: true
1536
- });
1537
- }
1538
- });
1539
- else if ("value" in descriptor) Object.defineProperty(global, nodeGlobalsKey, {
1540
- configurable: false,
1541
- enumerable: descriptor.enumerable,
1542
- value: descriptor.value,
1543
- writable: descriptor.writable
1544
- });
1545
- else Object.defineProperty(global, nodeGlobalsKey, {
1546
- configurable: false,
1547
- enumerable: descriptor.enumerable,
1548
- get: descriptor.get,
1549
- set: descriptor.set
1550
- });
1535
+ for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) {
1536
+ if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
1537
+ configurable: true,
1538
+ enumerable: descriptor.enumerable,
1539
+ get() {
1540
+ // @ts-expect-error: no index signature
1541
+ const val = globalThis[nodeGlobalsKey];
1542
+ // override lazy getter
1543
+ Object.defineProperty(global, nodeGlobalsKey, {
1544
+ configurable: true,
1545
+ enumerable: descriptor.enumerable,
1546
+ value: val,
1547
+ writable: descriptor.writable === true || nodeGlobalsKey === "performance"
1548
+ });
1549
+ return val;
1550
+ },
1551
+ set(val) {
1552
+ // override lazy getter
1553
+ Object.defineProperty(global, nodeGlobalsKey, {
1554
+ configurable: true,
1555
+ enumerable: descriptor.enumerable,
1556
+ value: val,
1557
+ writable: true
1558
+ });
1559
+ }
1560
+ });
1561
+ else if ("value" in descriptor) Object.defineProperty(global, nodeGlobalsKey, {
1562
+ configurable: false,
1563
+ enumerable: descriptor.enumerable,
1564
+ value: descriptor.value,
1565
+ writable: descriptor.writable
1566
+ });
1567
+ else Object.defineProperty(global, nodeGlobalsKey, {
1568
+ configurable: false,
1569
+ enumerable: descriptor.enumerable,
1570
+ get: descriptor.get,
1571
+ set: descriptor.set
1572
+ });
1573
+ }
1551
1574
  global.global = global;
1552
1575
  global.Buffer = Buffer;
1553
1576
  global.ArrayBuffer = ArrayBuffer;