vitest 4.0.9 → 4.0.11

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 (58) hide show
  1. package/dist/browser.d.ts +4 -3
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
  4. package/dist/chunks/{base.CiIV2DDC.js → base.DiCUKpyF.js} +47 -40
  5. package/dist/chunks/{browser.d.DnU_kh8a.d.ts → browser.d.D-d8eZY4.d.ts} +1 -1
  6. package/dist/chunks/{cac.B_NTJoIH.js → cac.aVhqBj0-.js} +21 -7
  7. package/dist/chunks/{cli-api.D48wY175.js → cli-api.-bIZD4XU.js} +960 -345
  8. package/dist/chunks/{coverage.BUlIqJrL.js → coverage.CtyeYmKM.js} +7 -1
  9. package/dist/chunks/{creator.BzqvXeRE.js → creator.DAmOKTvJ.js} +5 -5
  10. package/dist/chunks/{global.d.BQDgW9Pr.d.ts → global.d.uY4Q0M5z.d.ts} +1 -1
  11. package/dist/chunks/{globals.DBrtKPdh.js → globals.C0izxiX3.js} +3 -3
  12. package/dist/chunks/{index.op2Re5rn.js → index.CMvpbrsJ.js} +1 -1
  13. package/dist/chunks/{index.CPA8jGhR.js → index.CQwQ_SLL.js} +16 -4
  14. package/dist/chunks/{index.z7NPOg2E.js → index.D4KonVSU.js} +1 -1
  15. package/dist/chunks/{index.CGezRSGU.js → index.DBx1AtPJ.js} +3 -2
  16. package/dist/chunks/{index.kotH7DY7.js → index.DWDW6mLz.js} +15 -4
  17. package/dist/chunks/{index.BfmpdV5p.js → index.QWbK7rHY.js} +3 -3
  18. package/dist/chunks/init-forks.DIuGPyId.js +32 -0
  19. package/dist/chunks/{init-threads.C7T0-YMD.js → init-threads.jC_8JdoN.js} +3 -3
  20. package/dist/chunks/{init.BQhNfT0h.js → init.B3IeC_yW.js} +60 -22
  21. package/dist/chunks/{moduleRunner.d.BxT-OjLR.d.ts → moduleRunner.d.B5SW5pMI.d.ts} +9 -1
  22. package/dist/chunks/plugin.d.N8khPRFb.d.ts +38 -0
  23. package/dist/chunks/{reporters.d.BQ0wpUaj.d.ts → reporters.d.DgZLBdyd.d.ts} +109 -48
  24. package/dist/chunks/{setup-common.Dw1XgX0v.js → setup-common.DGHc_BUK.js} +2 -2
  25. package/dist/chunks/{startModuleRunner.DLjmA_wU.js → startModuleRunner.DaBMy1JT.js} +97 -49
  26. package/dist/chunks/{test.w5HLbjmU.js → test.DqQZzsWf.js} +15 -5
  27. package/dist/chunks/traces.BVPrsYso.js +151 -0
  28. package/dist/chunks/{config.d.BTfZNUu9.d.ts → traces.d.B8ukBJqA.d.ts} +36 -1
  29. package/dist/chunks/{vi.CyIUVSoU.js → vi.BiaV1qII.js} +2 -2
  30. package/dist/chunks/{vm.DXN8eCh2.js → vm.BKyGp1KW.js} +12 -8
  31. package/dist/chunks/{worker.d.ZGohxCEd.d.ts → worker.d.B_PZTrCQ.d.ts} +5 -4
  32. package/dist/cli.js +2 -2
  33. package/dist/config.d.ts +8 -7
  34. package/dist/coverage.d.ts +6 -5
  35. package/dist/coverage.js +2 -2
  36. package/dist/environments.js +1 -1
  37. package/dist/index.d.ts +14 -12
  38. package/dist/index.js +4 -4
  39. package/dist/module-evaluator.d.ts +7 -6
  40. package/dist/module-evaluator.js +14 -1
  41. package/dist/module-runner.js +2 -1
  42. package/dist/node.d.ts +11 -10
  43. package/dist/node.js +12 -11
  44. package/dist/reporters.d.ts +6 -5
  45. package/dist/reporters.js +2 -2
  46. package/dist/runners.d.ts +5 -1
  47. package/dist/runners.js +3 -3
  48. package/dist/worker.d.ts +8 -7
  49. package/dist/worker.js +11 -10
  50. package/dist/workers/forks.js +12 -12
  51. package/dist/workers/runVmTests.js +24 -22
  52. package/dist/workers/threads.js +12 -11
  53. package/dist/workers/vmForks.js +6 -6
  54. package/dist/workers/vmThreads.js +6 -5
  55. package/package.json +19 -14
  56. package/dist/chunks/_commonjsHelpers.BFTU3MAI.js +0 -7
  57. package/dist/chunks/init-forks.aqTzCSR2.js +0 -65
  58. package/dist/chunks/plugin.d.DevON6kQ.d.ts +0 -9
@@ -1,13 +1,13 @@
1
- import { TaskMeta, Suite, File, TestAnnotation, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
1
+ import { TaskMeta, Suite, File, TestAnnotation, TestArtifact, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
2
  import { TestError, SerializedError, Arrayable, ParsedStack, Awaitable } from '@vitest/utils';
3
- import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, d as ContextTestEnvironment, f as WorkerTestEnvironment, g as WorkerExecuteContext, L as LabelColor } from './worker.d.ZGohxCEd.js';
3
+ import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, d as ContextTestEnvironment, f as WorkerTestEnvironment, g as WorkerExecuteContext, L as LabelColor } from './worker.d.B_PZTrCQ.js';
4
4
  import { Writable } from 'node:stream';
5
5
  import { TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
6
6
  import { MockedModule } from '@vitest/mocker';
7
7
  import { StackTraceParserOptions } from '@vitest/utils/source-map';
8
8
  import { BrowserCommands } from 'vitest/browser';
9
- import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.BTfZNUu9.js';
10
- import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.DnU_kh8a.js';
9
+ import { B as BrowserTraceViewMode, S as SerializedConfig, O as OTELCarrier, F as FakeTimerInstallOpts } from './traces.d.B8ukBJqA.js';
10
+ import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.D-d8eZY4.js';
11
11
  import { PrettyFormatOptions } from '@vitest/pretty-format';
12
12
  import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
13
13
  import { SerializedDiffOptions } from '@vitest/utils/diff';
@@ -16,8 +16,8 @@ import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
16
16
  import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
17
17
  import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
18
18
  import { SnapshotManager } from '@vitest/snapshot/manager';
19
- import { Stats } from 'node:fs';
20
19
  import { Console } from 'node:console';
20
+ import { Stats } from 'node:fs';
21
21
 
22
22
  type ChaiConfig = Omit<Partial<typeof chai.config>, "useProxy" | "proxyExcludedKeys">;
23
23
 
@@ -134,6 +134,12 @@ declare class TestCase extends ReportedTaskImplementation {
134
134
  */
135
135
  annotations(): ReadonlyArray<TestAnnotation>;
136
136
  /**
137
+ * @experimental
138
+ *
139
+ * Test artifacts recorded via the `recordArtifact` API during the test execution.
140
+ */
141
+ artifacts(): ReadonlyArray<TestArtifact>;
142
+ /**
137
143
  * Useful information about the test like duration, memory usage, etc.
138
144
  * Diagnostic is only available after the test has finished.
139
145
  */
@@ -619,6 +625,12 @@ interface CoverageProvider {
619
625
  mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
620
626
  /** Callback called for instrumenting files with coverage counters. */
621
627
  onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
628
+ /**
629
+ * Return `true` if this file is transformed by the coverage provider.
630
+ * This is used to generate the persistent file hash by `fsModuleCache`
631
+ * @experimental
632
+ */
633
+ requiresTransform?: (id: string) => boolean;
622
634
  /** Callback that's called when the coverage is enabled via a programmatic `enableCoverage` API. */
623
635
  onEnabled?: () => void | Promise<void>;
624
636
  }
@@ -809,46 +821,6 @@ interface TestRunResult {
809
821
  unhandledErrors: unknown[];
810
822
  }
811
823
 
812
- interface SuiteResultCache {
813
- failed: boolean;
814
- duration: number;
815
- }
816
- declare class ResultsCache {
817
- private cache;
818
- private workspacesKeyMap;
819
- private cachePath;
820
- private version;
821
- private root;
822
- constructor(version: string);
823
- getCachePath(): string | null;
824
- setConfig(root: string, config: ResolvedConfig["cache"]): void;
825
- getResults(key: string): SuiteResultCache | undefined;
826
- readFromCache(): Promise<void>;
827
- updateResults(files: File[]): void;
828
- removeFromCache(filepath: string): void;
829
- writeToCache(): Promise<void>;
830
- }
831
-
832
- type FileStatsCache = Pick<Stats, "size">;
833
- declare class FilesStatsCache {
834
- cache: Map<string, FileStatsCache>;
835
- getStats(key: string): FileStatsCache | undefined;
836
- populateStats(root: string, specs: TestSpecification[]): Promise<void>;
837
- updateStats(fsPath: string, key: string): Promise<void>;
838
- removeStats(fsPath: string): void;
839
- }
840
-
841
- declare class VitestCache {
842
- results: ResultsCache;
843
- stats: FilesStatsCache;
844
- constructor(version: string);
845
- getFileTestResults(key: string): SuiteResultCache | undefined;
846
- getFileStats(key: string): {
847
- size: number;
848
- } | undefined;
849
- static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
850
- }
851
-
852
824
  declare class TypeCheckError extends Error {
853
825
  message: string;
854
826
  stacks: ParsedStack[];
@@ -896,6 +868,48 @@ declare class Logger {
896
868
  private registerUnhandledRejection;
897
869
  }
898
870
 
871
+ interface SuiteResultCache {
872
+ failed: boolean;
873
+ duration: number;
874
+ }
875
+ declare class ResultsCache {
876
+ private logger;
877
+ private cache;
878
+ private workspacesKeyMap;
879
+ private cachePath;
880
+ private version;
881
+ private root;
882
+ constructor(logger: Logger);
883
+ getCachePath(): string | null;
884
+ setConfig(root: string, config: ResolvedConfig["cache"]): void;
885
+ getResults(key: string): SuiteResultCache | undefined;
886
+ clearCache(): Promise<void>;
887
+ readFromCache(): Promise<void>;
888
+ updateResults(files: File[]): void;
889
+ removeFromCache(filepath: string): void;
890
+ writeToCache(): Promise<void>;
891
+ }
892
+
893
+ type FileStatsCache = Pick<Stats, "size">;
894
+ declare class FilesStatsCache {
895
+ cache: Map<string, FileStatsCache>;
896
+ getStats(key: string): FileStatsCache | undefined;
897
+ populateStats(root: string, specs: TestSpecification[]): Promise<void>;
898
+ updateStats(fsPath: string, key: string): Promise<void>;
899
+ removeStats(fsPath: string): void;
900
+ }
901
+
902
+ declare class VitestCache {
903
+ results: ResultsCache;
904
+ stats: FilesStatsCache;
905
+ constructor(logger: Logger);
906
+ getFileTestResults(key: string): SuiteResultCache | undefined;
907
+ getFileStats(key: string): {
908
+ size: number;
909
+ } | undefined;
910
+ static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
911
+ }
912
+
899
913
  declare class VitestPackageInstaller {
900
914
  isPackageExists(name: string, options?: {
901
915
  paths?: string[];
@@ -957,6 +971,10 @@ interface Reporter {
957
971
  */
958
972
  onTestCaseAnnotate?: (testCase: TestCase, annotation: TestAnnotation) => Awaitable<void>;
959
973
  /**
974
+ * Called when artifacts are recorded on tests via the `recordArtifact` utility.
975
+ */
976
+ onTestCaseArtifactRecord?: (testCase: TestCase, artifact: TestArtifact) => Awaitable<void>;
977
+ /**
960
978
  * Called when test suite is ready to run.
961
979
  * Called before the `beforeAll` hooks for the test are run.
962
980
  */
@@ -1159,6 +1177,7 @@ declare class Vitest {
1159
1177
  get cache(): VitestCache;
1160
1178
  enableCoverage(): Promise<void>;
1161
1179
  disableCoverage(): void;
1180
+ private clearAllCachePaths;
1162
1181
  private _coverageOverrideCache;
1163
1182
  /**
1164
1183
  * Inject new test projects into the workspace.
@@ -1196,6 +1215,11 @@ declare class Vitest {
1196
1215
  globTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
1197
1216
  private initCoverageProvider;
1198
1217
  /**
1218
+ * Deletes all Vitest caches, including `experimental.fsModuleCache`.
1219
+ * @experimental
1220
+ */
1221
+ experimental_clearCache(): Promise<void>;
1222
+ /**
1199
1223
  * Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
1200
1224
  */
1201
1225
  mergeReports(directory?: string): Promise<TestRunResult>;
@@ -1325,7 +1349,7 @@ declare class Vitest {
1325
1349
  /**
1326
1350
  * Register a handler that will be called when the test run is cancelled with `vitest.cancelCurrentRun`.
1327
1351
  */
1328
- onCancel(fn: (reason: CancelReason) => Awaitable<void>): void;
1352
+ onCancel(fn: (reason: CancelReason) => Awaitable<void>): () => void;
1329
1353
  /**
1330
1354
  * Register a handler that will be called when the server is closed.
1331
1355
  */
@@ -1377,7 +1401,7 @@ interface BrowserServerOptions {
1377
1401
  metaEnvReplacer: () => Plugin;
1378
1402
  }
1379
1403
  interface BrowserServerFactory {
1380
- (otpions: BrowserServerOptions): Promise<ParentProjectBrowser>;
1404
+ (options: BrowserServerOptions): Promise<ParentProjectBrowser>;
1381
1405
  }
1382
1406
  interface BrowserProvider {
1383
1407
  name: string;
@@ -1919,16 +1943,24 @@ type WorkerRequest = {
1919
1943
  config: SerializedConfig;
1920
1944
  pool: string;
1921
1945
  };
1946
+ traces: {
1947
+ enabled: boolean;
1948
+ sdkPath?: string;
1949
+ otelCarrier?: OTELCarrier;
1950
+ };
1922
1951
  } | {
1923
1952
  type: "stop";
1953
+ otelCarrier?: OTELCarrier;
1924
1954
  } | {
1925
1955
  type: "run";
1926
1956
  context: WorkerExecuteContext;
1927
1957
  poolId: number;
1958
+ otelCarrier?: OTELCarrier;
1928
1959
  } | {
1929
1960
  type: "collect";
1930
1961
  context: WorkerExecuteContext;
1931
1962
  poolId: number;
1963
+ otelCarrier?: OTELCarrier;
1932
1964
  } | {
1933
1965
  type: "cancel";
1934
1966
  });
@@ -1965,6 +1997,7 @@ declare abstract class BaseReporter implements Reporter {
1965
1997
  log(...messages: any): void;
1966
1998
  error(...messages: any): void;
1967
1999
  relative(path: string): string;
2000
+ onTestRunStart(_specifications: ReadonlyArray<TestSpecification>): void;
1968
2001
  onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, _reason: TestRunEndReason): void;
1969
2002
  onTestCaseResult(testCase: TestCase): void;
1970
2003
  onTestSuiteResult(testSuite: TestSuite): void;
@@ -2962,6 +2995,29 @@ interface InlineConfig {
2962
2995
  * @default '.vitest-attachments'
2963
2996
  */
2964
2997
  attachmentsDir?: string;
2998
+ /**
2999
+ * Experimental features
3000
+ *
3001
+ * @experimental
3002
+ */
3003
+ experimental?: {
3004
+ /**
3005
+ * Enable caching of modules on the file system between reruns.
3006
+ */
3007
+ fsModuleCache?: boolean;
3008
+ /**
3009
+ * Path relative to the root of the project where the fs module cache will be stored.
3010
+ * @default node_modules/.experimental-vitest-cache
3011
+ */
3012
+ fsModuleCachePath?: string;
3013
+ /**
3014
+ * {@link https://vitest.dev/guide/open-telemetry}
3015
+ */
3016
+ openTelemetry?: {
3017
+ enabled: boolean;
3018
+ sdkPath?: string;
3019
+ };
3020
+ };
2965
3021
  }
2966
3022
  interface TypecheckConfig {
2967
3023
  /**
@@ -3077,6 +3133,11 @@ interface UserConfig extends InlineConfig {
3077
3133
  * @default '.vitest-reports'
3078
3134
  */
3079
3135
  mergeReports?: string;
3136
+ /**
3137
+ * Delete all Vitest caches, including `experimental.fsModuleCache`.
3138
+ * @experimental
3139
+ */
3140
+ clearCache?: boolean;
3080
3141
  }
3081
3142
  type OnUnhandledErrorCallback = (error: (TestError | Error) & {
3082
3143
  type: string;
@@ -3181,4 +3242,4 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
3181
3242
  type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3182
3243
 
3183
3244
  export { CoverageMap as C, TestSuite as K, Logger as L, experimental_getRunnerTask as Q, TestProject as T, Vitest as V, BenchmarkReporter as aE, BenchmarkReportsMap as aF, DefaultReporter as aG, DotReporter as aH, GithubActionsReporter as aI, HangingProcessReporter as aJ, JsonReporter as aK, JUnitReporter as aL, ReportersMap as aM, TapFlatReporter as aN, TapReporter as aO, VerboseBenchmarkReporter as aP, VerboseReporter as aQ, BaseReporter as aR, TestSpecification as k, VitestPackageInstaller as p, TestCase as v, TestCollection as w, TestModule as y };
3184
- export type { BrowserCommand as $, ApiConfig as A, TestResult as B, TestResultFailed as D, TestResultPassed as E, TestResultSkipped as F, TestState as G, HTMLOptions as H, InlineConfig as I, JsonOptions as J, ModuleDiagnostic as M, TestSuiteState as N, OnServerRestartHandler as O, PoolWorker as P, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, TestSequencerConstructor as X, BenchmarkUserOptions as Y, BrowserBuiltinProvider as Z, _BrowserNames as _, TestProjectConfiguration as a, BrowserCommandContext as a0, BrowserConfigOptions as a1, BrowserInstanceOption as a2, BrowserModuleMocker as a3, BrowserOrchestrator as a4, BrowserProvider as a5, BrowserProviderOption as a6, BrowserScript as a7, BrowserServerFactory as a8, BrowserServerOptions as a9, TestRunResult as aA, ReportedHookContext as aB, Reporter as aC, TestRunEndReason as aD, BenchmarkBuiltinReporters as aS, BuiltinReporterOptions as aT, BuiltinReporters as aU, JsonAssertionResult as aV, JsonTestResult as aW, JsonTestResults as aX, BrowserServerState as aa, BrowserServerStateSession as ab, CDPSession as ac, ParentProjectBrowser as ad, ProjectBrowser as ae, ResolvedBrowserOptions as af, ToMatchScreenshotComparators as ag, ToMatchScreenshotOptions as ah, BuiltinEnvironment as ai, CSSModuleScopeStrategy as aj, DepsOptimizationOptions as ak, EnvironmentOptions as al, Pool as am, ProjectConfig as an, ResolvedProjectConfig as ao, ResolveSnapshotPathHandler as ap, ResolveSnapshotPathHandlerContext as aq, TypecheckConfig as ar, VitestEnvironment as as, BaseCoverageOptions as at, CoverageIstanbulOptions as au, CoverageOptions as av, CoverageProvider as aw, CoverageProviderModule as ax, CoverageReporter as ay, CustomProviderOptions as az, ReportContext as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, PoolOptions as l, WorkerRequest as m, TestSequencer as n, OnTestsRerunHandler as o, PoolRunnerInitializer as q, PoolTask as r, WorkerResponse as s, JUnitOptions as t, TaskOptions as u, TestDiagnostic as x, TestModuleState as z };
3245
+ export type { BrowserCommand as $, ApiConfig as A, TestResult as B, TestResultFailed as D, TestResultPassed as E, TestResultSkipped as F, TestState as G, HTMLOptions as H, InlineConfig as I, JsonOptions as J, ModuleDiagnostic as M, TestSuiteState as N, OnServerRestartHandler as O, PoolWorker as P, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, TestSequencerConstructor as X, BenchmarkUserOptions as Y, BrowserBuiltinProvider as Z, _BrowserNames as _, ReportContext as a, BrowserCommandContext as a0, BrowserConfigOptions as a1, BrowserInstanceOption as a2, BrowserModuleMocker as a3, BrowserOrchestrator as a4, BrowserProvider as a5, BrowserProviderOption as a6, BrowserScript as a7, BrowserServerFactory as a8, BrowserServerOptions as a9, TestRunResult as aA, ReportedHookContext as aB, Reporter as aC, TestRunEndReason as aD, BenchmarkBuiltinReporters as aS, BuiltinReporterOptions as aT, BuiltinReporters as aU, JsonAssertionResult as aV, JsonTestResult as aW, JsonTestResults as aX, BrowserServerState as aa, BrowserServerStateSession as ab, CDPSession as ac, ParentProjectBrowser as ad, ProjectBrowser as ae, ResolvedBrowserOptions as af, ToMatchScreenshotComparators as ag, ToMatchScreenshotOptions as ah, BuiltinEnvironment as ai, CSSModuleScopeStrategy as aj, DepsOptimizationOptions as ak, EnvironmentOptions as al, Pool as am, ProjectConfig as an, ResolvedProjectConfig as ao, ResolveSnapshotPathHandler as ap, ResolveSnapshotPathHandlerContext as aq, TypecheckConfig as ar, VitestEnvironment as as, BaseCoverageOptions as at, CoverageIstanbulOptions as au, CoverageOptions as av, CoverageProvider as aw, CoverageProviderModule as ax, CoverageReporter as ay, CustomProviderOptions as az, TestProjectConfiguration as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, PoolOptions as l, WorkerRequest as m, TestSequencer as n, OnTestsRerunHandler as o, PoolRunnerInitializer as q, PoolTask as r, WorkerResponse as s, JUnitOptions as t, TaskOptions as u, TestDiagnostic as x, TestModuleState as z };
@@ -26,7 +26,7 @@ async function setupCommonEnv(config) {
26
26
  if (globalSetup) return;
27
27
  globalSetup = true;
28
28
  setSafeTimers();
29
- if (config.globals) (await import('./globals.DBrtKPdh.js')).registerApiGlobally();
29
+ if (config.globals) (await import('./globals.C0izxiX3.js')).registerApiGlobally();
30
30
  }
31
31
  function setupDefines(config) {
32
32
  for (const key in config.defines) globalThis[key] = config.defines[key];
@@ -34,7 +34,7 @@ function setupDefines(config) {
34
34
  function setupEnv(env) {
35
35
  const state = getWorkerState();
36
36
  // same boolean-to-string assignment as VitestPlugin.configResolved
37
- const { PROD, DEV,...restEnvs } = env;
37
+ const { PROD, DEV, ...restEnvs } = env;
38
38
  state.metaEnv.PROD = PROD;
39
39
  state.metaEnv.DEV = DEV;
40
40
  for (const key in restEnvs) state.metaEnv[key] = env[key];
@@ -10,6 +10,7 @@ import { resolve as resolve$1, isAbsolute as isAbsolute$1 } from 'node:path';
10
10
  import vm from 'node:vm';
11
11
  import { MockerRegistry, mockObject, RedirectedModule, AutomockedModule } from '@vitest/mocker';
12
12
  import * as viteModuleRunner from 'vite/module-runner';
13
+ import { T as Traces } from './traces.BVPrsYso.js';
13
14
 
14
15
  class VitestTransport {
15
16
  constructor(options) {
@@ -234,10 +235,12 @@ class VitestMocker {
234
235
  filterPublicKeys;
235
236
  registries = /* @__PURE__ */ new Map();
236
237
  mockContext = { callstack: null };
238
+ _otel;
237
239
  constructor(moduleRunner, options) {
238
240
  this.moduleRunner = moduleRunner;
239
241
  this.options = options;
240
242
  const context = this.options.context;
243
+ this._otel = options.traces;
241
244
  if (context) this.primitives = vm.runInContext("({ Object, Error, Function, RegExp, Symbol, Array, Map })", context);
242
245
  else this.primitives = {
243
246
  Object,
@@ -309,23 +312,41 @@ class VitestMocker {
309
312
  return error;
310
313
  }
311
314
  async resolveId(rawId, importer) {
312
- const result = await this.options.resolveId(rawId, importer);
313
- if (!result) {
314
- const id = normalizeModuleId(rawId);
315
+ return this._otel.$("vitest.mocker.resolve_id", { attributes: {
316
+ "vitest.module.raw_id": rawId,
317
+ "vitest.module.importer": rawId
318
+ } }, async (span) => {
319
+ const result = await this.options.resolveId(rawId, importer);
320
+ if (!result) {
321
+ span.addEvent("could not resolve id, fallback to unresolved values");
322
+ const id = normalizeModuleId(rawId);
323
+ span.setAttributes({
324
+ "vitest.module.id": id,
325
+ "vitest.module.url": rawId,
326
+ "vitest.module.external": id,
327
+ "vitest.module.fallback": true
328
+ });
329
+ return {
330
+ id,
331
+ url: rawId,
332
+ external: id
333
+ };
334
+ }
335
+ // external is node_module or unresolved module
336
+ // for example, some people mock "vscode" and don't have it installed
337
+ const external = !isAbsolute$1(result.file) || this.isModuleDirectory(result.file) ? normalizeModuleId(rawId) : null;
338
+ const id = normalizeModuleId(result.id);
339
+ span.setAttributes({
340
+ "vitest.module.id": id,
341
+ "vitest.module.url": result.url,
342
+ "vitest.module.external": external ?? false
343
+ });
315
344
  return {
345
+ ...result,
316
346
  id,
317
- url: rawId,
318
- external: id
347
+ external
319
348
  };
320
- }
321
- // external is node_module or unresolved module
322
- // for example, some people mock "vscode" and don't have it installed
323
- const external = !isAbsolute$1(result.file) || this.isModuleDirectory(result.file) ? normalizeModuleId(rawId) : null;
324
- return {
325
- ...result,
326
- id: normalizeModuleId(result.id),
327
- external
328
- };
349
+ });
329
350
  }
330
351
  async resolveMocks() {
331
352
  if (!VitestMocker.pendingIds.length) return;
@@ -437,40 +458,52 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
437
458
  return this.moduleRunner.cachedRequest(mock.redirect, node, [importer], void 0, true);
438
459
  }
439
460
  async requestWithMockedModule(url, evaluatedNode, callstack, mock) {
440
- const mockId = this.getMockPath(evaluatedNode.id);
441
- if (mock.type === "automock" || mock.type === "autospy") {
442
- const cache = this.evaluatedModules.getModuleById(mockId);
443
- if (cache && cache.mockedExports) return cache.mockedExports;
444
- const Object = this.primitives.Object;
445
- // we have to define a separate object that will copy all properties into itself
446
- // and can't just use the same `exports` define automatically by Vite before the evaluator
447
- const exports$1 = Object.create(null);
448
- Object.defineProperty(exports$1, Symbol.toStringTag, {
449
- value: "Module",
450
- configurable: true,
451
- writable: true
461
+ return this._otel.$("vitest.mocker.evaluate", async (span) => {
462
+ const mockId = this.getMockPath(evaluatedNode.id);
463
+ span.setAttributes({
464
+ "vitest.module.id": mockId,
465
+ "vitest.mock.type": mock.type,
466
+ "vitest.mock.id": mock.id,
467
+ "vitest.mock.url": mock.url,
468
+ "vitest.mock.raw": mock.raw
452
469
  });
453
- const node = this.ensureModule(mockId, this.getMockPath(evaluatedNode.url));
454
- node.meta = evaluatedNode.meta;
455
- node.file = evaluatedNode.file;
456
- node.mockedExports = exports$1;
457
- const mod = await this.moduleRunner.cachedRequest(url, node, callstack, void 0, true);
458
- this.mockObject(mod, exports$1, mock.type);
459
- return exports$1;
460
- }
461
- if (mock.type === "manual" && !callstack.includes(mockId) && !callstack.includes(url)) try {
462
- callstack.push(mockId);
463
- // this will not work if user does Promise.all(import(), import())
464
- // we can also use AsyncLocalStorage to store callstack, but this won't work in the browser
465
- // maybe we should improve mock API in the future?
466
- this.mockContext.callstack = callstack;
467
- return await this.callFunctionMock(mockId, this.getMockPath(url), mock);
468
- } finally {
469
- this.mockContext.callstack = null;
470
- const indexMock = callstack.indexOf(mockId);
471
- callstack.splice(indexMock, 1);
472
- }
473
- else if (mock.type === "redirect" && !callstack.includes(mock.redirect)) return mock.redirect;
470
+ if (mock.type === "automock" || mock.type === "autospy") {
471
+ const cache = this.evaluatedModules.getModuleById(mockId);
472
+ if (cache && cache.mockedExports) return cache.mockedExports;
473
+ const Object = this.primitives.Object;
474
+ // we have to define a separate object that will copy all properties into itself
475
+ // and can't just use the same `exports` define automatically by Vite before the evaluator
476
+ const exports$1 = Object.create(null);
477
+ Object.defineProperty(exports$1, Symbol.toStringTag, {
478
+ value: "Module",
479
+ configurable: true,
480
+ writable: true
481
+ });
482
+ const node = this.ensureModule(mockId, this.getMockPath(evaluatedNode.url));
483
+ node.meta = evaluatedNode.meta;
484
+ node.file = evaluatedNode.file;
485
+ node.mockedExports = exports$1;
486
+ const mod = await this.moduleRunner.cachedRequest(url, node, callstack, void 0, true);
487
+ this.mockObject(mod, exports$1, mock.type);
488
+ return exports$1;
489
+ }
490
+ if (mock.type === "manual" && !callstack.includes(mockId) && !callstack.includes(url)) try {
491
+ callstack.push(mockId);
492
+ // this will not work if user does Promise.all(import(), import())
493
+ // we can also use AsyncLocalStorage to store callstack, but this won't work in the browser
494
+ // maybe we should improve mock API in the future?
495
+ this.mockContext.callstack = callstack;
496
+ return await this.callFunctionMock(mockId, this.getMockPath(url), mock);
497
+ } finally {
498
+ this.mockContext.callstack = null;
499
+ const indexMock = callstack.indexOf(mockId);
500
+ callstack.splice(indexMock, 1);
501
+ }
502
+ else if (mock.type === "redirect" && !callstack.includes(mock.redirect)) {
503
+ span.setAttribute("vitest.mock.redirect", mock.redirect);
504
+ return mock.redirect;
505
+ }
506
+ });
474
507
  }
475
508
  async mockedRequest(url, evaluatedNode, callstack) {
476
509
  const mock = this.getDependencyMock(evaluatedNode.id);
@@ -554,6 +587,7 @@ function createImportMetaResolver() {
554
587
  class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
555
588
  mocker;
556
589
  moduleExecutionInfo;
590
+ _otel;
557
591
  constructor(vitestOptions) {
558
592
  const options = vitestOptions;
559
593
  const transport = new VitestTransport(options.transport);
@@ -566,10 +600,12 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
566
600
  createImportMeta: vitestOptions.createImportMeta
567
601
  }, options.evaluator);
568
602
  this.vitestOptions = vitestOptions;
603
+ this._otel = vitestOptions.traces || new Traces({ enabled: false });
569
604
  this.moduleExecutionInfo = options.getWorkerState().moduleExecutionInfo;
570
605
  this.mocker = options.mocker || new VitestMocker(this, {
571
606
  spyModule: options.spyModule,
572
607
  context: options.vm?.context,
608
+ traces: this._otel,
573
609
  resolveId: options.transport.resolveId,
574
610
  get root() {
575
611
  return options.getWorkerState().config.root;
@@ -599,7 +635,15 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
599
635
  return exports$1;
600
636
  }
601
637
  async import(rawId) {
602
- const resolved = await this.vitestOptions.transport.resolveId(rawId);
638
+ const resolved = await this._otel.$("vitest.module.resolve_id", { attributes: { "vitest.module.raw_id": rawId } }, async (span) => {
639
+ const result = await this.vitestOptions.transport.resolveId(rawId);
640
+ if (result) span.setAttributes({
641
+ "vitest.module.url": result.url,
642
+ "vitest.module.file": result.file,
643
+ "vitest.module.id": result.id
644
+ });
645
+ return result;
646
+ });
603
647
  return super.import(resolved ? resolved.url : rawId);
604
648
  }
605
649
  async fetchModule(url, importer) {
@@ -716,6 +760,7 @@ const VITEST_VM_CONTEXT_SYMBOL = "__vitest_vm_context__";
716
760
  const cwd = process.cwd();
717
761
  const isWindows = process.platform === "win32";
718
762
  function startVitestModuleRunner(options) {
763
+ const traces = options.traces;
719
764
  const state = () => globalThis.__vitest_worker__ || options.state;
720
765
  const rpc = () => state().rpc;
721
766
  process.exit = (code = process.exitCode || 0) => {
@@ -731,6 +776,7 @@ function startVitestModuleRunner(options) {
731
776
  externalModulesExecutor: options.externalModulesExecutor
732
777
  } : void 0;
733
778
  const evaluator = options.evaluator || new VitestModuleEvaluator(vm, {
779
+ traces,
734
780
  get moduleExecutionInfo() {
735
781
  return state().moduleExecutionInfo;
736
782
  },
@@ -743,6 +789,7 @@ function startVitestModuleRunner(options) {
743
789
  spyModule: options.spyModule,
744
790
  evaluatedModules: options.evaluatedModules,
745
791
  evaluator,
792
+ traces,
746
793
  mocker: options.mocker,
747
794
  transport: {
748
795
  async fetchModule(id, importer, options) {
@@ -774,7 +821,8 @@ function startVitestModuleRunner(options) {
774
821
  externalize: toBuiltin(rawId),
775
822
  type: "builtin"
776
823
  };
777
- const result = await rpc().fetch(id, importer, environment(), options);
824
+ const otelCarrier = traces?.getContextCarrier();
825
+ const result = await rpc().fetch(id, importer, environment(), options, otelCarrier);
778
826
  if ("cached" in result) return {
779
827
  code: readFileSync(result.tmp, "utf-8"),
780
828
  ...result
@@ -7,7 +7,7 @@ import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
7
7
  import { getTests, getNames, getTestName } from '@vitest/runner/utils';
8
8
  import { processError } from '@vitest/utils/error';
9
9
  import { normalize } from 'pathe';
10
- import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.CyIUVSoU.js';
10
+ import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.BiaV1qII.js';
11
11
  import { r as rpc } from './rpc.BytlcPfC.js';
12
12
 
13
13
  function createBenchmarkResult(name) {
@@ -121,6 +121,7 @@ class VitestTestRunner {
121
121
  cancelRun = false;
122
122
  assertionsErrors = /* @__PURE__ */ new WeakMap();
123
123
  pool = this.workerState.ctx.pool;
124
+ _otel;
124
125
  constructor(config) {
125
126
  this.config = config;
126
127
  }
@@ -129,7 +130,7 @@ class VitestTestRunner {
129
130
  const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
130
131
  if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
131
132
  }
132
- return this.moduleRunner.import(filepath);
133
+ return this._otel.$(`vitest.module.import_${source === "setup" ? "setup" : "spec"}`, { attributes: { "code.file.path": filepath } }, () => this.moduleRunner.import(filepath));
133
134
  }
134
135
  onCollectStart(file) {
135
136
  this.workerState.current = file;
@@ -220,11 +221,20 @@ class VitestTestRunner {
220
221
  return context;
221
222
  }
222
223
  getImportDurations() {
223
- const entries = [...this.workerState.moduleExecutionInfo?.entries() ?? []];
224
- return Object.fromEntries(entries.map(([filepath, { duration, selfTime }]) => [normalize(filepath), {
224
+ const importDurations = {};
225
+ const entries = this.workerState.moduleExecutionInfo?.entries() || [];
226
+ for (const [filepath, { duration, selfTime }] of entries) importDurations[normalize(filepath)] = {
225
227
  selfTime,
226
228
  totalTime: duration
227
- }]));
229
+ };
230
+ return importDurations;
231
+ }
232
+ trace = (name, attributes, cb) => {
233
+ const options = typeof attributes === "object" ? { attributes } : {};
234
+ return this._otel.$(`vitest.test.runner.${name}`, options, cb || attributes);
235
+ };
236
+ __setTraces(traces) {
237
+ this._otel = traces;
228
238
  }
229
239
  }
230
240
  function clearModuleMocks(config) {