vitest 4.1.12 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE.md +192 -10
  2. package/browser/context.d.ts +7 -1
  3. package/browser/context.js +5 -5
  4. package/config.d.ts +0 -2
  5. package/dist/browser.d.ts +52 -21
  6. package/dist/browser.js +12 -13
  7. package/dist/chunks/{acorn.B2iPLyUM.js → acorn.C1kjbUFw.js} +30 -30
  8. package/dist/chunks/{base.B6Opl8PE.js → base.Cof-UHJf.js} +81 -52
  9. package/dist/chunks/{browser.d.BcoexmFG.d.ts → browser.d.C7tWgUvw.d.ts} +17 -14
  10. package/dist/chunks/{cac.DzDtg8hz.js → cac.BYbt0aJp.js} +143 -87
  11. package/dist/chunks/{cli-api.B0Pz1_R7.js → cli-api.COfZo8lK.js} +7160 -7189
  12. package/dist/chunks/config.d.B3YV4t0O.d.ts +3873 -0
  13. package/dist/chunks/{console.3WNpx0tS.js → console.CQZ877Hi.js} +69 -63
  14. package/dist/chunks/{constants.CPYnjOGj.js → constants.DLYM6cZY.js} +2 -2
  15. package/dist/chunks/coverage.9iqXE2gN.js +26 -0
  16. package/dist/chunks/{coverage.CTzCuANN.js → coverage.jGCktcGP.js} +7 -2
  17. package/dist/chunks/{creator.DgVhQm5q.js → creator.DHWmytIK.js} +65 -28
  18. package/dist/chunks/{defaults.9aQKnqFk.js → defaults.B1FCaFfh.js} +16 -9
  19. package/dist/chunks/display.BlTmubjj.js +194 -0
  20. package/dist/chunks/doctor.B-oPbwps.js +465 -0
  21. package/dist/chunks/{env.D4Lgay0q.js → env.BKKtU2WC.js} +2 -1
  22. package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.BFQtFKdZ.d.ts} +9 -1
  23. package/dist/chunks/globals.ZKtKSkEf.js +29 -0
  24. package/dist/chunks/index.Bi0NXYPf.js +1708 -0
  25. package/dist/chunks/{index.CMESou6r.js → index.BoyTG_B7.js} +82 -81
  26. package/dist/chunks/index.CZzC1gGg.js +8501 -0
  27. package/dist/chunks/index.D0heQG4v.js +1318 -0
  28. package/dist/chunks/index.Di8au7q4.js +15665 -0
  29. package/dist/chunks/{index.Chj8NDwU.js → index.DmDMHCg8.js} +6 -12
  30. package/dist/chunks/{index.DXx9Dtk7.js → index.w_oBZ9N8.js} +25 -12
  31. package/dist/chunks/{init-forks.H5ZuobOQ.js → init-forks.BaDXQSD8.js} +7 -10
  32. package/dist/chunks/{init-threads.6kl1khcL.js → init-threads.ZX_Vov0z.js} +1 -1
  33. package/dist/chunks/{init.k9zZ9sLh.js → init.CO4AB7HZ.js} +113 -38
  34. package/dist/chunks/module-dependencies._2Eei3FO.js +71 -0
  35. package/dist/chunks/{native.DPzPHdi5.js → native.upB-V0CK.js} +50 -37
  36. package/dist/chunks/{nativeModuleMocker.BkNfQMkH.js → nativeModuleMocker.Dh5azSB4.js} +48 -19
  37. package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.9xPIMzi7.js} +110 -42
  38. package/dist/chunks/node.B9mkVmLH.js +47 -0
  39. package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
  40. package/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +492 -0
  41. package/dist/chunks/{reporters.d.DtoKVV2s.d.ts → plugin.d.LRFSN46m.d.ts} +2573 -1453
  42. package/dist/chunks/plugins.DPQHVT0p.js +37 -0
  43. package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
  44. package/dist/chunks/resolver.BzpmeQeT.js +48 -0
  45. package/dist/chunks/rpc.Uhkwr2NM.js +93 -0
  46. package/dist/chunks/rpc.d.3FOhdFx8.d.ts +75 -0
  47. package/dist/chunks/run.CjdgFZiW.js +4231 -0
  48. package/dist/chunks/setup-common.CqAQCXzx.js +36 -0
  49. package/dist/chunks/source-map.DakdQc29.js +1788 -0
  50. package/dist/chunks/source-map.d.BkG8YK_3.d.ts +89 -0
  51. package/dist/chunks/spy.DDMXghXv.js +509 -0
  52. package/dist/chunks/task-utils.d.D-gFPNFi.d.ts +144 -0
  53. package/dist/chunks/tinyrainbow.Do8I1XRG.js +88 -0
  54. package/dist/chunks/{utils.BS4fH3nR.js → utils.BBk_icFG.js} +50 -52
  55. package/dist/chunks/{utils.BX5Fg8C4.js → utils.DYj33du9.js} +1 -17
  56. package/dist/chunks/vm.b4MbCAJQ.js +1329 -0
  57. package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.CyJRpyfZ.d.ts} +34 -19
  58. package/dist/cli.js +5 -6
  59. package/dist/config.cjs +9 -6
  60. package/dist/config.d.ts +27 -25
  61. package/dist/config.js +3 -3
  62. package/dist/index.d.ts +471 -38
  63. package/dist/index.js +18 -19
  64. package/dist/module-evaluator.d.ts +64 -5
  65. package/dist/module-evaluator.js +122 -62
  66. package/dist/node.d.ts +355 -87
  67. package/dist/node.js +49 -73
  68. package/dist/runtime.d.ts +43 -6
  69. package/dist/runtime.js +7 -9
  70. package/dist/spy.js +1 -1
  71. package/dist/task-utils.js +290 -0
  72. package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +3 -2
  73. package/dist/worker.d.ts +8 -10
  74. package/dist/worker.js +33 -43
  75. package/dist/workers/forks.js +30 -40
  76. package/dist/workers/runVmTests.js +66 -43
  77. package/dist/workers/threads.js +30 -40
  78. package/dist/workers/vmForks.js +19 -20
  79. package/dist/workers/vmThreads.js +19 -20
  80. package/globals.d.ts +19 -19
  81. package/index.cjs +3 -3
  82. package/optional-runtime-types.d.ts +1 -1
  83. package/optional-types.d.ts +1 -1
  84. package/package.json +59 -74
  85. package/suppress-warnings.cjs +1 -1
  86. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
  87. package/dist/chunks/benchmark.CX_oY03V.js +0 -40
  88. package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
  89. package/dist/chunks/config.d.A1h_Y6Jt.d.ts +0 -232
  90. package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
  91. package/dist/chunks/coverage.d.BZtK59WP.d.ts +0 -37
  92. package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
  93. package/dist/chunks/global.d.DVsSRdQ5.d.ts +0 -100
  94. package/dist/chunks/globals.Dj1TGiMC.js +0 -31
  95. package/dist/chunks/index.DC7d2Pf8.js +0 -729
  96. package/dist/chunks/index.DdgEv5B1.js +0 -42
  97. package/dist/chunks/index.UpGiHP7g.js +0 -4255
  98. package/dist/chunks/index.og1WyBLx.js +0 -6358
  99. package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
  100. package/dist/chunks/node.COQbm6gK.js +0 -14
  101. package/dist/chunks/plugin.d.DwFIiJ7i.d.ts +0 -38
  102. package/dist/chunks/rpc.MzXet3jl.js +0 -144
  103. package/dist/chunks/rpc.d.B_8sPU0w.d.ts +0 -30
  104. package/dist/chunks/setup-common.DYx3LtFI.js +0 -60
  105. package/dist/chunks/startVitestModuleRunner.DB-7oCpn.js +0 -740
  106. package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
  107. package/dist/chunks/test.DNmyFkvJ.js +0 -4430
  108. package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
  109. package/dist/chunks/vm.CXMd5FHa.js +0 -785
  110. package/dist/coverage.d.ts +0 -123
  111. package/dist/coverage.js +0 -27
  112. package/dist/environments.d.ts +0 -22
  113. package/dist/environments.js +0 -5
  114. package/dist/reporters.d.ts +0 -27
  115. package/dist/reporters.js +0 -26
  116. package/dist/runners.d.ts +0 -70
  117. package/dist/runners.js +0 -19
  118. package/dist/snapshot.d.ts +0 -9
  119. package/dist/snapshot.js +0 -6
  120. package/dist/suite.d.ts +0 -5
  121. package/dist/suite.js +0 -8
@@ -10,13 +10,19 @@ const AGENTS = [
10
10
  "yarn@berry",
11
11
  "pnpm",
12
12
  "pnpm@6",
13
+ "pnpm-rush",
13
14
  "bun",
14
- "deno"
15
+ "deno",
16
+ "nub",
17
+ "aube"
15
18
  ];
16
19
  const LOCKS = {
20
+ "aube-lock.yaml": "aube",
21
+ "aube-workspace.yaml": "aube",
17
22
  "bun.lock": "bun",
18
23
  "bun.lockb": "bun",
19
24
  "deno.lock": "deno",
25
+ "nub.lock": "nub",
20
26
  "pnpm-lock.yaml": "pnpm",
21
27
  "pnpm-workspace.yaml": "pnpm",
22
28
  "yarn.lock": "yarn",
@@ -24,6 +30,7 @@ const LOCKS = {
24
30
  "npm-shrinkwrap.json": "npm"
25
31
  };
26
32
  const INSTALL_METADATA = {
33
+ "node_modules/.aube/": "aube",
27
34
  "node_modules/.deno/": "deno",
28
35
  "node_modules/.pnpm/": "pnpm",
29
36
  "node_modules/.yarn-state.yml": "yarn",
@@ -55,14 +62,15 @@ function* lookup(cwd = process.cwd()) {
55
62
  directory = path.dirname(directory);
56
63
  }
57
64
  }
58
- async function parsePackageJson(filepath, onUnknown) {
59
- return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
65
+ async function parsePackageJson(filepath, options) {
66
+ if (!filepath || !await pathExists(filepath, "file"))
67
+ return null;
68
+ return await handlePackageManager(filepath, options);
60
69
  }
61
70
  async function detect(options = {}) {
62
71
  const {
63
72
  cwd,
64
- strategies = ["lockfile", "packageManager-field", "devEngines-field"],
65
- onUnknown
73
+ strategies = ["lockfile", "packageManager-field", "devEngines-field"]
66
74
  } = options;
67
75
  let stopDir;
68
76
  if (typeof options.stopDir === "string") {
@@ -75,10 +83,13 @@ async function detect(options = {}) {
75
83
  for (const strategy of strategies) {
76
84
  switch (strategy) {
77
85
  case "lockfile": {
86
+ if (await pathExists(path.join(directory, "rush.json"), "file")) {
87
+ return { name: "pnpm", agent: "pnpm-rush" };
88
+ }
78
89
  for (const lock of Object.keys(LOCKS)) {
79
90
  if (await pathExists(path.join(directory, lock), "file")) {
80
91
  const name = LOCKS[lock];
81
- const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
92
+ const result = await parsePackageJson(path.join(directory, "package.json"), options);
82
93
  if (result)
83
94
  return result;
84
95
  else
@@ -89,7 +100,7 @@ async function detect(options = {}) {
89
100
  }
90
101
  case "packageManager-field":
91
102
  case "devEngines-field": {
92
- const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
103
+ const result = await parsePackageJson(path.join(directory, "package.json"), options);
93
104
  if (result)
94
105
  return result;
95
106
  break;
@@ -126,9 +137,10 @@ function getNameAndVer(pkg) {
126
137
  }
127
138
  return void 0;
128
139
  }
129
- async function handlePackageManager(filepath, onUnknown) {
140
+ async function handlePackageManager(filepath, options) {
130
141
  try {
131
- const pkg = JSON.parse(await fs.readFile(filepath, "utf8"));
142
+ const content = await fs.readFile(filepath, "utf8");
143
+ const pkg = options.packageJsonParser ? await options.packageJsonParser(content, filepath) : JSON.parse(content);
132
144
  let agent;
133
145
  const nameAndVer = getNameAndVer(pkg);
134
146
  if (nameAndVer) {
@@ -146,7 +158,7 @@ async function handlePackageManager(filepath, onUnknown) {
146
158
  agent = name;
147
159
  return { name, agent, version };
148
160
  } else {
149
- return onUnknown?.(pkg.packageManager) ?? null;
161
+ return options.onUnknown?.(pkg.packageManager) ?? null;
150
162
  }
151
163
  }
152
164
  } catch {
@@ -157,82 +169,71 @@ function isMetadataYarnClassic(metadataPath) {
157
169
  return metadataPath.endsWith(".yarn_integrity");
158
170
  }
159
171
 
160
- // src/detect.ts
172
+ //#region src/detect.ts
161
173
  async function detectPackageManager(cwd = process.cwd()) {
162
- const result = await detect({
163
- cwd,
164
- onUnknown(packageManager) {
165
- console.warn("[@antfu/install-pkg] Unknown packageManager:", packageManager);
166
- return void 0;
167
- }
168
- });
169
- return result?.agent || null;
174
+ return (await detect({
175
+ cwd,
176
+ onUnknown(packageManager) {
177
+ console.warn("[@antfu/install-pkg] Unknown packageManager:", packageManager);
178
+ }
179
+ }))?.agent || null;
170
180
  }
181
+ //#endregion
182
+ //#region src/install.ts
171
183
  async function installPackage(names, options = {}) {
172
- const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
173
- const [agent] = detectedAgent.split("@");
174
- if (!Array.isArray(names))
175
- names = [names];
176
- const args = (typeof options.additionalArgs === "function" ? options.additionalArgs(agent, detectedAgent) : options.additionalArgs) || [];
177
- if (options.preferOffline) {
178
- if (detectedAgent === "yarn@berry")
179
- args.unshift("--cached");
180
- else
181
- args.unshift("--prefer-offline");
182
- }
183
- if (agent === "pnpm") {
184
- args.unshift(
185
- /**
186
- * Prevent pnpm from removing installed devDeps while `NODE_ENV` is `production`
187
- * @see https://pnpm.io/cli/install#--prod--p
188
- */
189
- "--prod=false"
190
- );
191
- if (existsSync(resolve(options.cwd ?? process.cwd(), "pnpm-workspace.yaml"))) {
192
- args.unshift("-w");
193
- }
194
- }
195
- return x(
196
- agent,
197
- [
198
- agent === "yarn" ? "add" : "install",
199
- options.dev ? "-D" : "",
200
- ...args,
201
- ...names
202
- ].filter(Boolean),
203
- {
204
- nodeOptions: {
205
- stdio: options.silent ? "ignore" : "inherit",
206
- cwd: options.cwd
207
- },
208
- throwOnError: true
209
- }
210
- );
184
+ const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
185
+ const [agent] = detectedAgent.split("@");
186
+ if (!Array.isArray(names)) names = [names];
187
+ const args = (typeof options.additionalArgs === "function" ? options.additionalArgs(agent, detectedAgent) : options.additionalArgs) || [];
188
+ if (options.preferOffline) {
189
+ if (detectedAgent === "yarn@berry") args.unshift("--cached");
190
+ else args.unshift("--prefer-offline");
191
+ }
192
+ if (agent === "pnpm") {
193
+ args.unshift(
194
+ /**
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`.
198
+ * @see https://pnpm.io/cli/install#--prod--p
199
+ * @see https://github.com/pnpm/pnpm/issues/14868
200
+ */
201
+ "--config.prod=false"
202
+ );
203
+ if (existsSync(resolve(options.cwd ?? process.cwd(), "pnpm-workspace.yaml"))) args.unshift("-w");
204
+ }
205
+ return x(agent, [
206
+ agent === "yarn" ? "add" : "install",
207
+ options.dev ? "-D" : "",
208
+ ...args,
209
+ ...names
210
+ ].filter(Boolean), {
211
+ nodeOptions: {
212
+ stdio: options.silent ? "ignore" : "inherit",
213
+ cwd: options.cwd
214
+ },
215
+ throwOnError: true
216
+ });
211
217
  }
218
+ //#endregion
219
+ //#region src/uninstall.ts
212
220
  async function uninstallPackage(names, options = {}) {
213
- const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
214
- const [agent] = detectedAgent.split("@");
215
- if (!Array.isArray(names))
216
- names = [names];
217
- const args = options.additionalArgs || [];
218
- if (agent === "pnpm" && existsSync(resolve(options.cwd ?? process.cwd(), "pnpm-workspace.yaml")))
219
- args.unshift("-w");
220
- return x(
221
- agent,
222
- [
223
- agent === "yarn" ? "remove" : "uninstall",
224
- options.dev ? "-D" : "",
225
- ...args,
226
- ...names
227
- ].filter(Boolean),
228
- {
229
- nodeOptions: {
230
- stdio: options.silent ? "ignore" : "inherit",
231
- cwd: options.cwd
232
- },
233
- throwOnError: true
234
- }
235
- );
221
+ const [agent] = (options.packageManager || await detectPackageManager(options.cwd) || "npm").split("@");
222
+ if (!Array.isArray(names)) names = [names];
223
+ const args = options.additionalArgs || [];
224
+ if (agent === "pnpm" && existsSync(resolve(options.cwd ?? process.cwd(), "pnpm-workspace.yaml"))) args.unshift("-w");
225
+ return x(agent, [
226
+ agent === "yarn" ? "remove" : "uninstall",
227
+ options.dev ? "-D" : "",
228
+ ...args,
229
+ ...names
230
+ ].filter(Boolean), {
231
+ nodeOptions: {
232
+ stdio: options.silent ? "ignore" : "inherit",
233
+ cwd: options.cwd
234
+ },
235
+ throwOnError: true
236
+ });
236
237
  }
237
238
 
238
239
  export { detectPackageManager, installPackage, uninstallPackage };