vitest 4.0.0-beta.8 → 4.0.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 (85) hide show
  1. package/LICENSE.md +86 -102
  2. package/browser/context.d.ts +7 -0
  3. package/browser/context.js +20 -0
  4. package/dist/browser.d.ts +26 -9
  5. package/dist/browser.js +17 -7
  6. package/dist/chunks/base.CtHM3ryk.js +128 -0
  7. package/dist/chunks/{benchmark.UW6Ezvxy.js → benchmark.DHKMYAts.js} +2 -2
  8. package/dist/chunks/{browser.d.DOMmqJQx.d.ts → browser.d.B9iJzZyn.d.ts} +3 -3
  9. package/dist/chunks/{cac.By1HvRIk.js → cac.B99MQg-w.js} +47 -91
  10. package/dist/chunks/{cli-api.C-JHgQgp.js → cli-api.PwHwIMss.js} +1544 -310
  11. package/dist/chunks/{config.d._GBBbReY.d.ts → config.d.u2CUDWwS.d.ts} +6 -19
  12. package/dist/chunks/{console.B0quX7yH.js → console.CTJL2nuH.js} +4 -6
  13. package/dist/chunks/{coverage.DarITf6U.js → coverage.FU3w4IrQ.js} +128 -1142
  14. package/dist/chunks/{creator.KEg6n5IC.js → creator.DucAaYBz.js} +10 -37
  15. package/dist/chunks/{defaults.CXFFjsi8.js → defaults.BOqNVLsY.js} +0 -1
  16. package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
  17. package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
  18. package/dist/chunks/{global.d.K6uBQHzY.d.ts → global.d.BgJSTpgQ.d.ts} +2 -17
  19. package/dist/chunks/{globals.lgsmH00r.js → globals.BGT_RUsD.js} +12 -9
  20. package/dist/chunks/{index.BuwjkI-q.js → index.BdSLhLDZ.js} +3 -3
  21. package/dist/chunks/{index.DfviD7lX.js → index.CbWINfS7.js} +49 -21
  22. package/dist/chunks/{index.AzwzFtyi.js → index.CcRZ6fUh.js} +1493 -114
  23. package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
  24. package/dist/chunks/{index.AR8aAkCC.js → index.RwjEGCQ0.js} +7 -8
  25. package/dist/chunks/init-forks.DSafeltJ.js +54 -0
  26. package/dist/chunks/init-threads.SUtZ-067.js +17 -0
  27. package/dist/chunks/init.B2EESLQM.js +213 -0
  28. package/dist/chunks/{inspector.CvQD-Nie.js → inspector.DLZxSeU3.js} +2 -6
  29. package/dist/chunks/{moduleRunner.d.CX4DuqOx.d.ts → moduleRunner.d.YtNsMIoJ.d.ts} +12 -14
  30. package/dist/chunks/{node.BOqcT2jW.js → node.BwAWWjHZ.js} +3 -4
  31. package/dist/chunks/{plugin.d.CHe6slQs.d.ts → plugin.d.DQU1R5px.d.ts} +1 -1
  32. package/dist/chunks/{reporters.d.37tJQ2uV.d.ts → reporters.d.BMKt7f6I.d.ts} +1066 -1030
  33. package/dist/chunks/{index.CsFXYRkW.js → resolveSnapshotEnvironment.DJJKMKxb.js} +18 -24
  34. package/dist/chunks/{rpc.RpPylpp0.js → rpc.cD77ENhU.js} +13 -14
  35. package/dist/chunks/{setup-common.hLGRxhC8.js → setup-common.DR1sucx6.js} +8 -8
  36. package/dist/chunks/{startModuleRunner.C8TW8zTN.js → startModuleRunner.C2tTvmF9.js} +131 -110
  37. package/dist/chunks/test.C3RPt8JR.js +214 -0
  38. package/dist/chunks/{utils.C7__0Iv5.js → utils.CG9h5ccR.js} +3 -15
  39. package/dist/chunks/{vi.BfdOiD4j.js → vi.BZvkKVkM.js} +73 -176
  40. package/dist/chunks/{vm.BHBje7cC.js → vm.DBeOXrP9.js} +29 -33
  41. package/dist/chunks/{worker.d.DYlqbejz.d.ts → worker.d.BFk-vvBU.d.ts} +42 -6
  42. package/dist/cli.js +12 -11
  43. package/dist/config.cjs +0 -1
  44. package/dist/config.d.ts +12 -14
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +8 -7
  47. package/dist/coverage.js +3 -14
  48. package/dist/environments.d.ts +3 -6
  49. package/dist/environments.js +1 -1
  50. package/dist/index.d.ts +24 -30
  51. package/dist/index.js +12 -11
  52. package/dist/module-evaluator.d.ts +6 -4
  53. package/dist/module-evaluator.js +14 -16
  54. package/dist/module-runner.js +5 -5
  55. package/dist/node.d.ts +83 -27
  56. package/dist/node.js +23 -20
  57. package/dist/reporters.d.ts +11 -10
  58. package/dist/reporters.js +12 -11
  59. package/dist/runners.d.ts +1 -1
  60. package/dist/runners.js +14 -216
  61. package/dist/snapshot.js +3 -3
  62. package/dist/suite.js +4 -3
  63. package/dist/worker.d.ts +26 -0
  64. package/dist/worker.js +45 -166
  65. package/dist/workers/forks.js +41 -35
  66. package/dist/workers/runVmTests.js +25 -22
  67. package/dist/workers/threads.js +41 -23
  68. package/dist/workers/vmForks.js +26 -39
  69. package/dist/workers/vmThreads.js +26 -29
  70. package/package.json +48 -35
  71. package/worker.d.ts +1 -0
  72. package/browser.d.ts +0 -1
  73. package/dist/chunks/base.BXI97p6t.js +0 -39
  74. package/dist/chunks/environment.d.2fYMoz3o.d.ts +0 -66
  75. package/dist/chunks/moduleTransport.I-bgQy0S.js +0 -19
  76. package/dist/chunks/resolver.Bx6lE0iq.js +0 -119
  77. package/dist/chunks/runBaseTests.D6sfuWBM.js +0 -99
  78. package/dist/chunks/typechecker.DSo_maXz.js +0 -762
  79. package/dist/chunks/utils.C2YI6McM.js +0 -52
  80. package/dist/chunks/worker.d.BKu8cnnX.d.ts +0 -8
  81. package/dist/workers.d.ts +0 -38
  82. package/dist/workers.js +0 -31
  83. package/execute.d.ts +0 -1
  84. package/utils.d.ts +0 -1
  85. package/workers.d.ts +0 -1
package/dist/node.d.ts CHANGED
@@ -3,28 +3,27 @@ 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, k as TestSpecification, T as TestProject, P as Pool, l as TestSequencer, L as Logger } from './chunks/reporters.d.37tJQ2uV.js';
7
- export { an as BaseCoverageOptions, G as BenchmarkUserOptions, K as BrowserBuiltinProvider, N as BrowserCommand, Q as BrowserCommandContext, X as BrowserConfigOptions, Y as BrowserInstanceOption, Z as BrowserModuleMocker, _ as BrowserOrchestrator, $ as BrowserProvider, a0 as BrowserProviderInitializationOptions, a1 as BrowserProviderModule, a2 as BrowserProviderOptions, a3 as BrowserScript, a4 as BrowserServerState, a5 as BrowserServerStateSession, ac as BuiltinEnvironment, a6 as CDPSession, ad as CSSModuleScopeStrategy, ao as CoverageIstanbulOptions, ap as CoverageOptions, aq as CoverageProvider, ar as CoverageProviderModule, as as CoverageReporter, c as CoverageV8Options, at as CustomProviderOptions, ae as DepsOptimizationOptions, af as EnvironmentOptions, H as HTMLOptions, I as InlineConfig, o as JUnitOptions, J as JsonOptions, M as ModuleDiagnostic, O as OnServerRestartHandler, m as OnTestsRerunHandler, a7 as ParentProjectBrowser, ag as PoolOptions, a8 as ProjectBrowser, ah as ProjectConfig, b as ReportContext, av as ReportedHookContext, aw as Reporter, aj as ResolveSnapshotPathHandler, ak as ResolveSnapshotPathHandlerContext, a9 as ResolvedBrowserOptions, R as ResolvedCoverageOptions, ai as ResolvedProjectConfig, S as SerializedTestProject, p as TaskOptions, q as TestCase, r as TestCollection, s as TestDiagnostic, t as TestModule, u as TestModuleState, v as TestResult, w as TestResultFailed, x as TestResultPassed, y as TestResultSkipped, ax as TestRunEndReason, au as TestRunResult, F as TestSequencerConstructor, z as TestState, B as TestSuite, D as TestSuiteState, aa as ToMatchScreenshotComparators, ab as ToMatchScreenshotOptions, al as TypecheckConfig, U as UserWorkspaceConfig, am as VitestEnvironment, n as VitestPackageInstaller, W as WatcherTriggerPattern, E as experimental_getRunnerTask } from './chunks/reporters.d.37tJQ2uV.js';
6
+ import { h as ResolvedConfig, f as UserConfig, i as VitestRunMode, j as VitestOptions, V as Vitest, A as ApiConfig, k as TestSpecification, T as TestProject, P as PoolWorker, l as PoolOptions, m as WorkerRequest, n as TestSequencer, L as Logger } from './chunks/reporters.d.BMKt7f6I.js';
7
+ export { at as BaseCoverageOptions, Y as BenchmarkUserOptions, Z as BrowserBuiltinProvider, $ as BrowserCommand, a0 as BrowserCommandContext, a1 as BrowserConfigOptions, a2 as BrowserInstanceOption, a3 as BrowserModuleMocker, a4 as BrowserOrchestrator, a5 as BrowserProvider, a6 as BrowserProviderOption, a7 as BrowserScript, a8 as BrowserServerFactory, a9 as BrowserServerOptions, aa as BrowserServerState, ab as BrowserServerStateSession, ai as BuiltinEnvironment, ac as CDPSession, aj as CSSModuleScopeStrategy, au as CoverageIstanbulOptions, av as CoverageOptions, aw as CoverageProvider, ax as CoverageProviderModule, ay as CoverageReporter, c as CoverageV8Options, az as CustomProviderOptions, ak as DepsOptimizationOptions, al as EnvironmentOptions, H as HTMLOptions, I as InlineConfig, t as JUnitOptions, J as JsonOptions, M as ModuleDiagnostic, O as OnServerRestartHandler, o as OnTestsRerunHandler, ad as ParentProjectBrowser, am as Pool, q as PoolRunnerInitializer, r as PoolTask, ae as ProjectBrowser, an as ProjectConfig, b as ReportContext, aB as ReportedHookContext, aC as Reporter, ap as ResolveSnapshotPathHandler, aq as ResolveSnapshotPathHandlerContext, af as ResolvedBrowserOptions, R as ResolvedCoverageOptions, ao as ResolvedProjectConfig, S as SerializedTestProject, u as TaskOptions, v as TestCase, w as TestCollection, x as TestDiagnostic, y as TestModule, z as TestModuleState, B as TestResult, D as TestResultFailed, E as TestResultPassed, F as TestResultSkipped, aD as TestRunEndReason, aA as TestRunResult, X as TestSequencerConstructor, G as TestState, K as TestSuite, N as TestSuiteState, ag as ToMatchScreenshotComparators, ah as ToMatchScreenshotOptions, ar as TypecheckConfig, U as UserWorkspaceConfig, as as VitestEnvironment, p as VitestPackageInstaller, W as WatcherTriggerPattern, s as WorkerResponse, _ as _BrowserNames, Q as experimental_getRunnerTask } from './chunks/reporters.d.BMKt7f6I.js';
8
8
  import { Awaitable } from '@vitest/utils';
9
9
  export { SerializedError } from '@vitest/utils';
10
- import { R as RuntimeRPC } from './chunks/worker.d.DYlqbejz.js';
11
- export { T as TestExecutionType } from './chunks/worker.d.DYlqbejz.js';
10
+ import { R as RuntimeRPC, C as ContextRPC } from './chunks/worker.d.BFk-vvBU.js';
11
+ export { T as TestExecutionType } from './chunks/worker.d.BFk-vvBU.js';
12
12
  import { Writable } from 'node:stream';
13
- export { V as VitestPluginContext } from './chunks/plugin.d.CHe6slQs.js';
14
- export { W as WorkerContext } from './chunks/worker.d.BKu8cnnX.js';
13
+ export { V as VitestPluginContext } from './chunks/plugin.d.DQU1R5px.js';
15
14
  import { Debugger } from 'debug';
16
- import './chunks/global.d.K6uBQHzY.js';
15
+ import './chunks/global.d.BgJSTpgQ.js';
17
16
  export { Task as RunnerTask, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SequenceHooks, SequenceSetupFiles } from '@vitest/runner';
18
- export { b as RuntimeConfig } from './chunks/config.d._GBBbReY.js';
17
+ export { b as RuntimeConfig } from './chunks/config.d.u2CUDWwS.js';
19
18
  export { generateFileHash } from '@vitest/runner/utils';
20
- import './chunks/environment.d.2fYMoz3o.js';
21
19
  import '@vitest/mocker';
22
20
  import '@vitest/utils/source-map';
23
- import './chunks/browser.d.DOMmqJQx.js';
21
+ import 'vitest/browser';
22
+ import './chunks/browser.d.B9iJzZyn.js';
24
23
  import '@vitest/pretty-format';
25
24
  import '@vitest/snapshot';
26
25
  import '@vitest/utils/diff';
27
- import 'chai';
26
+ import '@vitest/expect';
28
27
  import 'vitest/optional-types.js';
29
28
  import './chunks/benchmark.d.DAaHLpsq.js';
30
29
  import 'tinybench';
@@ -33,8 +32,7 @@ import '@vitest/snapshot/manager';
33
32
  import 'node:fs';
34
33
  import 'node:console';
35
34
  import 'vite/module-runner';
36
- import 'node:worker_threads';
37
- import '@vitest/expect';
35
+ import './chunks/environment.d.CrsxCzP1.js';
38
36
 
39
37
  type RawErrsMap = Map<string, TscErrorInfo[]>;
40
38
  interface TscErrorInfo {
@@ -121,7 +119,6 @@ declare class GitNotFoundError extends Error {
121
119
 
122
120
  declare function VitestPlugin(options?: UserConfig, vitest?: Vitest): Promise<Plugin[]>;
123
121
 
124
- // this is only exported as a public function and not used inside vitest
125
122
  declare function resolveConfig(options?: UserConfig, viteOverrides?: UserConfig$1): Promise<{
126
123
  vitestConfig: ResolvedConfig;
127
124
  viteConfig: ResolvedConfig$1;
@@ -129,39 +126,99 @@ declare function resolveConfig(options?: UserConfig, viteOverrides?: UserConfig$
129
126
 
130
127
  declare function resolveFsAllow(projectRoot: string, rootConfigFile: string | false | undefined): string[];
131
128
 
132
- type RunWithFiles = (files: TestSpecification[], invalidates?: string[]) => Awaitable<void>;
129
+ type RunWithFiles = (files: TestSpecification[], invalidates?: string[]) => Promise<void>;
133
130
  interface ProcessPool {
134
131
  name: string;
135
132
  runTests: RunWithFiles;
136
133
  collectTests: RunWithFiles;
137
134
  close?: () => Awaitable<void>;
138
135
  }
139
- declare function getFilePoolName(project: TestProject): Pool;
136
+ declare function getFilePoolName(project: TestProject): ResolvedConfig["pool"];
140
137
 
141
138
  interface MethodsOptions {
142
139
  cacheFs?: boolean;
143
- // do not report files
144
140
  collect?: boolean;
145
141
  }
146
142
  declare function createMethodsRPC(project: TestProject, options?: MethodsOptions): RuntimeRPC;
147
143
 
144
+ /** @experimental */
145
+ declare class ForksPoolWorker implements PoolWorker {
146
+ readonly name: string;
147
+ readonly cacheFs: boolean;
148
+ protected readonly entrypoint: string;
149
+ protected execArgv: string[];
150
+ protected env: Partial<NodeJS.ProcessEnv>;
151
+ private _fork?;
152
+ constructor(options: PoolOptions);
153
+ on(event: string, callback: (arg: any) => void): void;
154
+ off(event: string, callback: (arg: any) => void): void;
155
+ send(message: WorkerRequest): void;
156
+ start(): Promise<void>;
157
+ stop(): Promise<void>;
158
+ deserialize(data: unknown): unknown;
159
+ private get fork();
160
+ }
161
+
162
+ /** @experimental */
163
+ declare class ThreadsPoolWorker implements PoolWorker {
164
+ readonly name: string;
165
+ protected readonly entrypoint: string;
166
+ protected execArgv: string[];
167
+ protected env: Partial<NodeJS.ProcessEnv>;
168
+ private _thread?;
169
+ constructor(options: PoolOptions);
170
+ on(event: string, callback: (arg: any) => void): void;
171
+ off(event: string, callback: (arg: any) => void): void;
172
+ send(message: WorkerRequest): void;
173
+ start(): Promise<void>;
174
+ stop(): Promise<void>;
175
+ deserialize(data: unknown): unknown;
176
+ private get thread();
177
+ }
178
+
179
+ /** @experimental */
180
+ declare class TypecheckPoolWorker implements PoolWorker {
181
+ readonly name: string;
182
+ private readonly project;
183
+ private _eventEmitter;
184
+ constructor(options: PoolOptions);
185
+ start(): Promise<void>;
186
+ stop(): Promise<void>;
187
+ canReuse(): boolean;
188
+ send(message: WorkerRequest): void;
189
+ on(event: string, callback: (arg: any) => any): void;
190
+ off(event: string, callback: (arg: any) => any): void;
191
+ deserialize(data: unknown): unknown;
192
+ }
193
+
194
+ /** @experimental */
195
+ declare class VmForksPoolWorker extends ForksPoolWorker {
196
+ readonly name = "vmForks";
197
+ readonly reportMemory: true;
198
+ protected readonly entrypoint: string;
199
+ constructor(options: PoolOptions);
200
+ }
201
+
202
+ /** @experimental */
203
+ declare class VmThreadsPoolWorker extends ThreadsPoolWorker {
204
+ readonly name = "vmThreads";
205
+ readonly reportMemory: true;
206
+ protected readonly entrypoint: string;
207
+ constructor(options: PoolOptions);
208
+ }
209
+
148
210
  declare class BaseSequencer implements TestSequencer {
149
211
  protected ctx: Vitest;
150
212
  constructor(ctx: Vitest);
151
- // async so it can be extended by other sequelizers
152
213
  shard(files: TestSpecification[]): Promise<TestSpecification[]>;
153
- // async so it can be extended by other sequelizers
154
214
  sort(files: TestSpecification[]): Promise<TestSpecification[]>;
155
- // Calculate distributed shard range [start, end] distributed equally
156
215
  private calculateShardRange;
157
216
  }
158
217
 
159
218
  declare function registerConsoleShortcuts(ctx: Vitest, stdin: NodeJS.ReadStream | undefined, stdout: NodeJS.WriteStream | Writable): () => void;
160
219
 
161
- // This is copy-pasted and needs to be synced from time to time. Ideally, Vite's `createLogger` should accept a custom `console`
162
- // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/logger.ts?rgh-link-date=2024-10-16T23%3A29%3A19Z
163
- // When Vitest supports only Vite 6 and above, we can use Vite's `createLogger({ console })`
164
- // https://github.com/vitejs/vite/pull/18379
220
+ interface WorkerContext extends ContextRPC {}
221
+
165
222
  declare function createViteLogger(console: Logger, level?: LogLevel, options?: LoggerOptions): Logger$1;
166
223
 
167
224
  declare const rootDir: string;
@@ -173,8 +230,7 @@ declare const version: string;
173
230
 
174
231
  declare const createViteServer: typeof vite.createServer;
175
232
 
176
- // rolldownVersion is exported only by rolldown-vite
177
233
  declare const rolldownVersion: string | undefined;
178
234
 
179
- export { ApiConfig, BaseSequencer, GitNotFoundError, Pool, ResolvedConfig, TestProject, TestSequencer, TestSpecification, UserConfig as TestUserConfig, FilesNotFoundError as TestsNotFoundError, Vitest, VitestOptions, VitestPlugin, VitestRunMode, createDebugger, createMethodsRPC, createViteLogger, createViteServer, createVitest, distDir, escapeTestName, getFilePoolName, isValidApiRequest, parseCLI, registerConsoleShortcuts, resolveApiServerConfig, resolveConfig, resolveFsAllow, rolldownVersion, rootDir, startVitest, version };
180
- export type { CliParseOptions, ProcessPool, CollectLineNumbers as TypeCheckCollectLineNumbers, CollectLines as TypeCheckCollectLines, Context as TypeCheckContext, TscErrorInfo as TypeCheckErrorInfo, RawErrsMap as TypeCheckRawErrorsMap, RootAndTarget as TypeCheckRootAndTarget };
235
+ export { ApiConfig, BaseSequencer, ForksPoolWorker, GitNotFoundError, PoolOptions, PoolWorker, ResolvedConfig, TestProject, TestSequencer, TestSpecification, UserConfig as TestUserConfig, FilesNotFoundError as TestsNotFoundError, ThreadsPoolWorker, TypecheckPoolWorker, Vitest, VitestOptions, VitestPlugin, VitestRunMode, VmForksPoolWorker, VmThreadsPoolWorker, WorkerRequest, createDebugger, createMethodsRPC, createViteLogger, createViteServer, createVitest, distDir, escapeTestName, getFilePoolName, isValidApiRequest, parseCLI, registerConsoleShortcuts, resolveApiServerConfig, resolveConfig, resolveFsAllow, rolldownVersion, rootDir, startVitest, version };
236
+ export type { CliParseOptions, ProcessPool, CollectLineNumbers as TypeCheckCollectLineNumbers, CollectLines as TypeCheckCollectLines, Context as TypeCheckContext, TscErrorInfo as TypeCheckErrorInfo, RawErrsMap as TypeCheckRawErrorsMap, RootAndTarget as TypeCheckRootAndTarget, WorkerContext };
package/dist/node.js CHANGED
@@ -1,13 +1,13 @@
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.C-JHgQgp.js';
5
- export { G as GitNotFoundError, F as TestsNotFoundError, b as VitestPackageInstaller, h as createDebugger, g as createViteLogger, c as createVitest, e as escapeTestName, d as experimental_getRunnerTask, i as isValidApiRequest, f as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.C-JHgQgp.js';
6
- export { p as parseCLI } from './chunks/cac.By1HvRIk.js';
7
- import { r as resolveConfig$2 } from './chunks/coverage.DarITf6U.js';
8
- export { b as BaseSequencer, c as createMethodsRPC, g as getFilePoolName, a as resolveApiServerConfig } from './chunks/coverage.DarITf6U.js';
9
- import { slash, deepClone } from '@vitest/utils';
10
- import { f as findUp } from './chunks/index.X0nbfr6-.js';
4
+ import { V as Vitest, a as VitestPlugin } from './chunks/cli-api.PwHwIMss.js';
5
+ export { f as ForksPoolWorker, G as GitNotFoundError, F as TestsNotFoundError, T as ThreadsPoolWorker, h as TypecheckPoolWorker, b as VitestPackageInstaller, j as VmForksPoolWorker, k as VmThreadsPoolWorker, o as createDebugger, d as createMethodsRPC, n as createViteLogger, c as createVitest, e as escapeTestName, l as experimental_getRunnerTask, g as getFilePoolName, i as isValidApiRequest, m as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.PwHwIMss.js';
6
+ export { p as parseCLI } from './chunks/cac.B99MQg-w.js';
7
+ import { r as resolveConfig$2 } from './chunks/coverage.FU3w4IrQ.js';
8
+ export { b as BaseSequencer, a as resolveApiServerConfig } from './chunks/coverage.FU3w4IrQ.js';
9
+ import { slash, deepClone } from '@vitest/utils/helpers';
10
+ import { a as any } from './chunks/index.Dc3xnDvT.js';
11
11
  import { resolve } from 'pathe';
12
12
  import { c as configFiles } from './chunks/constants.D_Q9UYh-.js';
13
13
  export { distDir, rootDir } from './path.js';
@@ -18,18 +18,19 @@ import 'node:path';
18
18
  import 'node:os';
19
19
  import '@vitest/snapshot/manager';
20
20
  import './chunks/index.Bgo3tNWt.js';
21
- import './chunks/index.AzwzFtyi.js';
21
+ import './chunks/index.CcRZ6fUh.js';
22
22
  import 'node:fs/promises';
23
- import './chunks/typechecker.DSo_maXz.js';
24
23
  import 'node:perf_hooks';
25
24
  import '@vitest/utils/source-map';
26
- import 'tinyexec';
27
25
  import 'tinyrainbow';
28
26
  import './chunks/env.D4Lgay0q.js';
29
27
  import 'std-env';
30
28
  import 'node:util';
31
29
  import 'node:console';
32
30
  import 'node:stream';
31
+ import '@vitest/utils/display';
32
+ import 'tinyexec';
33
+ import '@vitest/utils/offset';
33
34
  import 'node:module';
34
35
  import 'events';
35
36
  import 'https';
@@ -46,29 +47,31 @@ import 'node:crypto';
46
47
  import 'debug';
47
48
  import '#module-evaluator';
48
49
  import 'vite/module-runner';
50
+ import '@vitest/utils/highlight';
49
51
  import 'node:url';
52
+ import 'node:tty';
53
+ import 'node:events';
54
+ import 'node:child_process';
55
+ import 'node:v8';
56
+ import 'node:worker_threads';
50
57
  import 'picomatch';
51
58
  import 'tinyglobby';
52
59
  import 'magic-string';
53
60
  import '@vitest/mocker/node';
54
- import './chunks/defaults.CXFFjsi8.js';
55
- import './chunks/resolver.Bx6lE0iq.js';
61
+ import './chunks/defaults.BOqNVLsY.js';
62
+ import '@vitest/utils/constants';
63
+ import '@vitest/utils/resolver';
56
64
  import 'es-module-lexer';
57
- import './chunks/index.BuwjkI-q.js';
65
+ import './chunks/index.BdSLhLDZ.js';
58
66
  import 'node:assert';
59
- import '@vitest/utils/error';
67
+ import '@vitest/utils/serialize';
60
68
  import 'node:readline';
61
69
  import 'node:process';
62
- import 'node:v8';
63
- import 'node:tty';
64
- import 'node:events';
65
- import 'tinypool';
66
- import 'node:worker_threads';
67
70
  import 'readline';
68
71
 
69
72
  // this is only exported as a public function and not used inside vitest
70
73
  async function resolveConfig(options = {}, viteOverrides = {}) {
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 });
74
+ const root = slash(resolve(options.root || process.cwd())), configPath = options.config === false ? false : options.config ? resolve(root, options.config) : any(configFiles, { cwd: root });
72
75
  options.config = configPath;
73
76
  const vitest = new Vitest("test", deepClone(options)), config = await resolveConfig$1(mergeConfig({
74
77
  configFile: configPath,
@@ -1,19 +1,20 @@
1
- export { aL as BaseReporter, aM as BenchmarkBuiltinReporters, ay as BenchmarkReporter, az as BenchmarkReportsMap, aN as BuiltinReporterOptions, aO as BuiltinReporters, aA as DefaultReporter, aB as DotReporter, aC as GithubActionsReporter, aD as HangingProcessReporter, aF as JUnitReporter, aP as JsonAssertionResult, aE as JsonReporter, aQ as JsonTestResult, aR as JsonTestResults, av as ReportedHookContext, aw as Reporter, aG as ReportersMap, aH as TapFlatReporter, aI as TapReporter, ax as TestRunEndReason, aJ as VerboseBenchmarkReporter, aK as VerboseReporter } from './chunks/reporters.d.37tJQ2uV.js';
1
+ export { aR as BaseReporter, aS as BenchmarkBuiltinReporters, aE as BenchmarkReporter, aF as BenchmarkReportsMap, aT as BuiltinReporterOptions, aU as BuiltinReporters, aG as DefaultReporter, aH as DotReporter, aI as GithubActionsReporter, aJ as HangingProcessReporter, aL as JUnitReporter, aV as JsonAssertionResult, aK as JsonReporter, aW as JsonTestResult, aX as JsonTestResults, aB as ReportedHookContext, aC as Reporter, aM as ReportersMap, aN as TapFlatReporter, aO as TapReporter, aD as TestRunEndReason, aP as VerboseBenchmarkReporter, aQ as VerboseReporter } from './chunks/reporters.d.BMKt7f6I.js';
2
2
  import '@vitest/runner';
3
3
  import '@vitest/utils';
4
- import './chunks/environment.d.2fYMoz3o.js';
5
- import 'node:stream';
6
- import 'vite';
7
- import '@vitest/mocker';
8
- import '@vitest/utils/source-map';
9
- import './chunks/browser.d.DOMmqJQx.js';
10
- import './chunks/worker.d.DYlqbejz.js';
4
+ import './chunks/worker.d.BFk-vvBU.js';
11
5
  import 'vite/module-runner';
12
- import './chunks/config.d._GBBbReY.js';
6
+ import './chunks/config.d.u2CUDWwS.js';
13
7
  import '@vitest/pretty-format';
14
8
  import '@vitest/snapshot';
15
9
  import '@vitest/utils/diff';
16
- import 'chai';
10
+ import './chunks/environment.d.CrsxCzP1.js';
11
+ import 'node:stream';
12
+ import 'vite';
13
+ import '@vitest/mocker';
14
+ import '@vitest/utils/source-map';
15
+ import 'vitest/browser';
16
+ import './chunks/browser.d.B9iJzZyn.js';
17
+ import '@vitest/expect';
17
18
  import 'vitest/optional-types.js';
18
19
  import './chunks/benchmark.d.DAaHLpsq.js';
19
20
  import '@vitest/runner/utils';
package/dist/reporters.js CHANGED
@@ -1,23 +1,24 @@
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.AzwzFtyi.js';
2
- export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.BuwjkI-q.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.CcRZ6fUh.js';
2
+ export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.BdSLhLDZ.js';
3
3
  import 'node:fs';
4
4
  import 'node:fs/promises';
5
5
  import 'pathe';
6
- import './chunks/typechecker.DSo_maXz.js';
7
- import 'node:os';
8
6
  import 'node:perf_hooks';
9
- import '@vitest/utils/source-map';
10
- import 'tinyexec';
11
- import './path.js';
12
- import 'node:path';
13
- import 'node:url';
14
7
  import '@vitest/runner/utils';
15
- import '@vitest/utils';
16
- import 'vite';
8
+ import '@vitest/utils/helpers';
9
+ import '@vitest/utils/source-map';
17
10
  import 'tinyrainbow';
18
11
  import './chunks/env.D4Lgay0q.js';
19
12
  import 'std-env';
20
13
  import 'node:util';
21
14
  import 'node:console';
22
15
  import 'node:stream';
16
+ import '@vitest/utils/display';
17
+ import 'node:os';
18
+ import 'tinyexec';
19
+ import './path.js';
20
+ import 'node:path';
21
+ import 'node:url';
22
+ import 'vite';
23
+ import '@vitest/utils/offset';
23
24
  import 'node:module';
package/dist/runners.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as tinybench from 'tinybench';
2
2
  import { VitestRunner, VitestRunnerImportSource, Suite, File, Task, CancelReason, Test, TestContext, ImportDuration } from '@vitest/runner';
3
3
  export { VitestRunner } from '@vitest/runner';
4
- import { a as SerializedConfig } from './chunks/config.d._GBBbReY.js';
4
+ import { S as SerializedConfig } from './chunks/config.d.u2CUDWwS.js';
5
5
  import '@vitest/pretty-format';
6
6
  import '@vitest/snapshot';
7
7
  import '@vitest/utils/diff';
package/dist/runners.js CHANGED
@@ -1,221 +1,19 @@
1
- import { updateTask } from '@vitest/runner';
2
- import { createDefer, getSafeTimers } from '@vitest/utils';
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
- import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
6
- import { getTests, getNames, getTestName } from '@vitest/runner/utils';
7
- import { processError } from '@vitest/utils/error';
8
- import { normalize } from 'pathe';
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
- import 'chai';
12
- import './chunks/_commonjsHelpers.BFTU3MAI.js';
1
+ export { N as NodeBenchmarkRunner, V as VitestTestRunner } from './chunks/test.C3RPt8JR.js';
2
+ import '@vitest/runner';
3
+ import '@vitest/utils/helpers';
4
+ import '@vitest/utils/timers';
5
+ import './chunks/benchmark.DHKMYAts.js';
6
+ import '@vitest/runner/utils';
7
+ import './chunks/utils.CG9h5ccR.js';
8
+ import '@vitest/expect';
9
+ import '@vitest/utils/error';
10
+ import 'pathe';
11
+ import './chunks/vi.BZvkKVkM.js';
13
12
  import '@vitest/snapshot';
14
13
  import '@vitest/spy';
14
+ import '@vitest/utils/offset';
15
15
  import '@vitest/utils/source-map';
16
+ import './chunks/_commonjsHelpers.BFTU3MAI.js';
16
17
  import './chunks/date.-jtEtIeV.js';
18
+ import './chunks/rpc.cD77ENhU.js';
17
19
  import './chunks/index.Bgo3tNWt.js';
18
-
19
- function createBenchmarkResult(name) {
20
- return {
21
- name,
22
- rank: 0,
23
- rme: 0,
24
- samples: []
25
- };
26
- }
27
- const benchmarkTasks = /* @__PURE__ */ new WeakMap();
28
- async function runBenchmarkSuite(suite, runner) {
29
- const { Task, Bench } = await runner.importTinybench(), start = performance.now(), benchmarkGroup = [], benchmarkSuiteGroup = [];
30
- for (const task of suite.tasks) {
31
- if (task.mode !== "run" && task.mode !== "queued") continue;
32
- if (task.meta?.benchmark) benchmarkGroup.push(task);
33
- else if (task.type === "suite") benchmarkSuiteGroup.push(task);
34
- }
35
- // run sub suites sequentially
36
- for (const subSuite of benchmarkSuiteGroup) await runBenchmarkSuite(subSuite, runner);
37
- if (benchmarkGroup.length) {
38
- const defer = createDefer();
39
- suite.result = {
40
- state: "run",
41
- startTime: start,
42
- benchmark: createBenchmarkResult(suite.name)
43
- }, updateTask$1("suite-prepare", suite);
44
- const addBenchTaskListener = (task, benchmark) => {
45
- task.addEventListener("complete", (e) => {
46
- const task = e.task, taskRes = task.result, result = benchmark.result.benchmark;
47
- benchmark.result.state = "pass", Object.assign(result, taskRes);
48
- // compute extra stats and free raw samples as early as possible
49
- const samples = result.samples;
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;
51
- updateTask$1("test-finished", benchmark);
52
- }, { once: true }), task.addEventListener("error", (e) => {
53
- const task = e.task;
54
- defer.reject(benchmark ? task.result.error : e);
55
- }, { once: true });
56
- };
57
- benchmarkGroup.forEach((benchmark) => {
58
- const options = getBenchOptions(benchmark), benchmarkInstance = new Bench(options), benchmarkFn = getBenchFn(benchmark);
59
- benchmark.result = {
60
- state: "run",
61
- startTime: start,
62
- benchmark: createBenchmarkResult(benchmark.name)
63
- };
64
- const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
65
- benchmarkTasks.set(benchmark, task), addBenchTaskListener(task, benchmark);
66
- });
67
- const { setTimeout } = getSafeTimers(), tasks = [];
68
- for (const benchmark of benchmarkGroup) {
69
- const task = benchmarkTasks.get(benchmark);
70
- updateTask$1("test-prepare", benchmark), await task.warmup(), tasks.push([await new Promise((resolve) => setTimeout(async () => {
71
- resolve(await task.run());
72
- })), benchmark]);
73
- }
74
- suite.result.duration = performance.now() - start, suite.result.state = "pass", updateTask$1("suite-finished", suite), defer.resolve(null), await defer;
75
- }
76
- function updateTask$1(event, task) {
77
- updateTask(event, task, runner);
78
- }
79
- }
80
- class NodeBenchmarkRunner {
81
- moduleRunner;
82
- constructor(config) {
83
- this.config = config;
84
- }
85
- async importTinybench() {
86
- return await import('tinybench');
87
- }
88
- importFile(filepath, source) {
89
- if (source === "setup") {
90
- const moduleNode = getWorkerState().evaluatedModules.getModuleById(filepath);
91
- if (moduleNode) getWorkerState().evaluatedModules.invalidateModule(moduleNode);
92
- }
93
- return this.moduleRunner.import(filepath);
94
- }
95
- async runSuite(suite) {
96
- await runBenchmarkSuite(suite, this);
97
- }
98
- async runTask() {
99
- throw new Error("`test()` and `it()` is only available in test mode.");
100
- }
101
- }
102
-
103
- // import type { VitestExecutor } from '../execute'
104
- // worker context is shared between all tests
105
- const workerContext = Object.create(null);
106
- class VitestTestRunner {
107
- snapshotClient = getSnapshotClient();
108
- workerState = getWorkerState();
109
- moduleRunner;
110
- cancelRun = false;
111
- assertionsErrors = /* @__PURE__ */ new WeakMap();
112
- pool = this.workerState.ctx.pool;
113
- constructor(config) {
114
- this.config = config;
115
- }
116
- importFile(filepath, source) {
117
- if (source === "setup") {
118
- const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
119
- if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
120
- }
121
- return this.moduleRunner.import(filepath);
122
- }
123
- onCollectStart(file) {
124
- this.workerState.current = file;
125
- }
126
- onCleanupWorkerContext(listener) {
127
- this.workerState.onCleanup(listener);
128
- }
129
- onAfterRunFiles() {
130
- this.snapshotClient.clear(), this.workerState.current = void 0;
131
- }
132
- getWorkerContext() {
133
- return workerContext;
134
- }
135
- async onAfterRunSuite(suite) {
136
- if (this.config.logHeapUsage && typeof process !== "undefined") suite.result.heap = process.memoryUsage().heapUsed;
137
- if (suite.mode !== "skip" && "filepath" in suite) {
138
- // mark snapshots in skipped tests as not obsolete
139
- for (const test of getTests(suite)) if (test.mode === "skip") {
140
- const name = getNames(test).slice(1).join(" > ");
141
- this.snapshotClient.skipTest(suite.file.filepath, name);
142
- }
143
- const result = await this.snapshotClient.finish(suite.file.filepath);
144
- if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
145
- let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
146
- for (const key of result.uncheckedKeys) message += `· ${key}\n`;
147
- suite.result.errors ??= [], suite.result.errors.push(processError(new Error(message))), suite.result.state = "fail";
148
- }
149
- await rpc().snapshotSaved(result);
150
- }
151
- this.workerState.current = suite.suite || suite.file;
152
- }
153
- onAfterRunTask(test) {
154
- if (this.config.logHeapUsage && typeof process !== "undefined") test.result.heap = process.memoryUsage().heapUsed;
155
- this.workerState.current = test.suite || test.file;
156
- }
157
- cancel(_reason) {
158
- this.cancelRun = true;
159
- }
160
- injectValue(key) {
161
- // inject has a very limiting type controlled by ProvidedContext
162
- // some tests override it which causes the build to fail
163
- return inject(key);
164
- }
165
- async onBeforeRunTask(test) {
166
- if (this.cancelRun) test.mode = "skip";
167
- test.mode !== "run" && test.mode !== "queued" || (this.workerState.current = test);
168
- }
169
- async onBeforeRunSuite(suite) {
170
- if (this.cancelRun) suite.mode = "skip";
171
- // initialize snapshot state before running file suite
172
- if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
173
- this.workerState.current = suite;
174
- }
175
- onBeforeTryTask(test) {
176
- clearModuleMocks(this.config), this.snapshotClient.clearTest(test.file.filepath, test.id), setState({
177
- assertionCalls: 0,
178
- isExpectingAssertions: false,
179
- isExpectingAssertionsError: null,
180
- expectedAssertionsNumber: null,
181
- expectedAssertionsNumberErrorGen: null,
182
- currentTestName: getTestName(test),
183
- snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
184
- }, globalThis[GLOBAL_EXPECT]);
185
- }
186
- onAfterTryTask(test) {
187
- const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
188
- if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber) throw expectedAssertionsNumberErrorGen();
189
- if (isExpectingAssertions === true && assertionCalls === 0) throw isExpectingAssertionsError;
190
- if (this.config.expect.requireAssertions && assertionCalls === 0) throw this.assertionsErrors.get(test);
191
- }
192
- extendTaskContext(context) {
193
- // create error during the test initialization so we have a nice stack trace
194
- if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
195
- let _expect;
196
- return Object.defineProperty(context, "expect", { get() {
197
- if (!_expect) _expect = createExpect(context.task);
198
- return _expect;
199
- } }), Object.defineProperty(context, "_local", { get() {
200
- return _expect != null;
201
- } }), context;
202
- }
203
- getImportDurations() {
204
- const entries = [...this.workerState.moduleExecutionInfo?.entries() ?? []];
205
- return Object.fromEntries(entries.map(([filepath, { duration, selfTime }]) => [normalize(filepath), {
206
- selfTime,
207
- totalTime: duration
208
- }]));
209
- }
210
- }
211
- function clearModuleMocks(config) {
212
- const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
213
- // since each function calls another, we can just call one
214
- if (restoreMocks) vi.restoreAllMocks();
215
- else if (mockReset) vi.resetAllMocks();
216
- else if (clearMocks) vi.clearAllMocks();
217
- if (unstubEnvs) vi.unstubAllEnvs();
218
- if (unstubGlobals) vi.unstubAllGlobals();
219
- }
220
-
221
- export { NodeBenchmarkRunner, VitestTestRunner };
package/dist/snapshot.js CHANGED
@@ -1,4 +1,4 @@
1
- export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.BOqcT2jW.js';
1
+ export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.BwAWWjHZ.js';
2
2
  import '@vitest/snapshot/environment';
3
- import './chunks/utils.C7__0Iv5.js';
4
- import '@vitest/utils';
3
+ import './chunks/utils.CG9h5ccR.js';
4
+ import '@vitest/utils/timers';
package/dist/suite.js CHANGED
@@ -1,5 +1,6 @@
1
- export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.UW6Ezvxy.js';
1
+ export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.DHKMYAts.js';
2
2
  export { createTaskCollector, getCurrentSuite, getCurrentTest, getFn, getHooks, setFn, setHooks } from '@vitest/runner';
3
3
  export { createChainable } from '@vitest/runner/utils';
4
- import '@vitest/utils';
5
- import './chunks/utils.C7__0Iv5.js';
4
+ import '@vitest/utils/helpers';
5
+ import './chunks/utils.CG9h5ccR.js';
6
+ import '@vitest/utils/timers';
@@ -0,0 +1,26 @@
1
+ import { W as WorkerGlobalState, B as BirpcOptions, R as RuntimeRPC } from './chunks/worker.d.BFk-vvBU.js';
2
+ import { Awaitable } from '@vitest/utils';
3
+ import '@vitest/runner';
4
+ import 'vite/module-runner';
5
+ import './chunks/config.d.u2CUDWwS.js';
6
+ import '@vitest/pretty-format';
7
+ import '@vitest/snapshot';
8
+ import '@vitest/utils/diff';
9
+ import './chunks/environment.d.CrsxCzP1.js';
10
+
11
+ /** @experimental */
12
+ declare function runBaseTests(method: "run" | "collect", state: WorkerGlobalState): Promise<void>;
13
+
14
+ type WorkerRpcOptions = Pick<BirpcOptions<RuntimeRPC>, "on" | "off" | "post" | "serialize" | "deserialize">;
15
+ interface VitestWorker extends WorkerRpcOptions {
16
+ runTests: (state: WorkerGlobalState) => Awaitable<unknown>;
17
+ collectTests: (state: WorkerGlobalState) => Awaitable<unknown>;
18
+ }
19
+
20
+ interface Options extends VitestWorker {
21
+ teardown?: () => void;
22
+ }
23
+ /** @experimental */
24
+ declare function init(worker: Options): void;
25
+
26
+ export { init, runBaseTests };