vitest 3.1.0-beta.1 → 3.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 (88) hide show
  1. package/LICENSE.md +29 -0
  2. package/dist/browser.js +4 -4
  3. package/dist/chunks/base.bV8rwssx.js +41 -0
  4. package/dist/chunks/benchmark.BKUatJGy.js +39 -0
  5. package/dist/chunks/cac.1WcTh-zl.js +1529 -0
  6. package/dist/chunks/{cli-api.BwkkJsRe.js → cli-api.2yb7XCwB.js} +4640 -5072
  7. package/dist/chunks/console.D6t261w0.js +173 -0
  8. package/dist/chunks/constants.BZZyIeIE.js +43 -0
  9. package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
  10. package/dist/chunks/{coverage.gV8doR2Y.js → coverage.SfnlalVs.js} +2424 -2482
  11. package/dist/chunks/creator.CuL7xDWI.js +705 -0
  12. package/dist/chunks/date.CDOsz-HY.js +53 -0
  13. package/dist/chunks/defaults.DmfNPoe5.js +114 -0
  14. package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
  15. package/dist/chunks/execute.CwmnH2oH.js +791 -0
  16. package/dist/chunks/git.DXfdBEfR.js +74 -0
  17. package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
  18. package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
  19. package/dist/chunks/index.CwHmn5H5.js +2422 -0
  20. package/dist/chunks/index.DFXFpH3w.js +607 -0
  21. package/dist/chunks/index.VfYQ6MXY.js +104 -0
  22. package/dist/chunks/inspector.DbDkSkFn.js +54 -0
  23. package/dist/chunks/node.IqGoMrm4.js +15 -0
  24. package/dist/chunks/{reporters.d.r7poTZjA.d.ts → reporters.d.CfRkRKN2.d.ts} +52 -20
  25. package/dist/chunks/rpc.DGgL5dw7.js +92 -0
  26. package/dist/chunks/run-once.I7PpBOk1.js +47 -0
  27. package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
  28. package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
  29. package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.CG0zmr19.js} +620 -622
  30. package/dist/chunks/utils.BfxieIyZ.js +66 -0
  31. package/dist/chunks/utils.CtocqOoE.js +72 -0
  32. package/dist/chunks/utils.Lot3J_8U.js +194 -0
  33. package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
  34. package/dist/chunks/vite.d.4pkSbgmp.d.ts +23 -0
  35. package/dist/chunks/vm.Lp7mPCVW.js +796 -0
  36. package/dist/cli.js +2 -2
  37. package/dist/config.cjs +97 -103
  38. package/dist/config.d.ts +6 -4
  39. package/dist/config.js +6 -6
  40. package/dist/coverage.d.ts +2 -1
  41. package/dist/coverage.js +7 -7
  42. package/dist/environments.js +1 -1
  43. package/dist/execute.d.ts +0 -2
  44. package/dist/execute.js +1 -1
  45. package/dist/index.d.ts +6 -5
  46. package/dist/index.js +6 -6
  47. package/dist/node.d.ts +17 -6
  48. package/dist/node.js +36 -45
  49. package/dist/path.js +1 -4
  50. package/dist/reporters.d.ts +2 -1
  51. package/dist/reporters.js +4 -4
  52. package/dist/runners.js +231 -267
  53. package/dist/snapshot.js +2 -2
  54. package/dist/suite.js +2 -2
  55. package/dist/worker.js +98 -114
  56. package/dist/workers/forks.js +22 -22
  57. package/dist/workers/runVmTests.js +61 -66
  58. package/dist/workers/threads.js +13 -13
  59. package/dist/workers/vmForks.js +24 -24
  60. package/dist/workers/vmThreads.js +15 -15
  61. package/dist/workers.d.ts +2 -1
  62. package/dist/workers.js +10 -10
  63. package/package.json +17 -17
  64. package/dist/chunks/base.DV59CbtV.js +0 -45
  65. package/dist/chunks/benchmark.DL72EVN-.js +0 -40
  66. package/dist/chunks/cac.BjmXy7OV.js +0 -1664
  67. package/dist/chunks/console.CN7AiMGV.js +0 -179
  68. package/dist/chunks/constants.DTYd6dNH.js +0 -46
  69. package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
  70. package/dist/chunks/creator.BsBnpTzI.js +0 -670
  71. package/dist/chunks/date.W2xKR2qe.js +0 -53
  72. package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
  73. package/dist/chunks/execute.eDH0aFFd.js +0 -839
  74. package/dist/chunks/git.B5SDxu-n.js +0 -69
  75. package/dist/chunks/index.DOyx6FYJ.js +0 -2551
  76. package/dist/chunks/index.K90BXFOx.js +0 -658
  77. package/dist/chunks/index.uXkkC4xl.js +0 -111
  78. package/dist/chunks/inspector.DKLceBVD.js +0 -54
  79. package/dist/chunks/node.AKq966Jp.js +0 -15
  80. package/dist/chunks/rpc.TVf73xOu.js +0 -102
  81. package/dist/chunks/run-once.2ogXb3JV.js +0 -28
  82. package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
  83. package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
  84. package/dist/chunks/utils.C8RiOc4B.js +0 -77
  85. package/dist/chunks/utils.Cn0zI1t3.js +0 -68
  86. package/dist/chunks/utils.bLM2atbD.js +0 -198
  87. package/dist/chunks/vite.d.Fvq-NZoa.d.ts +0 -11
  88. package/dist/chunks/vm.jEFQDlX_.js +0 -852
@@ -0,0 +1,54 @@
1
+ import { createRequire } from 'node:module';
2
+ import { pathToFileURL } from 'node:url';
3
+
4
+ const __require = createRequire(import.meta.url);
5
+ let inspector;
6
+ let session;
7
+ /**
8
+ * Enables debugging inside `worker_threads` and `child_process`.
9
+ * Should be called as early as possible when worker/process has been set up.
10
+ */
11
+ function setupInspect(ctx) {
12
+ const config = ctx.config;
13
+ const isEnabled = config.inspector.enabled;
14
+ if (isEnabled) {
15
+ inspector = __require("node:inspector");
16
+ const isOpen = inspector.url() !== undefined;
17
+ if (!isOpen) {
18
+ inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger);
19
+ if (config.inspectBrk) {
20
+ const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
21
+ if (firstTestFile) {
22
+ session = new inspector.Session();
23
+ session.connect();
24
+ session.post("Debugger.enable");
25
+ session.post("Debugger.setBreakpointByUrl", {
26
+ lineNumber: 0,
27
+ url: pathToFileURL(firstTestFile)
28
+ });
29
+ }
30
+ }
31
+ }
32
+ }
33
+ const keepOpen = shouldKeepOpen(config);
34
+ return function cleanup() {
35
+ if (isEnabled && !keepOpen && inspector) {
36
+ inspector.close();
37
+ session?.disconnect();
38
+ }
39
+ };
40
+ }
41
+ function closeInspector(config) {
42
+ const keepOpen = shouldKeepOpen(config);
43
+ if (inspector && !keepOpen) {
44
+ inspector.close();
45
+ session?.disconnect();
46
+ }
47
+ }
48
+ function shouldKeepOpen(config) {
49
+ const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread;
50
+ const isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
51
+ return config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
52
+ }
53
+
54
+ export { closeInspector as c, setupInspect as s };
@@ -0,0 +1,15 @@
1
+ import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
2
+ import { g as getWorkerState } from './utils.CtocqOoE.js';
3
+ import '@vitest/utils';
4
+
5
+ class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
6
+ getHeader() {
7
+ return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
8
+ }
9
+ resolvePath(filepath) {
10
+ const rpc = getWorkerState().rpc;
11
+ return rpc.resolveSnapshotPath(filepath);
12
+ }
13
+ }
14
+
15
+ export { VitestNodeSnapshotEnvironment };
@@ -1,9 +1,10 @@
1
- import { Task, Suite, File, TaskMeta, TaskResultPack, SequenceSetupFiles, SequenceHooks, CancelReason } from '@vitest/runner';
1
+ import { Task, TaskMeta, Suite, File, TaskResultPack, SequenceSetupFiles, SequenceHooks, CancelReason } from '@vitest/runner';
2
2
  import { b as Awaitable, U as UserConsoleLog, c as Arrayable$1, A as AfterSuiteRunMeta, f as EnvironmentOptions, P as ProvidedContext } from './environment.d.C8UItCbf.js';
3
3
  import { ParsedStack, TestError, SerializedError, ErrorWithDiff, Arrayable, Awaitable as Awaitable$1 } from '@vitest/utils';
4
4
  import { Writable } from 'node:stream';
5
5
  import { TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions, ViteDevServer, ModuleNode } from 'vite';
6
6
  import { Console } from 'node:console';
7
+ import { MockedModule } from '@vitest/mocker';
7
8
  import { StackTraceParserOptions } from '@vitest/utils/source-map';
8
9
  import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.DevWltVl.js';
9
10
  import { PrettyFormatOptions } from '@vitest/pretty-format';
@@ -93,6 +94,10 @@ declare class ReportedTaskImplementation {
93
94
  * If the test is not finished yet or was skipped, it will return `true`.
94
95
  */
95
96
  ok(): boolean;
97
+ /**
98
+ * Custom metadata that was attached to the test during its execution.
99
+ */
100
+ meta(): TaskMeta;
96
101
  }
97
102
  declare class TestCase extends ReportedTaskImplementation {
98
103
  #private;
@@ -126,10 +131,6 @@ declare class TestCase extends ReportedTaskImplementation {
126
131
  */
127
132
  result(): TestResult;
128
133
  /**
129
- * Custom metadata that was attached to the test during its execution.
130
- */
131
- meta(): TaskMeta;
132
- /**
133
134
  * Useful information about the test like duration, memory usage, etc.
134
135
  * Diagnostic is only available after the test has finished.
135
136
  */
@@ -211,6 +212,10 @@ declare class TestSuite extends SuiteImplementation {
211
212
  */
212
213
  ok: () => boolean;
213
214
  /**
215
+ * The meta information attached to the suite during its collection or execution.
216
+ */
217
+ meta: () => TaskMeta;
218
+ /**
214
219
  * Checks the running state of the suite.
215
220
  */
216
221
  state(): TestSuiteState;
@@ -238,6 +243,10 @@ declare class TestModule extends SuiteImplementation {
238
243
  */
239
244
  ok: () => boolean;
240
245
  /**
246
+ * The meta information attached to the module during its collection or execution.
247
+ */
248
+ meta: () => TaskMeta;
249
+ /**
241
250
  * Useful information about the module like duration, memory usage, etc.
242
251
  * If the module was not executed yet, all diagnostic values will return `0`.
243
252
  */
@@ -357,6 +366,11 @@ interface ModuleDiagnostic {
357
366
  * Accumulated duration of all tests and hooks in the module.
358
367
  */
359
368
  readonly duration: number;
369
+ /**
370
+ * The amount of memory used by the test module in bytes.
371
+ * This value is only available if the test was executed with `logHeapUsage` flag.
372
+ */
373
+ readonly heap: number | undefined;
360
374
  }
361
375
 
362
376
  type BuiltinPool = "browser" | "threads" | "forks" | "vmThreads" | "vmForks" | "typescript";
@@ -626,7 +640,7 @@ declare abstract class BaseReporter implements Reporter {
626
640
  start: number;
627
641
  end: number;
628
642
  watchFilters?: string[];
629
- failedUnwatchedFiles: Task[];
643
+ failedUnwatchedFiles: TestModule[];
630
644
  isTTY: boolean;
631
645
  ctx: Vitest;
632
646
  renderSucceed: boolean;
@@ -643,12 +657,10 @@ declare abstract class BaseReporter implements Reporter {
643
657
  onTestSuiteResult(testSuite: TestSuite): void;
644
658
  onTestModuleEnd(testModule: TestModule): void;
645
659
  private logFailedTask;
646
- onTaskUpdate(packs: TaskResultPack[]): void;
647
- /**
648
- * Callback invoked with a single `Task` from `onTaskUpdate`
649
- */
650
- protected printTask(task: Task): void;
651
- protected printSuite(_task: Task): void;
660
+ protected printTestModule(testModule: TestModule): void;
661
+ protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
662
+ private getModuleLog;
663
+ protected printTestSuite(_suite: TestSuite): void;
652
664
  protected getTestName(test: Task, separator?: string): string;
653
665
  protected formatShortError(error: ErrorWithDiff): string;
654
666
  protected getTestIndentation(_test: Task): string;
@@ -915,7 +927,7 @@ declare class DotReporter extends BaseReporter {
915
927
  private tests;
916
928
  private finishedTests;
917
929
  onInit(ctx: Vitest): void;
918
- printTask(task: Task): void;
930
+ printTestModule(testModule: TestModule): void;
919
931
  onWatcherRerun(files: string[], trigger?: string): void;
920
932
  onFinished(files?: File[], errors?: unknown[]): void;
921
933
  onTestModuleCollected(module: TestModule): void;
@@ -955,8 +967,9 @@ declare class TapFlatReporter extends TapReporter {
955
967
  declare class VerboseReporter extends DefaultReporter {
956
968
  protected verbose: boolean;
957
969
  renderSucceed: boolean;
958
- printTask(task: Task): void;
959
- protected printSuite(task: Task): void;
970
+ printTestModule(module: TestModule): void;
971
+ onTestCaseResult(test: TestCase): void;
972
+ protected printTestSuite(testSuite: TestSuite): void;
960
973
  protected getTestName(test: Task): string;
961
974
  protected getTestIndentation(test: Task): string;
962
975
  protected formatShortError(): string;
@@ -980,7 +993,9 @@ declare class BenchmarkReporter extends DefaultReporter {
980
993
  compare?: Parameters<typeof renderTable>[0]["compare"];
981
994
  onInit(ctx: Vitest): Promise<void>;
982
995
  onTaskUpdate(packs: TaskResultPack[]): void;
983
- printTask(task: Task): void;
996
+ onTestSuiteResult(testSuite: TestSuite): void;
997
+ protected printTestModule(testModule: TestModule): void;
998
+ private printSuiteTable;
984
999
  onFinished(files?: File[], errors?: unknown[]): Promise<void>;
985
1000
  }
986
1001
 
@@ -2238,7 +2253,7 @@ interface UserWorkspaceConfig extends UserConfig$1 {
2238
2253
  }
2239
2254
  type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
2240
2255
  type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
2241
- type TestProjectConfiguration = string | (UserProjectConfigExport & {
2256
+ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
2242
2257
  /**
2243
2258
  * Relative path to the extendable config. All other options will be merged with this config.
2244
2259
  * If `true`, the project will inherit all options from the root config.
@@ -2246,6 +2261,7 @@ type TestProjectConfiguration = string | (UserProjectConfigExport & {
2246
2261
  */
2247
2262
  extends?: string | true
2248
2263
  });
2264
+ type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
2249
2265
  /** @deprecated use `TestProjectConfiguration` instead */
2250
2266
  type WorkspaceProjectConfiguration = TestProjectConfiguration;
2251
2267
 
@@ -2259,8 +2275,14 @@ interface CDPSession {
2259
2275
  once: (event: string, listener: (...args: unknown[]) => void) => void;
2260
2276
  off: (event: string, listener: (...args: unknown[]) => void) => void;
2261
2277
  }
2278
+ interface BrowserModuleMocker {
2279
+ register: (sessionId: string, module: MockedModule) => Promise<void>;
2280
+ delete: (sessionId: string, url: string) => Promise<void>;
2281
+ clear: (sessionId: string) => Promise<void>;
2282
+ }
2262
2283
  interface BrowserProvider {
2263
2284
  name: string;
2285
+ mocker?: BrowserModuleMocker;
2264
2286
  /**
2265
2287
  * @experimental opt-in into file parallelisation
2266
2288
  */
@@ -2610,7 +2632,6 @@ declare class TestProject {
2610
2632
  private isInSourceTestCode;
2611
2633
  private filterFiles;
2612
2634
  private _parentBrowser?;
2613
- private _parent?;
2614
2635
  /**
2615
2636
  * Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts.
2616
2637
  * If the resources are needed again, create a new project.
@@ -2636,7 +2657,7 @@ interface SerializedTestProject {
2636
2657
  serializedConfig: SerializedConfig;
2637
2658
  context: ProvidedContext;
2638
2659
  }
2639
- interface InitializeProjectOptions extends UserWorkspaceConfig {
2660
+ interface InitializeProjectOptions extends TestProjectInlineConfiguration {
2640
2661
  configFile: string | false;
2641
2662
  }
2642
2663
 
@@ -2825,6 +2846,12 @@ declare class Vitest {
2825
2846
  /** @deprecated internal */
2826
2847
  setServer(options: UserConfig, server: ViteDevServer, cliOptions: UserConfig): Promise<void>;
2827
2848
  /**
2849
+ * Inject new test projects into the workspace.
2850
+ * @param config Glob, config path or a custom config options.
2851
+ * @returns An array of new test projects. Can be empty if the name was filtered out.
2852
+ */
2853
+ private injectTestProject;
2854
+ /**
2828
2855
  * Provide a value to the test context. This value will be available to all tests with `inject`.
2829
2856
  */
2830
2857
  provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
@@ -3005,8 +3032,13 @@ declare class Vitest {
3005
3032
  * vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))
3006
3033
  */
3007
3034
  onFilterWatchedSpecification(fn: (specification: TestSpecification) => boolean): void;
3035
+ /**
3036
+ * Check if the project with a given name should be included.
3037
+ */
3038
+ matchesProjectFilter(name: string): boolean;
3008
3039
  }
3009
3040
  type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
3010
3041
  type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
3011
3042
 
3012
- export { type JUnitOptions as $, type ApiConfig as A, type BaseCoverageOptions as B, CoverageMap as C, type DepsOptimizationOptions as D, TestProject as E, type TestSequencer as F, TestSpecification as G, TestModule as H, type InlineConfig as I, type OnTestsRerunHandler as J, VitestPackageInstaller as K, Logger as L, type ModuleDiagnostic as M, type ProcessPool as N, type OnServerRestartHandler as O, type Pool as P, type WorkspaceSpec as Q, type ResolvedCoverageOptions as R, type SerializedTestSpecification as S, type TestProjectConfiguration as T, type UserWorkspaceConfig as U, Vitest as V, type WorkspaceProjectConfiguration as W, getFilePoolName as X, type SerializedTestProject as Y, type HTMLOptions as Z, type JsonOptions$1 as _, type ReportContext as a, type TaskOptions as a0, TestCase as a1, TestCollection as a2, type TestDiagnostic as a3, type TestModuleState as a4, type TestResult as a5, type TestResultFailed as a6, type TestResultPassed as a7, type TestResultSkipped as a8, type TestState as a9, BenchmarkReportsMap as aA, DefaultReporter as aB, DotReporter as aC, GithubActionsReporter as aD, HangingProcessReporter as aE, JsonReporter as aF, JUnitReporter as aG, ReportersMap as aH, TapFlatReporter as aI, TapReporter as aJ, VerboseBenchmarkReporter as aK, VerboseReporter as aL, BaseReporter as aM, type BenchmarkBuiltinReporters as aN, type BuiltinReporterOptions as aO, type BuiltinReporters as aP, type JsonAssertionResult as aQ, type JsonTestResult as aR, type JsonTestResults as aS, TestSuite as aa, type TestSuiteState as ab, type TestSequencerConstructor as ac, type BrowserBuiltinProvider as ad, type BrowserCommand as ae, type BrowserCommandContext as af, type BrowserInstanceOption as ag, type BrowserOrchestrator as ah, type BrowserProvider as ai, type BrowserProviderInitializationOptions as aj, type BrowserProviderModule as ak, type BrowserProviderOptions as al, type BrowserServerState as am, type BrowserServerStateSession as an, type CDPSession as ao, type ParentProjectBrowser as ap, type ProjectBrowser as aq, type ResolvedBrowserOptions as ar, type ResolvedProjectConfig as as, type ResolveSnapshotPathHandler as at, type ResolveSnapshotPathHandlerContext as au, type TestRunResult as av, type ReportedHookContext as aw, type TestRunEndReason as ax, BasicReporter as ay, BenchmarkReporter as az, type CoverageV8Options as b, type UserProjectConfigFn as c, type UserProjectConfigExport as d, type CoverageProvider as e, type CoverageProviderModule as f, type CoverageReporter as g, type CoverageProviderName as h, type CoverageOptions as i, type CoverageIstanbulOptions as j, type CustomProviderOptions as k, type Reporter as l, type BrowserScript as m, type BrowserConfigOptions as n, type BuiltinEnvironment as o, type VitestEnvironment as p, type PoolOptions as q, type CSSModuleScopeStrategy as r, type VitestRunMode as s, type TransformModePatterns as t, type TypecheckConfig as u, type UserConfig as v, type ResolvedConfig as w, type ProjectConfig as x, type BenchmarkUserOptions as y, type VitestOptions as z };
3043
+ export { CoverageMap as C, TestSpecification as H, TestModule as J, Logger as L, VitestPackageInstaller as N, TestProject as T, Vitest as V, getFilePoolName as Y, TestCase as a2, TestCollection as a3, BasicReporter as aA, BenchmarkReporter as aB, BenchmarkReportsMap as aC, DefaultReporter as aD, DotReporter as aE, GithubActionsReporter as aF, HangingProcessReporter as aG, JsonReporter as aH, JUnitReporter as aI, ReportersMap as aJ, TapFlatReporter as aK, TapReporter as aL, VerboseBenchmarkReporter as aM, VerboseReporter as aN, BaseReporter as aO, TestSuite as ab };
3044
+ export type { JsonOptions$1 as $, ApiConfig as A, BaseCoverageOptions as B, DepsOptimizationOptions as D, BenchmarkUserOptions as E, VitestOptions as F, TestSequencer as G, InlineConfig as I, OnTestsRerunHandler as K, ModuleDiagnostic as M, OnServerRestartHandler as O, Pool as P, ProcessPool as Q, ResolvedCoverageOptions as R, SerializedTestSpecification as S, UserWorkspaceConfig as U, WorkspaceProjectConfiguration as W, WorkspaceSpec as X, SerializedTestProject as Z, HTMLOptions as _, ReportContext as a, JUnitOptions as a0, TaskOptions as a1, TestDiagnostic as a4, TestModuleState as a5, TestResult as a6, TestResultFailed as a7, TestResultPassed as a8, TestResultSkipped as a9, BenchmarkBuiltinReporters as aP, BuiltinReporterOptions as aQ, BuiltinReporters as aR, JsonAssertionResult as aS, JsonTestResult as aT, JsonTestResults as aU, TestState as aa, TestSuiteState as ac, TestSequencerConstructor as ad, BrowserBuiltinProvider as ae, BrowserCommand as af, BrowserCommandContext as ag, BrowserInstanceOption as ah, BrowserModuleMocker as ai, BrowserOrchestrator as aj, BrowserProvider as ak, BrowserProviderInitializationOptions as al, BrowserProviderModule as am, BrowserProviderOptions as an, BrowserServerState as ao, BrowserServerStateSession as ap, CDPSession as aq, ParentProjectBrowser as ar, ProjectBrowser as as, ResolvedBrowserOptions as at, ResolvedProjectConfig as au, ResolveSnapshotPathHandler as av, ResolveSnapshotPathHandlerContext as aw, TestRunResult as ax, ReportedHookContext as ay, TestRunEndReason as az, TestProjectConfiguration as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, TestProjectInlineConfiguration as f, CoverageProvider as g, CoverageProviderModule as h, CoverageReporter as i, CoverageProviderName as j, CoverageOptions as k, CoverageIstanbulOptions as l, CustomProviderOptions as m, Reporter as n, BrowserScript as o, BrowserConfigOptions as p, BuiltinEnvironment as q, VitestEnvironment as r, PoolOptions as s, CSSModuleScopeStrategy as t, VitestRunMode as u, TransformModePatterns as v, TypecheckConfig as w, UserConfig as x, ResolvedConfig as y, ProjectConfig as z };
@@ -0,0 +1,92 @@
1
+ import { getSafeTimers } from '@vitest/utils';
2
+ import { c as createBirpc } from './index.68735LiX.js';
3
+ import { g as getWorkerState } from './utils.CtocqOoE.js';
4
+
5
+ const { get } = Reflect;
6
+ function withSafeTimers(fn) {
7
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
8
+ const currentSetTimeout = globalThis.setTimeout;
9
+ const currentClearTimeout = globalThis.clearTimeout;
10
+ const currentSetImmediate = globalThis.setImmediate;
11
+ const currentClearImmediate = globalThis.clearImmediate;
12
+ const currentNextTick = globalThis.process?.nextTick;
13
+ try {
14
+ globalThis.setTimeout = setTimeout;
15
+ globalThis.clearTimeout = clearTimeout;
16
+ globalThis.setImmediate = setImmediate;
17
+ globalThis.clearImmediate = clearImmediate;
18
+ if (globalThis.process) {
19
+ globalThis.process.nextTick = nextTick;
20
+ }
21
+ const result = fn();
22
+ return result;
23
+ } finally {
24
+ globalThis.setTimeout = currentSetTimeout;
25
+ globalThis.clearTimeout = currentClearTimeout;
26
+ globalThis.setImmediate = currentSetImmediate;
27
+ globalThis.clearImmediate = currentClearImmediate;
28
+ if (globalThis.process) {
29
+ nextTick(() => {
30
+ globalThis.process.nextTick = currentNextTick;
31
+ });
32
+ }
33
+ }
34
+ }
35
+ const promises = new Set();
36
+ async function rpcDone() {
37
+ if (!promises.size) {
38
+ return;
39
+ }
40
+ const awaitable = Array.from(promises);
41
+ return Promise.all(awaitable);
42
+ }
43
+ function createRuntimeRpc(options) {
44
+ let setCancel = (_reason) => {};
45
+ const onCancel = new Promise((resolve) => {
46
+ setCancel = resolve;
47
+ });
48
+ const rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
49
+ eventNames: [
50
+ "onUserConsoleLog",
51
+ "onCollected",
52
+ "onCancel"
53
+ ],
54
+ onTimeoutError(functionName, args) {
55
+ let message = `[vitest-worker]: Timeout calling "${functionName}"`;
56
+ if (functionName === "fetch" || functionName === "transform" || functionName === "resolveId") {
57
+ message += ` with "${JSON.stringify(args)}"`;
58
+ }
59
+ if (functionName === "onUnhandledError") {
60
+ message += ` with "${args[0]?.message || args[0]}"`;
61
+ }
62
+ throw new Error(message);
63
+ },
64
+ ...options
65
+ }));
66
+ return {
67
+ rpc,
68
+ onCancel
69
+ };
70
+ }
71
+ function createSafeRpc(rpc) {
72
+ return new Proxy(rpc, { get(target, p, handler) {
73
+ const sendCall = get(target, p, handler);
74
+ const safeSendCall = (...args) => withSafeTimers(async () => {
75
+ const result = sendCall(...args);
76
+ promises.add(result);
77
+ try {
78
+ return await result;
79
+ } finally {
80
+ promises.delete(result);
81
+ }
82
+ });
83
+ safeSendCall.asEvent = sendCall.asEvent;
84
+ return safeSendCall;
85
+ } });
86
+ }
87
+ function rpc() {
88
+ const { rpc } = getWorkerState();
89
+ return rpc;
90
+ }
91
+
92
+ export { rpcDone as a, createRuntimeRpc as c, rpc as r };
@@ -0,0 +1,47 @@
1
+ import { g as getWorkerState } from './utils.CtocqOoE.js';
2
+
3
+ const filesCount = new Map();
4
+ const cache = new Map();
5
+ /**
6
+ * This utils allows computational intensive tasks to only be ran once
7
+ * across test reruns to improve the watch mode performance.
8
+ *
9
+ * Currently only works with `poolOptions.<pool>.isolate: false`
10
+ *
11
+ * @experimental
12
+ */
13
+ function runOnce(fn, key) {
14
+ const filepath = getWorkerState().filepath || "__unknown_files__";
15
+ if (!key) {
16
+ filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
17
+ key = String(filesCount.get(filepath));
18
+ }
19
+ const id = `${filepath}:${key}`;
20
+ if (!cache.has(id)) {
21
+ cache.set(id, fn());
22
+ }
23
+ return cache.get(id);
24
+ }
25
+ /**
26
+ * Get a boolean indicates whether the task is running in the first time.
27
+ * Could only be `false` in watch mode.
28
+ *
29
+ * Currently only works with `isolate: false`
30
+ *
31
+ * @experimental
32
+ */
33
+ function isFirstRun() {
34
+ let firstRun = false;
35
+ runOnce(() => {
36
+ firstRun = true;
37
+ }, "__vitest_first_run__");
38
+ return firstRun;
39
+ }
40
+ /**
41
+ * @internal
42
+ */
43
+ function resetRunOnceCounter() {
44
+ filesCount.clear();
45
+ }
46
+
47
+ export { runOnce as a, isFirstRun as i, resetRunOnceCounter as r };
@@ -0,0 +1,134 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import { startTests, collectTests } from '@vitest/runner';
3
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.VfYQ6MXY.js';
4
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.DEGDGBiA.js';
5
+ import { a as globalExpect, v as vi } from './vi.B-PuvDzu.js';
6
+ import { c as closeInspector } from './inspector.DbDkSkFn.js';
7
+ import { createRequire } from 'node:module';
8
+ import timers from 'node:timers';
9
+ import timersPromises from 'node:timers/promises';
10
+ import util from 'node:util';
11
+ import { getSafeTimers } from '@vitest/utils';
12
+ import { KNOWN_ASSET_TYPES } from 'vite-node/constants';
13
+ import { installSourcemapsSupport } from 'vite-node/source-map';
14
+ import { V as VitestIndex } from './index.BDobFbcz.js';
15
+ import { g as getWorkerState, r as resetModules } from './utils.CtocqOoE.js';
16
+ import 'chai';
17
+ import 'node:path';
18
+ import '../path.js';
19
+ import 'node:url';
20
+ import './rpc.DGgL5dw7.js';
21
+ import './index.68735LiX.js';
22
+ import './coverage.0iPg4Wrz.js';
23
+ import '@vitest/snapshot';
24
+ import './run-once.I7PpBOk1.js';
25
+ import '@vitest/expect';
26
+ import '@vitest/runner/utils';
27
+ import './_commonjsHelpers.BFTU3MAI.js';
28
+ import '@vitest/utils/error';
29
+ import '@vitest/spy';
30
+ import '@vitest/utils/source-map';
31
+ import './date.CDOsz-HY.js';
32
+ import './benchmark.BKUatJGy.js';
33
+ import 'expect-type';
34
+
35
+ let globalSetup = false;
36
+ async function setupGlobalEnv(config, { environment }, executor) {
37
+ await setupCommonEnv(config);
38
+ Object.defineProperty(globalThis, "__vitest_index__", {
39
+ value: VitestIndex,
40
+ enumerable: false
41
+ });
42
+ const state = getWorkerState();
43
+ if (!state.config.snapshotOptions.snapshotEnvironment) {
44
+ state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, executor);
45
+ }
46
+ if (globalSetup) {
47
+ return;
48
+ }
49
+ globalSetup = true;
50
+ if (environment.transformMode === "web") {
51
+ const _require = createRequire(import.meta.url);
52
+ _require.extensions[".css"] = resolveCss;
53
+ _require.extensions[".scss"] = resolveCss;
54
+ _require.extensions[".sass"] = resolveCss;
55
+ _require.extensions[".less"] = resolveCss;
56
+ KNOWN_ASSET_TYPES.forEach((type) => {
57
+ _require.extensions[`.${type}`] = resolveAsset;
58
+ });
59
+ process.env.SSR = "";
60
+ } else {
61
+ process.env.SSR = "1";
62
+ }
63
+ globalThis.__vitest_required__ = {
64
+ util,
65
+ timers,
66
+ timersPromises
67
+ };
68
+ installSourcemapsSupport({ getSourceMap: (source) => state.moduleCache.getSourceMap(source) });
69
+ if (!config.disableConsoleIntercept) {
70
+ await setupConsoleLogSpy();
71
+ }
72
+ }
73
+ function resolveCss(mod) {
74
+ mod.exports = "";
75
+ }
76
+ function resolveAsset(mod, url) {
77
+ mod.exports = url;
78
+ }
79
+ async function setupConsoleLogSpy() {
80
+ const { createCustomConsole } = await import('./console.D6t261w0.js');
81
+ globalThis.console = createCustomConsole();
82
+ }
83
+ async function withEnv({ environment }, options, fn) {
84
+ globalThis.__vitest_environment__ = environment.name;
85
+ globalExpect.setState({ environment: environment.name });
86
+ const env = await environment.setup(globalThis, options);
87
+ try {
88
+ await fn();
89
+ } finally {
90
+ const { setTimeout } = getSafeTimers();
91
+ await new Promise((resolve) => setTimeout(resolve));
92
+ await env.teardown(globalThis);
93
+ }
94
+ }
95
+
96
+ async function run(method, files, config, environment, executor) {
97
+ const workerState = getWorkerState();
98
+ const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
99
+ const isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true);
100
+ const isolate = isIsolatedThreads || isIsolatedForks;
101
+ await setupGlobalEnv(config, environment, executor);
102
+ await startCoverageInsideWorker(config.coverage, executor, { isolate });
103
+ if (config.chaiConfig) {
104
+ setupChaiConfig(config.chaiConfig);
105
+ }
106
+ const runner = await resolveTestRunner(config, executor);
107
+ workerState.onCancel.then((reason) => {
108
+ closeInspector(config);
109
+ runner.onCancel?.(reason);
110
+ });
111
+ workerState.durations.prepare = performance.now() - workerState.durations.prepare;
112
+ workerState.durations.environment = performance.now();
113
+ await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
114
+ workerState.durations.environment = performance.now() - workerState.durations.environment;
115
+ for (const file of files) {
116
+ if (isolate) {
117
+ executor.mocker.reset();
118
+ resetModules(workerState.moduleCache, true);
119
+ }
120
+ workerState.filepath = file.filepath;
121
+ if (method === "run") {
122
+ await startTests([file], runner);
123
+ } else {
124
+ await collectTests([file], runner);
125
+ }
126
+ vi.resetConfig();
127
+ vi.restoreAllMocks();
128
+ }
129
+ await stopCoverageInsideWorker(config.coverage, executor, { isolate });
130
+ });
131
+ workerState.environmentTeardownRun = true;
132
+ }
133
+
134
+ export { run };
@@ -0,0 +1,88 @@
1
+ import { r as resolveCoverageProviderModule } from './coverage.0iPg4Wrz.js';
2
+ import { addSerializer } from '@vitest/snapshot';
3
+ import { setSafeTimers } from '@vitest/utils';
4
+ import { r as resetRunOnceCounter } from './run-once.I7PpBOk1.js';
5
+
6
+ async function startCoverageInsideWorker(options, loader, runtimeOptions) {
7
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
8
+ if (coverageModule) {
9
+ return coverageModule.startCoverage?.(runtimeOptions);
10
+ }
11
+ return null;
12
+ }
13
+ async function takeCoverageInsideWorker(options, loader) {
14
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
15
+ if (coverageModule) {
16
+ return coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo });
17
+ }
18
+ return null;
19
+ }
20
+ async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
21
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
22
+ if (coverageModule) {
23
+ return coverageModule.stopCoverage?.(runtimeOptions);
24
+ }
25
+ return null;
26
+ }
27
+
28
+ let globalSetup = false;
29
+ async function setupCommonEnv(config) {
30
+ resetRunOnceCounter();
31
+ setupDefines(config.defines);
32
+ setupEnv(config.env);
33
+ if (globalSetup) {
34
+ return;
35
+ }
36
+ globalSetup = true;
37
+ setSafeTimers();
38
+ if (config.globals) {
39
+ (await import('./globals.DCbUWjip.js')).registerApiGlobally();
40
+ }
41
+ }
42
+ function setupDefines(defines) {
43
+ for (const key in defines) {
44
+ globalThis[key] = defines[key];
45
+ }
46
+ }
47
+ function setupEnv(env) {
48
+ if (typeof process === "undefined") {
49
+ return;
50
+ }
51
+ const { PROD, DEV,...restEnvs } = env;
52
+ process.env.PROD = PROD ? "1" : "";
53
+ process.env.DEV = DEV ? "1" : "";
54
+ for (const key in restEnvs) {
55
+ process.env[key] = env[key];
56
+ }
57
+ }
58
+ async function loadDiffConfig(config, executor) {
59
+ if (typeof config.diff === "object") {
60
+ return config.diff;
61
+ }
62
+ if (typeof config.diff !== "string") {
63
+ return;
64
+ }
65
+ const diffModule = await executor.executeId(config.diff);
66
+ if (diffModule && typeof diffModule.default === "object" && diffModule.default != null) {
67
+ return diffModule.default;
68
+ } else {
69
+ throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
70
+ }
71
+ }
72
+ async function loadSnapshotSerializers(config, executor) {
73
+ const files = config.snapshotSerializers;
74
+ const snapshotSerializers = await Promise.all(files.map(async (file) => {
75
+ const mo = await executor.executeId(file);
76
+ if (!mo || typeof mo.default !== "object" || mo.default === null) {
77
+ throw new Error(`invalid snapshot serializer file ${file}. Must export a default object`);
78
+ }
79
+ const config = mo.default;
80
+ if (typeof config.test !== "function" || typeof config.serialize !== "function" && typeof config.print !== "function") {
81
+ throw new TypeError(`invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`);
82
+ }
83
+ return config;
84
+ }));
85
+ snapshotSerializers.forEach((serializer) => addSerializer(serializer));
86
+ }
87
+
88
+ export { stopCoverageInsideWorker as a, loadSnapshotSerializers as b, setupCommonEnv as c, loadDiffConfig as l, startCoverageInsideWorker as s, takeCoverageInsideWorker as t };