vitest 4.0.0-beta.5 → 4.0.0-beta.6

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 (57) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.DMfOuRWD.js → base.BXI97p6t.js} +7 -16
  5. package/dist/chunks/{benchmark.CtuRzf-i.js → benchmark.UW6Ezvxy.js} +4 -9
  6. package/dist/chunks/{cac.CKnbxhn2.js → cac.WE-urWw5.js} +37 -113
  7. package/dist/chunks/{cli-api.COn58yrl.js → cli-api.CZz3evYC.js} +505 -1211
  8. package/dist/chunks/{console.Duv2dVIC.js → console.B0quX7yH.js} +32 -68
  9. package/dist/chunks/{coverage.B6cReEn1.js → coverage.BPRS6xgn.js} +210 -579
  10. package/dist/chunks/{creator.DUVZ6rfm.js → creator.KEg6n5IC.js} +28 -74
  11. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  12. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  13. package/dist/chunks/{globals.CJQ63oO0.js → globals.lgsmH00r.js} +5 -5
  14. package/dist/chunks/{index.DgN0Zk9a.js → index.7w0eqmYM.js} +14 -24
  15. package/dist/chunks/{index.QZr3S3vQ.js → index.AR8aAkCC.js} +2 -2
  16. package/dist/chunks/{index.BRtIe7r8.js → index.BG0gqZH-.js} +39 -102
  17. package/dist/chunks/{index.oWRWx-nj.js → index.CsFXYRkW.js} +17 -36
  18. package/dist/chunks/{index.DQhAfQQU.js → index.VNI-1z5c.js} +270 -606
  19. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  20. package/dist/chunks/{moduleRunner.d.mmOmOGrW.d.ts → moduleRunner.d.8kKUsuDg.d.ts} +1 -1
  21. package/dist/chunks/{node.4JV5OXkt.js → node.BOqcT2jW.js} +1 -1
  22. package/dist/chunks/{plugin.d.CvOlgjxK.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
  23. package/dist/chunks/{reporters.d.CYE9sT5z.d.ts → reporters.d.CqR9-CDJ.d.ts} +16 -33
  24. package/dist/chunks/{resolver.D5bG4zy5.js → resolver.Bx6lE0iq.js} +21 -64
  25. package/dist/chunks/{rpc.DGoW_Vl-.js → rpc.RpPylpp0.js} +7 -21
  26. package/dist/chunks/{runBaseTests.B3KcKqlF.js → runBaseTests.D6sfuWBM.js} +25 -54
  27. package/dist/chunks/{setup-common.lgPs-bYv.js → setup-common.hLGRxhC8.js} +9 -22
  28. package/dist/chunks/{startModuleRunner.C8FtT_BY.js → startModuleRunner.C8TW8zTN.js} +83 -205
  29. package/dist/chunks/{typechecker.BgoW4nTA.js → typechecker.Cd1wvxUM.js} +96 -208
  30. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  31. package/dist/chunks/{utils.B9FY3b73.js → utils.C7__0Iv5.js} +5 -14
  32. package/dist/chunks/{vi.DGAfBY4R.js → vi.BfdOiD4j.js} +110 -267
  33. package/dist/chunks/{vm.BKfKvaKl.js → vm.BHBje7cC.js} +73 -177
  34. package/dist/cli.js +3 -3
  35. package/dist/config.d.ts +4 -4
  36. package/dist/coverage.d.ts +1 -1
  37. package/dist/coverage.js +2 -2
  38. package/dist/environments.js +1 -1
  39. package/dist/index.js +5 -5
  40. package/dist/module-evaluator.d.ts +1 -1
  41. package/dist/module-evaluator.js +33 -84
  42. package/dist/module-runner.js +2 -2
  43. package/dist/node.d.ts +3 -3
  44. package/dist/node.js +13 -19
  45. package/dist/reporters.d.ts +2 -2
  46. package/dist/reporters.js +3 -3
  47. package/dist/runners.js +23 -51
  48. package/dist/snapshot.js +2 -2
  49. package/dist/suite.js +2 -2
  50. package/dist/worker.js +18 -34
  51. package/dist/workers/forks.js +4 -4
  52. package/dist/workers/runVmTests.js +19 -37
  53. package/dist/workers/threads.js +4 -4
  54. package/dist/workers/vmForks.js +7 -7
  55. package/dist/workers/vmThreads.js +7 -7
  56. package/dist/workers.js +11 -11
  57. package/package.json +11 -11
@@ -9,14 +9,12 @@ class ModuleDebug {
9
9
  executionStack = [];
10
10
  startCalculateModuleExecutionInfo(filename, startOffset) {
11
11
  const startTime = performanceNow();
12
- this.executionStack.push({
12
+ return this.executionStack.push({
13
13
  filename,
14
14
  startTime,
15
15
  subImportTime: 0
16
- });
17
- return () => {
18
- const duration = performanceNow() - startTime;
19
- const currentExecution = this.executionStack.pop();
16
+ }), () => {
17
+ const duration = performanceNow() - startTime, currentExecution = this.executionStack.pop();
20
18
  if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");
21
19
  const selfTime = duration - currentExecution.subImportTime;
22
20
  if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;
@@ -39,10 +37,7 @@ class VitestModuleEvaluator {
39
37
  primitives;
40
38
  debug = new ModuleDebug();
41
39
  constructor(vmOptions, options = {}) {
42
- this.options = options;
43
- this.vm = vmOptions;
44
- this.stubs = getDefaultRequestStubs(vmOptions?.context);
45
- if (options.compiledFunctionArgumentsNames) this.compiledFunctionArgumentsNames = options.compiledFunctionArgumentsNames;
40
+ if (this.options = options, this.vm = vmOptions, this.stubs = getDefaultRequestStubs(vmOptions?.context), options.compiledFunctionArgumentsNames) this.compiledFunctionArgumentsNames = options.compiledFunctionArgumentsNames;
46
41
  if (options.compiledFunctionArgumentsValues) this.compiledFunctionArgumentsValues = options.compiledFunctionArgumentsValues;
47
42
  if (vmOptions) this.primitives = vm.runInContext("({ Object, Proxy, Reflect })", vmOptions.context);
48
43
  else this.primitives = {
@@ -57,24 +52,18 @@ class VitestModuleEvaluator {
57
52
  // https://github.com/vitejs/vite/pull/20449
58
53
  if (!isWindows || isBuiltin(id) || /^(?:node:|data:|http:|https:|file:)/.test(id)) return id;
59
54
  const [filepath, query] = id.split("?");
60
- if (query) return `${pathToFileURL(filepath).toString()}?${query}`;
61
- return pathToFileURL(filepath).toString();
55
+ return query ? `${pathToFileURL(filepath).toString()}?${query}` : pathToFileURL(filepath).toString();
62
56
  }
63
57
  async runExternalModule(id) {
64
58
  if (id in this.stubs) return this.stubs[id];
65
- const file = this.convertIdToImportUrl(id);
66
- const namespace = this.vm ? await this.vm.externalModulesExecutor.import(file) : await import(file);
59
+ const file = this.convertIdToImportUrl(id), namespace = this.vm ? await this.vm.externalModulesExecutor.import(file) : await import(file);
67
60
  if (!this.shouldInterop(file, namespace)) return namespace;
68
- const { mod, defaultExport } = interopModule(namespace);
69
- const { Proxy, Reflect } = this.primitives;
70
- const proxy = new Proxy(mod, {
61
+ const { mod, defaultExport } = interopModule(namespace), { Proxy, Reflect } = this.primitives, proxy = new Proxy(mod, {
71
62
  get(mod, prop) {
72
- if (prop === "default") return defaultExport;
73
- return mod[prop] ?? defaultExport?.[prop];
63
+ return prop === "default" ? defaultExport : mod[prop] ?? defaultExport?.[prop];
74
64
  },
75
65
  has(mod, prop) {
76
- if (prop === "default") return defaultExport !== void 0;
77
- return prop in mod || defaultExport && prop in defaultExport;
66
+ return prop === "default" ? defaultExport !== void 0 : prop in mod || defaultExport && prop in defaultExport;
78
67
  },
79
68
  getOwnPropertyDescriptor(mod, prop) {
80
69
  const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
@@ -90,58 +79,40 @@ class VitestModuleEvaluator {
90
79
  }
91
80
  async runInlinedModule(context, code, module) {
92
81
  context.__vite_ssr_import_meta__.env = this.env;
93
- const { Reflect, Proxy, Object } = this.primitives;
94
- const exportsObject = context[ssrModuleExportsKey];
95
- const SYMBOL_NOT_DEFINED = Symbol("not defined");
82
+ const { Reflect, Proxy, Object } = this.primitives, exportsObject = context[ssrModuleExportsKey], SYMBOL_NOT_DEFINED = Symbol("not defined");
96
83
  let moduleExports = SYMBOL_NOT_DEFINED;
97
84
  // this proxy is triggered only on exports.{name} and module.exports access
98
85
  // inside the module itself. imported module is always "exports"
99
86
  const cjsExports = new Proxy(exportsObject, {
100
87
  get: (target, p, receiver) => {
101
- if (Reflect.has(target, p)) return Reflect.get(target, p, receiver);
102
- return Reflect.get(Object.prototype, p, receiver);
88
+ return Reflect.has(target, p) ? Reflect.get(target, p, receiver) : Reflect.get(Object.prototype, p, receiver);
103
89
  },
104
90
  getPrototypeOf: () => Object.prototype,
105
91
  set: (_, p, value) => {
106
92
  // treat "module.exports =" the same as "exports.default =" to not have nested "default.default",
107
93
  // so "exports.default" becomes the actual module
108
- if (p === "default" && this.shouldInterop(module.file, { default: value }) && cjsExports !== value) {
109
- exportAll(cjsExports, value);
110
- exportsObject.default = value;
111
- return true;
112
- }
94
+ if (p === "default" && this.shouldInterop(module.file, { default: value }) && cjsExports !== value) return exportAll(cjsExports, value), exportsObject.default = value, true;
113
95
  if (!Reflect.has(exportsObject, "default")) exportsObject.default = {};
114
96
  // returns undefined, when accessing named exports, if default is not an object
115
97
  // but is still present inside hasOwnKeys, this is Node behaviour for CJS
116
- if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) {
117
- defineExport(exportsObject, p, () => void 0);
118
- return true;
119
- }
98
+ if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) return defineExport(exportsObject, p, () => void 0), true;
120
99
  if (!isPrimitive(exportsObject.default)) exportsObject.default[p] = value;
121
100
  if (p !== "default") defineExport(exportsObject, p, () => value);
122
101
  return true;
123
102
  }
124
- });
125
- const moduleProxy = {
103
+ }), moduleProxy = {
126
104
  set exports(value) {
127
- exportAll(cjsExports, value);
128
- exportsObject.default = value;
129
- moduleExports = value;
105
+ exportAll(cjsExports, value), exportsObject.default = value, moduleExports = value;
130
106
  },
131
107
  get exports() {
132
108
  return cjsExports;
133
109
  }
134
- };
135
- const meta = context[ssrImportMetaKey];
136
- const testFilepath = this.options.getCurrentTestFilepath?.();
110
+ }, meta = context[ssrImportMetaKey], testFilepath = this.options.getCurrentTestFilepath?.();
137
111
  if (testFilepath === module.file) {
138
112
  const globalNamespace = this.vm?.context || globalThis;
139
113
  Object.defineProperty(meta, "vitest", { get: () => globalNamespace.__vitest_index__ });
140
114
  }
141
- const filename = meta.filename;
142
- const dirname = meta.dirname;
143
- const require = this.createRequire(filename);
144
- const argumentsList = [
115
+ const filename = meta.filename, dirname = meta.dirname, require = this.createRequire(filename), argumentsList = [
145
116
  ssrModuleExportsKey,
146
117
  ssrImportMetaKey,
147
118
  ssrImportKey,
@@ -156,22 +127,14 @@ class VitestModuleEvaluator {
156
127
  ];
157
128
  if (this.compiledFunctionArgumentsNames) argumentsList.push(...this.compiledFunctionArgumentsNames);
158
129
  // add 'use strict' since ESM enables it by default
159
- const codeDefinition = `'use strict';async (${argumentsList.join(",")})=>{{`;
160
- const wrappedCode = `${codeDefinition}${code}\n}}`;
161
- const options = {
130
+ const codeDefinition = `'use strict';async (${argumentsList.join(",")})=>{{`, wrappedCode = `${codeDefinition}${code}\n}}`, options = {
162
131
  filename: module.file || filename,
163
132
  lineOffset: 0,
164
133
  columnOffset: -codeDefinition.length
165
- };
166
- const finishModuleExecutionInfo = this.debug.startCalculateModuleExecutionInfo(filename, codeDefinition.length);
134
+ }, finishModuleExecutionInfo = this.debug.startCalculateModuleExecutionInfo(filename, codeDefinition.length);
167
135
  try {
168
- const initModule = this.vm ? vm.runInContext(wrappedCode, this.vm.context, options) : vm.runInThisContext(wrappedCode, options);
169
- const dynamicRequest = async (dep, options) => {
170
- dep = String(dep);
171
- // TODO: support more edge cases?
172
- // vite doesn't support dynamic modules by design, but we have to
173
- if (dep[0] === "#") return context[ssrDynamicImportKey](wrapId(dep), options);
174
- return context[ssrDynamicImportKey](dep, options);
136
+ const initModule = this.vm ? vm.runInContext(wrappedCode, this.vm.context, options) : vm.runInThisContext(wrappedCode, options), dynamicRequest = async (dep, options) => {
137
+ return dep = String(dep), dep[0] === "#" ? context[ssrDynamicImportKey](wrapId(dep), options) : context[ssrDynamicImportKey](dep, options);
175
138
  };
176
139
  await initModule(
177
140
  context[ssrModuleExportsKey],
@@ -199,16 +162,12 @@ class VitestModuleEvaluator {
199
162
  }
200
163
  }
201
164
  createRequire(filename) {
202
- // \x00 is a rollup convention for virtual files,
203
- // it is not allowed in actual file names
204
- if (filename.startsWith("\0") || !isAbsolute(filename)) return () => ({});
205
- return this.vm ? this.vm.externalModulesExecutor.createRequire(filename) : createRequire(filename);
165
+ return filename.startsWith("\0") || !isAbsolute(filename) ? () => ({}) : this.vm ? this.vm.externalModulesExecutor.createRequire(filename) : createRequire(filename);
206
166
  }
207
167
  shouldInterop(path, mod) {
208
- if (this.options.interopDefault === false) return false;
209
168
  // never interop ESM modules
210
169
  // TODO: should also skip for `.js` with `type="module"`
211
- return !path.endsWith(".mjs") && "default" in mod;
170
+ return this.options.interopDefault === false ? false : !path.endsWith(".mjs") && "default" in mod;
212
171
  }
213
172
  }
214
173
  function createImportMetaEnvProxy() {
@@ -220,9 +179,7 @@ function createImportMetaEnvProxy() {
220
179
  ];
221
180
  return new Proxy(process.env, {
222
181
  get(_, key) {
223
- if (typeof key !== "string") return void 0;
224
- if (booleanKeys.includes(key)) return !!process.env[key];
225
- return process.env[key];
182
+ return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
226
183
  },
227
184
  set(_, key, value) {
228
185
  if (typeof key !== "string") return true;
@@ -239,12 +196,8 @@ function updateStyle(id, css) {
239
196
  element.textContent = css;
240
197
  return;
241
198
  }
242
- const head = document.querySelector("head");
243
- const style = document.createElement("style");
244
- style.setAttribute("type", "text/css");
245
- style.setAttribute("data-vite-dev-id", id);
246
- style.textContent = css;
247
- head?.appendChild(style);
199
+ const head = document.querySelector("head"), style = document.createElement("style");
200
+ style.setAttribute("type", "text/css"), style.setAttribute("data-vite-dev-id", id), style.textContent = css, head?.appendChild(style);
248
201
  }
249
202
  function removeStyle(id) {
250
203
  if (typeof document === "undefined") return;
@@ -280,13 +233,11 @@ function getDefaultRequestStubs(context) {
280
233
  return { "/@vite/client": clientStub };
281
234
  }
282
235
  function exportAll(exports, sourceModule) {
283
- // #1120 when a module exports itself it causes
284
- // call stack error
285
- if (exports === sourceModule) return;
286
- if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;
287
- for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
288
- defineExport(exports, key, () => sourceModule[key]);
289
- } catch {}
236
+ if (exports !== sourceModule && !(isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise)) {
237
+ for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
238
+ defineExport(exports, key, () => sourceModule[key]);
239
+ } catch {}
240
+ }
290
241
  }
291
242
  // keep consistency with Vite on how exports are defined
292
243
  function defineExport(exports, key, value) {
@@ -307,16 +258,14 @@ function interopModule(mod) {
307
258
  };
308
259
  let defaultExport = "default" in mod ? mod.default : mod;
309
260
  if (!isPrimitive(defaultExport) && "__esModule" in defaultExport) {
310
- mod = defaultExport;
311
- if ("default" in defaultExport) defaultExport = defaultExport.default;
261
+ if (mod = defaultExport, "default" in defaultExport) defaultExport = defaultExport.default;
312
262
  }
313
263
  return {
314
264
  mod,
315
265
  defaultExport
316
266
  };
317
267
  }
318
- const VALID_ID_PREFIX = `/@id/`;
319
- const NULL_BYTE_PLACEHOLDER = `__x00__`;
268
+ const VALID_ID_PREFIX = `/@id/`, NULL_BYTE_PLACEHOLDER = `__x00__`;
320
269
  function wrapId(id) {
321
270
  return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
322
271
  }
@@ -1,6 +1,6 @@
1
1
  export { VitestModuleEvaluator } from './module-evaluator.js';
2
- export { a as VITEST_VM_CONTEXT_SYMBOL, V as VitestModuleRunner, s as startVitestModuleRunner } from './chunks/startModuleRunner.C8FtT_BY.js';
3
- export { g as getWorkerState } from './chunks/utils.B9FY3b73.js';
2
+ export { a as VITEST_VM_CONTEXT_SYMBOL, V as VitestModuleRunner, s as startVitestModuleRunner } from './chunks/startModuleRunner.C8TW8zTN.js';
3
+ export { g as getWorkerState } from './chunks/utils.C7__0Iv5.js';
4
4
  import 'node:module';
5
5
  import 'node:url';
6
6
  import 'node:vm';
package/dist/node.d.ts CHANGED
@@ -3,12 +3,12 @@ import { InlineConfig, UserConfig as UserConfig$1, Plugin, ResolvedConfig as Res
3
3
  export { vite as Vite };
4
4
  export { esbuildVersion, isCSSRequest, isFileServingAllowed, parseAst, parseAstAsync, rollupVersion, version as viteVersion } from 'vite';
5
5
  import { IncomingMessage } from 'node:http';
6
- import { h as ResolvedConfig, f as UserConfig, i as VitestRunMode, j as VitestOptions, V as Vitest, A as ApiConfig, T as TestProject, k as TestSequencer, l as TestSpecification, L as Logger } from './chunks/reporters.d.CYE9sT5z.js';
7
- export { ap as BaseCoverageOptions, K as BenchmarkUserOptions, N as BrowserBuiltinProvider, Q as BrowserCommand, X as BrowserCommandContext, Y as BrowserConfigOptions, Z as BrowserInstanceOption, _ as BrowserModuleMocker, $ as BrowserOrchestrator, a0 as BrowserProvider, a1 as BrowserProviderInitializationOptions, a2 as BrowserProviderModule, a3 as BrowserProviderOptions, a4 as BrowserScript, a5 as BrowserServerState, a6 as BrowserServerStateSession, ad as BuiltinEnvironment, a7 as CDPSession, ae as CSSModuleScopeStrategy, aq as CoverageIstanbulOptions, ar as CoverageOptions, as as CoverageProvider, at as CoverageProviderModule, au as CoverageReporter, c as CoverageV8Options, av as CustomProviderOptions, af as DepsOptimizationOptions, ag as EnvironmentOptions, H as HTMLOptions, I as InlineConfig, q as JUnitOptions, J as JsonOptions, M as ModuleDiagnostic, O as OnServerRestartHandler, m as OnTestsRerunHandler, a8 as ParentProjectBrowser, ah as Pool, ai as PoolOptions, P as ProcessPool, a9 as ProjectBrowser, aj as ProjectConfig, b as ReportContext, ax as ReportedHookContext, ay as Reporter, al as ResolveSnapshotPathHandler, am as ResolveSnapshotPathHandlerContext, aa as ResolvedBrowserOptions, R as ResolvedCoverageOptions, ak as ResolvedProjectConfig, S as SerializedTestProject, r as TaskOptions, s as TestCase, t as TestCollection, u as TestDiagnostic, v as TestModule, w as TestModuleState, x as TestResult, y as TestResultFailed, z as TestResultPassed, B as TestResultSkipped, az as TestRunEndReason, aw as TestRunResult, G as TestSequencerConstructor, D as TestState, E as TestSuite, F as TestSuiteState, ab as ToMatchScreenshotComparators, ac as ToMatchScreenshotOptions, an as TypecheckConfig, U as UserWorkspaceConfig, ao as VitestEnvironment, n as VitestPackageInstaller, W as WatcherTriggerPattern, o as WorkspaceSpec, p as getFilePoolName } from './chunks/reporters.d.CYE9sT5z.js';
6
+ import { h as ResolvedConfig, f as UserConfig, i as VitestRunMode, j as VitestOptions, V as Vitest, A as ApiConfig, T as TestProject, k as TestSequencer, l as TestSpecification, L as Logger } from './chunks/reporters.d.CqR9-CDJ.js';
7
+ export { ap as BaseCoverageOptions, K as BenchmarkUserOptions, N as BrowserBuiltinProvider, Q as BrowserCommand, X as BrowserCommandContext, Y as BrowserConfigOptions, Z as BrowserInstanceOption, _ as BrowserModuleMocker, $ as BrowserOrchestrator, a0 as BrowserProvider, a1 as BrowserProviderInitializationOptions, a2 as BrowserProviderModule, a3 as BrowserProviderOptions, a4 as BrowserScript, a5 as BrowserServerState, a6 as BrowserServerStateSession, ad as BuiltinEnvironment, a7 as CDPSession, ae as CSSModuleScopeStrategy, aq as CoverageIstanbulOptions, ar as CoverageOptions, as as CoverageProvider, at as CoverageProviderModule, au as CoverageReporter, c as CoverageV8Options, av as CustomProviderOptions, af as DepsOptimizationOptions, ag as EnvironmentOptions, H as HTMLOptions, I as InlineConfig, q as JUnitOptions, J as JsonOptions, M as ModuleDiagnostic, O as OnServerRestartHandler, m as OnTestsRerunHandler, a8 as ParentProjectBrowser, ah as Pool, ai as PoolOptions, P as ProcessPool, a9 as ProjectBrowser, aj as ProjectConfig, b as ReportContext, ax as ReportedHookContext, ay as Reporter, al as ResolveSnapshotPathHandler, am as ResolveSnapshotPathHandlerContext, aa as ResolvedBrowserOptions, R as ResolvedCoverageOptions, ak as ResolvedProjectConfig, S as SerializedTestProject, r as TaskOptions, s as TestCase, t as TestCollection, u as TestDiagnostic, v as TestModule, w as TestModuleState, x as TestResult, y as TestResultFailed, z as TestResultPassed, B as TestResultSkipped, az as TestRunEndReason, aw as TestRunResult, G as TestSequencerConstructor, D as TestState, E as TestSuite, F as TestSuiteState, ab as ToMatchScreenshotComparators, ac as ToMatchScreenshotOptions, an as TypecheckConfig, U as UserWorkspaceConfig, ao as VitestEnvironment, n as VitestPackageInstaller, W as WatcherTriggerPattern, o as WorkspaceSpec, p as getFilePoolName } from './chunks/reporters.d.CqR9-CDJ.js';
8
8
  import { R as RuntimeRPC } from './chunks/worker.d.D9QWnzAe.js';
9
9
  export { T as TestExecutionType } from './chunks/worker.d.D9QWnzAe.js';
10
10
  import { Writable } from 'node:stream';
11
- export { V as VitestPluginContext } from './chunks/plugin.d.CvOlgjxK.js';
11
+ export { V as VitestPluginContext } from './chunks/plugin.d.DuiQJfUL.js';
12
12
  export { W as WorkerContext } from './chunks/worker.d.Db-UVmXc.js';
13
13
  import { Debugger } from 'debug';
14
14
  import './chunks/global.d.K6uBQHzY.js';
package/dist/node.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as vite from 'vite';
2
2
  import { resolveConfig as resolveConfig$1, mergeConfig } from 'vite';
3
3
  export { esbuildVersion, isCSSRequest, isFileServingAllowed, parseAst, parseAstAsync, rollupVersion, version as viteVersion } from 'vite';
4
- import { V as Vitest, a as VitestPlugin } from './chunks/cli-api.COn58yrl.js';
5
- export { G as GitNotFoundError, F as TestsNotFoundError, b as VitestPackageInstaller, e as createViteLogger, c as createVitest, i as isValidApiRequest, d as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.COn58yrl.js';
6
- export { p as parseCLI } from './chunks/cac.CKnbxhn2.js';
7
- import { r as resolveConfig$2 } from './chunks/coverage.B6cReEn1.js';
8
- export { b as BaseSequencer, c as createMethodsRPC, g as getFilePoolName, a as resolveApiServerConfig } from './chunks/coverage.B6cReEn1.js';
4
+ import { V as Vitest, a as VitestPlugin } from './chunks/cli-api.CZz3evYC.js';
5
+ export { G as GitNotFoundError, F as TestsNotFoundError, b as VitestPackageInstaller, e as createViteLogger, c as createVitest, i as isValidApiRequest, d as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.CZz3evYC.js';
6
+ export { p as parseCLI } from './chunks/cac.WE-urWw5.js';
7
+ import { r as resolveConfig$2 } from './chunks/coverage.BPRS6xgn.js';
8
+ export { b as BaseSequencer, c as createMethodsRPC, g as getFilePoolName, a as resolveApiServerConfig } from './chunks/coverage.BPRS6xgn.js';
9
9
  import { slash, deepClone } from '@vitest/utils';
10
10
  import { f as findUp } from './chunks/index.X0nbfr6-.js';
11
11
  import { resolve } from 'pathe';
@@ -18,9 +18,9 @@ import './chunks/coverage.D_JHT54q.js';
18
18
  import 'node:path';
19
19
  import '@vitest/snapshot/manager';
20
20
  import './chunks/index.Bgo3tNWt.js';
21
- import './chunks/index.DQhAfQQU.js';
21
+ import './chunks/index.VNI-1z5c.js';
22
22
  import 'node:fs/promises';
23
- import './chunks/typechecker.BgoW4nTA.js';
23
+ import './chunks/typechecker.Cd1wvxUM.js';
24
24
  import 'node:os';
25
25
  import 'node:perf_hooks';
26
26
  import '@vitest/utils/source-map';
@@ -52,9 +52,9 @@ import 'tinyglobby';
52
52
  import 'magic-string';
53
53
  import '@vitest/mocker/node';
54
54
  import './chunks/defaults.CXFFjsi8.js';
55
- import './chunks/resolver.D5bG4zy5.js';
55
+ import './chunks/resolver.Bx6lE0iq.js';
56
56
  import 'es-module-lexer';
57
- import './chunks/index.DgN0Zk9a.js';
57
+ import './chunks/index.7w0eqmYM.js';
58
58
  import 'node:assert';
59
59
  import '@vitest/utils/error';
60
60
  import 'node:readline';
@@ -68,20 +68,14 @@ import 'readline';
68
68
 
69
69
  // this is only exported as a public function and not used inside vitest
70
70
  async function resolveConfig(options = {}, viteOverrides = {}) {
71
- const root = slash(resolve(options.root || process.cwd()));
72
- const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
71
+ const root = slash(resolve(options.root || process.cwd())), configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
73
72
  options.config = configPath;
74
- const vitest = new Vitest("test", deepClone(options));
75
- const config = await resolveConfig$1(mergeConfig({
73
+ const vitest = new Vitest("test", deepClone(options)), config = await resolveConfig$1(mergeConfig({
76
74
  configFile: configPath,
77
75
  mode: options.mode || "test",
78
76
  plugins: [await VitestPlugin(options, vitest)]
79
- }, mergeConfig(viteOverrides, { root: options.root })), "serve");
80
- // Reflect just to avoid type error
81
- const updatedOptions = Reflect.get(config, "_vitest");
82
- const vitestConfig = resolveConfig$2(vitest, updatedOptions, config);
83
- await vitest.close();
84
- return {
77
+ }, mergeConfig(viteOverrides, { root: options.root })), "serve"), updatedOptions = Reflect.get(config, "_vitest"), vitestConfig = resolveConfig$2(vitest, updatedOptions, config);
78
+ return await vitest.close(), {
85
79
  viteConfig: config,
86
80
  vitestConfig
87
81
  };
@@ -1,7 +1,7 @@
1
- export { aN as BaseReporter, aO as BenchmarkBuiltinReporters, aA as BenchmarkReporter, aB as BenchmarkReportsMap, aP as BuiltinReporterOptions, aQ as BuiltinReporters, aC as DefaultReporter, aD as DotReporter, aE as GithubActionsReporter, aF as HangingProcessReporter, aH as JUnitReporter, aR as JsonAssertionResult, aG as JsonReporter, aS as JsonTestResult, aT as JsonTestResults, ax as ReportedHookContext, ay as Reporter, aI as ReportersMap, aJ as TapFlatReporter, aK as TapReporter, az as TestRunEndReason, aL as VerboseBenchmarkReporter, aM as VerboseReporter } from './chunks/reporters.d.CYE9sT5z.js';
1
+ export { aN as BaseReporter, aO as BenchmarkBuiltinReporters, aA as BenchmarkReporter, aB as BenchmarkReportsMap, aP as BuiltinReporterOptions, aQ as BuiltinReporters, aC as DefaultReporter, aD as DotReporter, aE as GithubActionsReporter, aF as HangingProcessReporter, aH as JUnitReporter, aR as JsonAssertionResult, aG as JsonReporter, aS as JsonTestResult, aT as JsonTestResults, ax as ReportedHookContext, ay as Reporter, aI as ReportersMap, aJ as TapFlatReporter, aK as TapReporter, az as TestRunEndReason, aL as VerboseBenchmarkReporter, aM as VerboseReporter } from './chunks/reporters.d.CqR9-CDJ.js';
2
2
  import '@vitest/runner';
3
- import './chunks/environment.d.2fYMoz3o.js';
4
3
  import '@vitest/utils';
4
+ import './chunks/environment.d.2fYMoz3o.js';
5
5
  import 'node:stream';
6
6
  import 'vite';
7
7
  import 'node:console';
package/dist/reporters.js CHANGED
@@ -1,9 +1,9 @@
1
- export { D as DefaultReporter, a as DotReporter, G as GithubActionsReporter, H as HangingProcessReporter, b as JUnitReporter, J as JsonReporter, R as ReportersMap, T as TapFlatReporter, c as TapReporter, V as VerboseReporter } from './chunks/index.DQhAfQQU.js';
2
- export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.DgN0Zk9a.js';
1
+ export { D as DefaultReporter, a as DotReporter, G as GithubActionsReporter, H as HangingProcessReporter, b as JUnitReporter, J as JsonReporter, R as ReportersMap, T as TapFlatReporter, c as TapReporter, V as VerboseReporter } from './chunks/index.VNI-1z5c.js';
2
+ export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.7w0eqmYM.js';
3
3
  import 'node:fs';
4
4
  import 'node:fs/promises';
5
5
  import 'pathe';
6
- import './chunks/typechecker.BgoW4nTA.js';
6
+ import './chunks/typechecker.Cd1wvxUM.js';
7
7
  import 'node:os';
8
8
  import 'node:perf_hooks';
9
9
  import '@vitest/utils/source-map';
package/dist/runners.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import { updateTask } from '@vitest/runner';
2
2
  import { createDefer, getSafeTimers } from '@vitest/utils';
3
- import { a as getBenchOptions, g as getBenchFn } from './chunks/benchmark.CtuRzf-i.js';
4
- import { g as getWorkerState } from './chunks/utils.B9FY3b73.js';
3
+ import { a as getBenchOptions, g as getBenchFn } from './chunks/benchmark.UW6Ezvxy.js';
4
+ import { g as getWorkerState } from './chunks/utils.C7__0Iv5.js';
5
5
  import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
6
6
  import { getTests, getNames, getTestName } from '@vitest/runner/utils';
7
7
  import { processError } from '@vitest/utils/error';
8
8
  import { normalize } from 'pathe';
9
- import { g as getSnapshotClient, i as inject, c as createExpect, v as vi } from './chunks/vi.DGAfBY4R.js';
10
- import { r as rpc } from './chunks/rpc.DGoW_Vl-.js';
9
+ import { g as getSnapshotClient, i as inject, c as createExpect, v as vi } from './chunks/vi.BfdOiD4j.js';
10
+ import { r as rpc } from './chunks/rpc.RpPylpp0.js';
11
11
  import 'chai';
12
12
  import './chunks/_commonjsHelpers.BFTU3MAI.js';
13
13
  import '@vitest/snapshot';
14
14
  import '@vitest/spy';
15
15
  import '@vitest/utils/source-map';
16
- import './chunks/date.Bq6ZW5rf.js';
16
+ import './chunks/date.-jtEtIeV.js';
17
17
  import './chunks/index.Bgo3tNWt.js';
18
18
 
19
19
  function createBenchmarkResult(name) {
@@ -26,10 +26,7 @@ function createBenchmarkResult(name) {
26
26
  }
27
27
  const benchmarkTasks = /* @__PURE__ */ new WeakMap();
28
28
  async function runBenchmarkSuite(suite, runner) {
29
- const { Task, Bench } = await runner.importTinybench();
30
- const start = performance.now();
31
- const benchmarkGroup = [];
32
- const benchmarkSuiteGroup = [];
29
+ const { Task, Bench } = await runner.importTinybench(), start = performance.now(), benchmarkGroup = [], benchmarkSuiteGroup = [];
33
30
  for (const task of suite.tasks) {
34
31
  if (task.mode !== "run" && task.mode !== "queued") continue;
35
32
  if (task.meta?.benchmark) benchmarkGroup.push(task);
@@ -43,55 +40,38 @@ async function runBenchmarkSuite(suite, runner) {
43
40
  state: "run",
44
41
  startTime: start,
45
42
  benchmark: createBenchmarkResult(suite.name)
46
- };
47
- updateTask$1("suite-prepare", suite);
43
+ }, updateTask$1("suite-prepare", suite);
48
44
  const addBenchTaskListener = (task, benchmark) => {
49
45
  task.addEventListener("complete", (e) => {
50
- const task = e.task;
51
- const taskRes = task.result;
52
- const result = benchmark.result.benchmark;
53
- benchmark.result.state = "pass";
54
- Object.assign(result, taskRes);
46
+ const task = e.task, taskRes = task.result, result = benchmark.result.benchmark;
47
+ benchmark.result.state = "pass", Object.assign(result, taskRes);
55
48
  // compute extra stats and free raw samples as early as possible
56
49
  const samples = result.samples;
57
- result.sampleCount = samples.length;
58
- result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
59
- if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
50
+ if (result.sampleCount = samples.length, result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2, !runner.config.benchmark?.includeSamples) result.samples.length = 0;
60
51
  updateTask$1("test-finished", benchmark);
61
- }, { once: true });
62
- task.addEventListener("error", (e) => {
52
+ }, { once: true }), task.addEventListener("error", (e) => {
63
53
  const task = e.task;
64
54
  defer.reject(benchmark ? task.result.error : e);
65
55
  }, { once: true });
66
56
  };
67
57
  benchmarkGroup.forEach((benchmark) => {
68
- const options = getBenchOptions(benchmark);
69
- const benchmarkInstance = new Bench(options);
70
- const benchmarkFn = getBenchFn(benchmark);
58
+ const options = getBenchOptions(benchmark), benchmarkInstance = new Bench(options), benchmarkFn = getBenchFn(benchmark);
71
59
  benchmark.result = {
72
60
  state: "run",
73
61
  startTime: start,
74
62
  benchmark: createBenchmarkResult(benchmark.name)
75
63
  };
76
64
  const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
77
- benchmarkTasks.set(benchmark, task);
78
- addBenchTaskListener(task, benchmark);
65
+ benchmarkTasks.set(benchmark, task), addBenchTaskListener(task, benchmark);
79
66
  });
80
- const { setTimeout } = getSafeTimers();
81
- const tasks = [];
67
+ const { setTimeout } = getSafeTimers(), tasks = [];
82
68
  for (const benchmark of benchmarkGroup) {
83
69
  const task = benchmarkTasks.get(benchmark);
84
- updateTask$1("test-prepare", benchmark);
85
- await task.warmup();
86
- tasks.push([await new Promise((resolve) => setTimeout(async () => {
70
+ updateTask$1("test-prepare", benchmark), await task.warmup(), tasks.push([await new Promise((resolve) => setTimeout(async () => {
87
71
  resolve(await task.run());
88
72
  })), benchmark]);
89
73
  }
90
- suite.result.duration = performance.now() - start;
91
- suite.result.state = "pass";
92
- updateTask$1("suite-finished", suite);
93
- defer.resolve(null);
94
- await defer;
74
+ suite.result.duration = performance.now() - start, suite.result.state = "pass", updateTask$1("suite-finished", suite), defer.resolve(null), await defer;
95
75
  }
96
76
  function updateTask$1(event, task) {
97
77
  updateTask(event, task, runner);
@@ -147,8 +127,7 @@ class VitestTestRunner {
147
127
  this.workerState.onCleanup(listener);
148
128
  }
149
129
  onAfterRunFiles() {
150
- this.snapshotClient.clear();
151
- this.workerState.current = void 0;
130
+ this.snapshotClient.clear(), this.workerState.current = void 0;
152
131
  }
153
132
  getWorkerContext() {
154
133
  return workerContext;
@@ -165,9 +144,7 @@ class VitestTestRunner {
165
144
  if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
166
145
  let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
167
146
  for (const key of result.uncheckedKeys) message += `· ${key}\n`;
168
- suite.result.errors ??= [];
169
- suite.result.errors.push(processError(new Error(message)));
170
- suite.result.state = "fail";
147
+ suite.result.errors ??= [], suite.result.errors.push(processError(new Error(message))), suite.result.state = "fail";
171
148
  }
172
149
  await rpc().snapshotSaved(result);
173
150
  }
@@ -187,8 +164,7 @@ class VitestTestRunner {
187
164
  }
188
165
  async onBeforeRunTask(test) {
189
166
  if (this.cancelRun) test.mode = "skip";
190
- if (test.mode !== "run" && test.mode !== "queued") return;
191
- this.workerState.current = test;
167
+ test.mode !== "run" && test.mode !== "queued" || (this.workerState.current = test);
192
168
  }
193
169
  async onBeforeRunSuite(suite) {
194
170
  if (this.cancelRun) suite.mode = "skip";
@@ -197,9 +173,7 @@ class VitestTestRunner {
197
173
  this.workerState.current = suite;
198
174
  }
199
175
  onBeforeTryTask(test) {
200
- clearModuleMocks(this.config);
201
- this.snapshotClient.clearTest(test.file.filepath, test.id);
202
- setState({
176
+ clearModuleMocks(this.config), this.snapshotClient.clearTest(test.file.filepath, test.id), setState({
203
177
  assertionCalls: 0,
204
178
  isExpectingAssertions: false,
205
179
  isExpectingAssertionsError: null,
@@ -219,14 +193,12 @@ class VitestTestRunner {
219
193
  // create error during the test initialization so we have a nice stack trace
220
194
  if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
221
195
  let _expect;
222
- Object.defineProperty(context, "expect", { get() {
196
+ return Object.defineProperty(context, "expect", { get() {
223
197
  if (!_expect) _expect = createExpect(context.task);
224
198
  return _expect;
225
- } });
226
- Object.defineProperty(context, "_local", { get() {
199
+ } }), Object.defineProperty(context, "_local", { get() {
227
200
  return _expect != null;
228
- } });
229
- return context;
201
+ } }), context;
230
202
  }
231
203
  getImportDurations() {
232
204
  const entries = [...this.workerState.moduleExecutionInfo?.entries() ?? []];
package/dist/snapshot.js CHANGED
@@ -1,4 +1,4 @@
1
- export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.4JV5OXkt.js';
1
+ export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.BOqcT2jW.js';
2
2
  import '@vitest/snapshot/environment';
3
- import './chunks/utils.B9FY3b73.js';
3
+ import './chunks/utils.C7__0Iv5.js';
4
4
  import '@vitest/utils';
package/dist/suite.js CHANGED
@@ -1,5 +1,5 @@
1
- export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.CtuRzf-i.js';
1
+ export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.UW6Ezvxy.js';
2
2
  export { createTaskCollector, getCurrentSuite, getCurrentTest, getFn, getHooks, setFn, setHooks } from '@vitest/runner';
3
3
  export { createChainable } from '@vitest/runner/utils';
4
4
  import '@vitest/utils';
5
- import './chunks/utils.B9FY3b73.js';
5
+ import './chunks/utils.C7__0Iv5.js';