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
@@ -0,0 +1,151 @@
1
+ class Traces {
2
+ /**
3
+ * otel stands for OpenTelemetry
4
+ */
5
+ #otel = null;
6
+ #sdk = null;
7
+ #init = null;
8
+ #noopSpan = createNoopSpan();
9
+ #noopContext = createNoopContext();
10
+ constructor(options) {
11
+ if (options.enabled) {
12
+ const apiInit = import('@opentelemetry/api').then((api) => {
13
+ this.#otel = {
14
+ tracer: api.trace.getTracer(options.tracerName || "vitest"),
15
+ context: api.context,
16
+ propagation: api.propagation,
17
+ trace: api.trace,
18
+ SpanKind: api.SpanKind,
19
+ SpanStatusCode: api.SpanStatusCode
20
+ };
21
+ }).catch(() => {
22
+ throw new Error(`"@opentelemetry/api" is not installed locally. Make sure you have setup OpenTelemetry instrumentation: https://vitest.dev/guide/open-telemetry`);
23
+ });
24
+ const sdkInit = (options.sdkPath ? import(options.sdkPath) : Promise.resolve()).catch((cause) => {
25
+ throw new Error(`Failed to import custom OpenTelemetry SDK script (${options.sdkPath}): ${cause.message}`);
26
+ });
27
+ this.#init = Promise.all([sdkInit, apiInit]).then(([sdk]) => {
28
+ if (sdk != null) {
29
+ if (sdk.default != null && typeof sdk.default === "object" && typeof sdk.default.shutdown === "function") this.#sdk = sdk.default;
30
+ else if (options.watchMode !== true && process.env.VITEST_MODE !== "watch") console.warn(`OpenTelemetry instrumentation module (${options.sdkPath}) does not have a default export with a "shutdown" method. Vitest won't be able to ensure that all traces are processed in time. Try running Vitest in watch mode instead.`);
31
+ }
32
+ }).finally(() => {
33
+ this.#init = null;
34
+ });
35
+ }
36
+ }
37
+ isEnabled() {
38
+ return !!this.#otel;
39
+ }
40
+ async waitInit() {
41
+ if (this.#init) await this.#init;
42
+ return this;
43
+ }
44
+ startContextSpan(name, currentContext) {
45
+ if (!this.#otel) return {
46
+ span: this.#noopSpan,
47
+ context: this.#noopContext
48
+ };
49
+ const activeContext = currentContext || this.#otel.context.active();
50
+ const span = this.#otel.tracer.startSpan(name, {}, activeContext);
51
+ return {
52
+ span,
53
+ context: this.#otel.trace.setSpan(activeContext, span)
54
+ };
55
+ }
56
+ getContextFromCarrier(carrier) {
57
+ if (!this.#otel) return this.#noopContext;
58
+ const activeContext = this.#otel.context.active();
59
+ if (!carrier) return activeContext;
60
+ return this.#otel.propagation.extract(activeContext, carrier);
61
+ }
62
+ getContextCarrier(context) {
63
+ if (!this.#otel) return;
64
+ const carrier = {};
65
+ this.#otel.propagation.inject(context || this.#otel.context.active(), carrier);
66
+ return carrier;
67
+ }
68
+ #callActiveSpan(span, callback) {
69
+ const otel = this.#otel;
70
+ let result;
71
+ try {
72
+ result = callback(span);
73
+ if (result instanceof Promise) return result.catch((error) => {
74
+ span.recordException({
75
+ name: error.name,
76
+ message: error.message,
77
+ stack: error.stack
78
+ });
79
+ span.setStatus({ code: otel.SpanStatusCode.ERROR });
80
+ throw error;
81
+ }).finally(() => span.end());
82
+ return result;
83
+ } catch (error) {
84
+ if (error instanceof Error) {
85
+ span.recordException({
86
+ name: error.name,
87
+ message: error.message,
88
+ stack: error.stack
89
+ });
90
+ span.setStatus({ code: otel.SpanStatusCode.ERROR });
91
+ }
92
+ throw error;
93
+ } finally {
94
+ // end sync callbcak
95
+ if (!(result instanceof Promise)) span.end();
96
+ }
97
+ }
98
+ $(name, optionsOrFn, fn) {
99
+ const callback = typeof optionsOrFn === "function" ? optionsOrFn : fn;
100
+ if (!this.#otel) return callback(this.#noopSpan);
101
+ const otel = this.#otel;
102
+ const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
103
+ const context = options.context;
104
+ if (context) return otel.tracer.startActiveSpan(name, options, context, (span) => this.#callActiveSpan(span, callback));
105
+ return otel.tracer.startActiveSpan(name, options, (span) => this.#callActiveSpan(span, callback));
106
+ }
107
+ startSpan(name, options, context) {
108
+ if (!this.#otel) return this.#noopSpan;
109
+ const { tracer } = this.#otel;
110
+ return tracer.startSpan(name, options, context);
111
+ }
112
+ async finish() {
113
+ await this.#sdk?.shutdown();
114
+ }
115
+ }
116
+ function noopSpan() {
117
+ return this;
118
+ }
119
+ function createNoopSpan() {
120
+ return {
121
+ setAttribute: noopSpan,
122
+ setStatus: noopSpan,
123
+ addEvent: noopSpan,
124
+ addLink: noopSpan,
125
+ addLinks: noopSpan,
126
+ setAttributes: noopSpan,
127
+ updateName: noopSpan,
128
+ end: () => {},
129
+ isRecording: () => false,
130
+ recordException: noopSpan,
131
+ spanContext() {
132
+ return {
133
+ spanId: "",
134
+ traceFlags: 0,
135
+ traceId: ""
136
+ };
137
+ }
138
+ };
139
+ }
140
+ function noopContext() {
141
+ return this;
142
+ }
143
+ function createNoopContext() {
144
+ return {
145
+ getValue: noopContext,
146
+ setValue: noopContext,
147
+ deleteValue: noopContext
148
+ };
149
+ }
150
+
151
+ export { Traces as T };
@@ -2,6 +2,7 @@ import { PrettyFormatOptions } from '@vitest/pretty-format';
2
2
  import { SequenceHooks, SequenceSetupFiles } from '@vitest/runner';
3
3
  import { SnapshotUpdateState, SnapshotEnvironment } from '@vitest/snapshot';
4
4
  import { SerializedDiffOptions } from '@vitest/utils/diff';
5
+ import { Context, Span, SpanOptions } from '@opentelemetry/api';
5
6
 
6
7
  /**
7
8
  * Names of clock methods that may be faked by install.
@@ -180,6 +181,9 @@ interface SerializedConfig {
180
181
  includeSamples: boolean;
181
182
  } | undefined;
182
183
  serializedDefines: string;
184
+ experimental: {
185
+ fsModuleCache: boolean;
186
+ };
183
187
  }
184
188
  interface SerializedCoverageConfig {
185
189
  provider: "istanbul" | "v8" | "custom" | undefined;
@@ -198,4 +202,35 @@ type RuntimeConfig = Pick<SerializedConfig, "allowOnly" | "testTimeout" | "hookT
198
202
  type RuntimeOptions = Partial<RuntimeConfig>;
199
203
  type BrowserTraceViewMode = "on" | "off" | "on-first-retry" | "on-all-retries" | "retain-on-failure";
200
204
 
201
- export type { BrowserTraceViewMode as B, FakeTimerInstallOpts as F, RuntimeOptions as R, SerializedConfig as S, SerializedCoverageConfig as a, RuntimeConfig as b };
205
+ interface OTELCarrier {
206
+ traceparent?: string;
207
+ tracestate?: string;
208
+ }
209
+ interface TracesOptions {
210
+ enabled: boolean;
211
+ watchMode?: boolean;
212
+ sdkPath?: string;
213
+ tracerName?: string;
214
+ }
215
+ interface TracesSpanOptions extends SpanOptions {
216
+ context?: Context;
217
+ }
218
+ declare class Traces {
219
+ #private;
220
+ constructor(options: TracesOptions);
221
+ isEnabled(): boolean;
222
+ waitInit(): Promise<this>;
223
+ startContextSpan(name: string, currentContext?: Context): {
224
+ span: Span;
225
+ context: Context;
226
+ };
227
+ getContextFromCarrier(carrier: OTELCarrier | undefined): Context;
228
+ getContextCarrier(context?: Context): OTELCarrier | undefined;
229
+ $<T>(name: string, fn: (span: Span) => T): T;
230
+ $<T>(name: string, optionsOrFn: TracesSpanOptions, fn: (span: Span) => T): T;
231
+ startSpan(name: string, options?: SpanOptions, context?: Context): Span;
232
+ finish(): Promise<void>;
233
+ }
234
+
235
+ export { Traces as T };
236
+ export type { BrowserTraceViewMode as B, FakeTimerInstallOpts as F, OTELCarrier as O, RuntimeOptions as R, SerializedConfig as S, SerializedCoverageConfig as a, RuntimeConfig as b };
@@ -9,7 +9,7 @@ import { assertTypes, createSimpleStackTrace } from '@vitest/utils/helpers';
9
9
  import { fn, spyOn, restoreAllMocks, resetAllMocks, clearAllMocks, isMockFunction } from '@vitest/spy';
10
10
  import '@vitest/utils/offset';
11
11
  import { parseSingleStack } from '@vitest/utils/source-map';
12
- import { c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
12
+ import { c as commonjsGlobal } from './_commonjsHelpers.D26ty3Ew.js';
13
13
  import { R as RealDate, r as resetDate, m as mockDate } from './date.Bq6ZW5rf.js';
14
14
 
15
15
  // these matchers are not supported because they don't make sense with poll
@@ -3902,7 +3902,7 @@ function _mocker() {
3902
3902
  function getImporter(name) {
3903
3903
  const stackArray = createSimpleStackTrace({ stackTraceLimit: 5 }).split("\n");
3904
3904
  return parseSingleStack(stackArray[stackArray.findLastIndex((stack) => {
3905
- return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
3905
+ return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`) || stack.includes(` at ${name} (`);
3906
3906
  }) + 1])?.file || "";
3907
3907
  }
3908
3908
 
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath, pathToFileURL } from 'node:url';
2
2
  import vm, { isContext, runInContext } from 'node:vm';
3
3
  import { dirname, basename, extname, normalize, resolve } from 'pathe';
4
- import { l as loadEnvironment } from './init.BQhNfT0h.js';
4
+ import { l as loadEnvironment } from './init.B3IeC_yW.js';
5
5
  import { distDir } from '../path.js';
6
6
  import { createCustomConsole } from './console.Cf-YriPC.js';
7
7
  import fs from 'node:fs';
@@ -11,7 +11,7 @@ import { findNearestPackageData } from '@vitest/utils/resolver';
11
11
  import { dirname as dirname$1 } from 'node:path';
12
12
  import { CSS_LANGS_RE, KNOWN_ASSET_RE } from '@vitest/utils/constants';
13
13
  import { getDefaultRequestStubs } from '../module-evaluator.js';
14
- import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.DLjmA_wU.js';
14
+ import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.DaBMy1JT.js';
15
15
  import { p as provideWorkerState } from './utils.DvEY5TfP.js';
16
16
 
17
17
  function interopCommonJsModule(interopDefault, mod) {
@@ -671,17 +671,20 @@ class FileMap {
671
671
  const entryFile = pathToFileURL(resolve(distDir, "workers/runVmTests.js")).href;
672
672
  const fileMap = new FileMap();
673
673
  const packageCache = /* @__PURE__ */ new Map();
674
- async function runVmTests(method, state) {
674
+ async function runVmTests(method, state, traces) {
675
675
  const { ctx, rpc } = state;
676
676
  const beforeEnvironmentTime = performance.now();
677
- const { environment } = await loadEnvironment(ctx.environment.name, ctx.config.root, rpc);
677
+ const { environment } = await loadEnvironment(ctx.environment.name, ctx.config.root, rpc, traces);
678
678
  state.environment = environment;
679
679
  if (!environment.setupVM) {
680
680
  const envName = ctx.environment.name;
681
681
  const packageId = envName[0] === "." ? envName : `vitest-environment-${envName}`;
682
682
  throw new TypeError(`Environment "${ctx.environment.name}" is not a valid environment. Path "${packageId}" doesn't support vm environment because it doesn't provide "setupVM" method.`);
683
683
  }
684
- const vm = await environment.setupVM(ctx.environment.options || ctx.config.environmentOptions || {});
684
+ const vm = await traces.$("vitest.runtime.environment.setup", { attributes: {
685
+ "vitest.environment": environment.name,
686
+ "vitest.environment.vite_environment": environment.viteEnvironment || environment.name
687
+ } }, () => environment.setupVM(ctx.environment.options || ctx.config.environmentOptions || {}));
685
688
  state.durations.environment = performance.now() - beforeEnvironmentTime;
686
689
  process.env.VITEST_VM_POOL = "1";
687
690
  if (!vm.getVmContext) throw new TypeError(`Environment ${environment.name} doesn't provide "getVmContext" method. It should return a context created by "vm.createContext" method.`);
@@ -710,7 +713,8 @@ async function runVmTests(method, state) {
710
713
  evaluatedModules: state.evaluatedModules,
711
714
  state,
712
715
  externalModulesExecutor,
713
- createImportMeta: createNodeImportMeta
716
+ createImportMeta: createNodeImportMeta,
717
+ traces
714
718
  });
715
719
  Object.defineProperty(context, VITEST_VM_CONTEXT_SYMBOL, {
716
720
  value: {
@@ -734,9 +738,9 @@ async function runVmTests(method, state) {
734
738
  testLocations: void 0
735
739
  } : f);
736
740
  try {
737
- await run(method, fileSpecs, ctx.config, moduleRunner);
741
+ await run(method, fileSpecs, ctx.config, moduleRunner, traces);
738
742
  } finally {
739
- await vm.teardown?.();
743
+ await traces.$("vitest.runtime.environment.teardown", () => vm.teardown?.());
740
744
  }
741
745
  }
742
746
 
@@ -1,6 +1,6 @@
1
- import { CancelReason, File, TestAnnotation, TaskResultPack, TaskEventPack, FileSpecification, Task } from '@vitest/runner';
1
+ import { CancelReason, File, TestArtifact, TaskResultPack, TaskEventPack, FileSpecification, Task } from '@vitest/runner';
2
2
  import { FetchFunctionOptions, FetchResult, EvaluatedModules } from 'vite/module-runner';
3
- import { S as SerializedConfig } from './config.d.BTfZNUu9.js';
3
+ import { O as OTELCarrier, S as SerializedConfig, T as Traces } from './traces.d.B8ukBJqA.js';
4
4
  import { E as Environment } from './environment.d.CrsxCzP1.js';
5
5
  import { SnapshotResult } from '@vitest/snapshot';
6
6
 
@@ -208,7 +208,7 @@ interface Request {
208
208
  declare const setTimeout: typeof globalThis.setTimeout;
209
209
 
210
210
  interface RuntimeRPC {
211
- fetch: (id: string, importer: string | undefined, environment: string, options?: FetchFunctionOptions) => Promise<FetchResult | FetchCachedFileSystemResult>;
211
+ fetch: (id: string, importer: string | undefined, environment: string, options?: FetchFunctionOptions, otelCarrier?: OTELCarrier) => Promise<FetchResult | FetchCachedFileSystemResult>;
212
212
  resolve: (id: string, importer: string | undefined, environment: string) => Promise<ResolveFunctionResult | null>;
213
213
  transform: (id: string) => Promise<{
214
214
  code?: string;
@@ -218,7 +218,7 @@ interface RuntimeRPC {
218
218
  onQueued: (file: File) => void;
219
219
  onCollected: (files: File[]) => Promise<void>;
220
220
  onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
221
- onTaskAnnotate: (testId: string, annotation: TestAnnotation) => Promise<TestAnnotation>;
221
+ onTaskArtifactRecord: <Artifact extends TestArtifact>(testId: string, artifact: Artifact) => Promise<Artifact>;
222
222
  onTaskUpdate: (pack: TaskResultPack[], events: TaskEventPack[]) => Promise<void>;
223
223
  onCancel: (reason: CancelReason) => void;
224
224
  getCountOfFailedTests: () => number;
@@ -264,6 +264,7 @@ interface WorkerSetupContext {
264
264
  config: SerializedConfig;
265
265
  projectName: string;
266
266
  rpc: WorkerRPC;
267
+ traces: Traces;
267
268
  }
268
269
  interface WorkerGlobalState {
269
270
  ctx: ContextRPC;
package/dist/cli.js CHANGED
@@ -1,10 +1,10 @@
1
- import { c as createCLI } from './chunks/cac.B_NTJoIH.js';
1
+ import { c as createCLI } from './chunks/cac.aVhqBj0-.js';
2
2
  import '@vitest/utils/helpers';
3
3
  import 'events';
4
4
  import 'pathe';
5
5
  import 'tinyrainbow';
6
6
  import './chunks/constants.D_Q9UYh-.js';
7
- import './chunks/index.kotH7DY7.js';
7
+ import './chunks/index.DWDW6mLz.js';
8
8
  import 'node:fs';
9
9
  import 'node:fs/promises';
10
10
  import 'node:perf_hooks';
package/dist/config.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { HookHandler, ConfigEnv, UserConfig } from 'vite';
2
2
  export { ConfigEnv, Plugin, UserConfig as ViteUserConfig, mergeConfig } from 'vite';
3
- import { I as InlineConfig, c as CoverageV8Options, R as ResolvedCoverageOptions, U as UserWorkspaceConfig, d as UserProjectConfigFn, e as UserProjectConfigExport } from './chunks/reporters.d.BQ0wpUaj.js';
4
- export { a as TestProjectConfiguration, g as TestProjectInlineConfiguration, f as TestUserConfig, W as WatcherTriggerPattern } from './chunks/reporters.d.BQ0wpUaj.js';
5
- import { V as VitestPluginContext } from './chunks/plugin.d.DevON6kQ.js';
6
- import { F as FakeTimerInstallOpts } from './chunks/config.d.BTfZNUu9.js';
3
+ import { I as InlineConfig, c as CoverageV8Options, R as ResolvedCoverageOptions, U as UserWorkspaceConfig, d as UserProjectConfigFn, e as UserProjectConfigExport } from './chunks/reporters.d.DgZLBdyd.js';
4
+ export { b as TestProjectConfiguration, g as TestProjectInlineConfiguration, f as TestUserConfig, W as WatcherTriggerPattern } from './chunks/reporters.d.DgZLBdyd.js';
5
+ import { V as VitestPluginContext } from './chunks/plugin.d.N8khPRFb.js';
6
+ import { F as FakeTimerInstallOpts } from './chunks/traces.d.B8ukBJqA.js';
7
7
  import '@vitest/runner';
8
8
  import '@vitest/utils';
9
- import './chunks/worker.d.ZGohxCEd.js';
9
+ import './chunks/worker.d.B_PZTrCQ.js';
10
10
  import 'vite/module-runner';
11
11
  import './chunks/environment.d.CrsxCzP1.js';
12
12
  import '@vitest/snapshot';
@@ -14,7 +14,7 @@ import 'node:stream';
14
14
  import '@vitest/mocker';
15
15
  import '@vitest/utils/source-map';
16
16
  import 'vitest/browser';
17
- import './chunks/browser.d.DnU_kh8a.js';
17
+ import './chunks/browser.d.D-d8eZY4.js';
18
18
  import '@vitest/pretty-format';
19
19
  import '@vitest/utils/diff';
20
20
  import '@vitest/expect';
@@ -24,8 +24,9 @@ import '@vitest/runner/utils';
24
24
  import 'tinybench';
25
25
  import './chunks/coverage.d.BZtK59WP.js';
26
26
  import '@vitest/snapshot/manager';
27
- import 'node:fs';
28
27
  import 'node:console';
28
+ import 'node:fs';
29
+ import '@opentelemetry/api';
29
30
 
30
31
  type VitestInlineConfig = InlineConfig;
31
32
  declare module "vite" {
@@ -1,17 +1,18 @@
1
- import { R as ResolvedCoverageOptions, V as Vitest, C as CoverageMap, b as ReportContext } from './chunks/reporters.d.BQ0wpUaj.js';
1
+ import { R as ResolvedCoverageOptions, V as Vitest, C as CoverageMap, a as ReportContext } from './chunks/reporters.d.DgZLBdyd.js';
2
2
  import { TransformResult } from 'vite';
3
- import { A as AfterSuiteRunMeta } from './chunks/worker.d.ZGohxCEd.js';
3
+ import { A as AfterSuiteRunMeta } from './chunks/worker.d.B_PZTrCQ.js';
4
4
  import '@vitest/runner';
5
5
  import '@vitest/utils';
6
6
  import 'node:stream';
7
7
  import '@vitest/mocker';
8
8
  import '@vitest/utils/source-map';
9
9
  import 'vitest/browser';
10
- import './chunks/config.d.BTfZNUu9.js';
10
+ import './chunks/traces.d.B8ukBJqA.js';
11
11
  import '@vitest/pretty-format';
12
12
  import '@vitest/snapshot';
13
13
  import '@vitest/utils/diff';
14
- import './chunks/browser.d.DnU_kh8a.js';
14
+ import '@opentelemetry/api';
15
+ import './chunks/browser.d.D-d8eZY4.js';
15
16
  import '@vitest/expect';
16
17
  import 'vitest/optional-types.js';
17
18
  import './chunks/benchmark.d.DAaHLpsq.js';
@@ -19,8 +20,8 @@ import '@vitest/runner/utils';
19
20
  import 'tinybench';
20
21
  import './chunks/coverage.d.BZtK59WP.js';
21
22
  import '@vitest/snapshot/manager';
22
- import 'node:fs';
23
23
  import 'node:console';
24
+ import 'node:fs';
24
25
  import 'vite/module-runner';
25
26
  import './chunks/environment.d.CrsxCzP1.js';
26
27
 
package/dist/coverage.js CHANGED
@@ -1,4 +1,4 @@
1
- export { B as BaseCoverageProvider } from './chunks/coverage.BUlIqJrL.js';
1
+ export { B as BaseCoverageProvider } from './chunks/coverage.CtyeYmKM.js';
2
2
  import 'node:fs';
3
3
  import 'node:path';
4
4
  import '@vitest/utils/helpers';
@@ -11,10 +11,10 @@ import 'node:os';
11
11
  import './chunks/env.D4Lgay0q.js';
12
12
  import 'std-env';
13
13
  import 'node:crypto';
14
+ import 'node:url';
14
15
  import 'node:module';
15
16
  import 'node:process';
16
17
  import 'node:fs/promises';
17
- import 'node:url';
18
18
  import 'node:assert';
19
19
  import 'node:v8';
20
20
  import 'node:util';
@@ -1,3 +1,3 @@
1
- export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.BfmpdV5p.js';
1
+ export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.QWbK7rHY.js';
2
2
  import 'node:url';
3
3
  import 'node:console';
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { S as SerializedTestSpecification } from './chunks/browser.d.DnU_kh8a.js';
2
- export { B as BrowserTesterOptions } from './chunks/browser.d.DnU_kh8a.js';
3
- import './chunks/global.d.BQDgW9Pr.js';
4
- import { File, TestAnnotation, TaskResultPack, TaskEventPack, TaskPopulated } from '@vitest/runner';
5
- export { CancelReason, ImportDuration, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskEventPack as RunnerTaskEventPack, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestAnnotation, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
1
+ import { S as SerializedTestSpecification } from './chunks/browser.d.D-d8eZY4.js';
2
+ export { B as BrowserTesterOptions } from './chunks/browser.d.D-d8eZY4.js';
3
+ import './chunks/global.d.uY4Q0M5z.js';
4
+ import { File, TestAnnotation, TestArtifact, TaskResultPack, TaskEventPack, Test, TaskPopulated } from '@vitest/runner';
5
+ export { CancelReason, ImportDuration, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskEventPack as RunnerTaskEventPack, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestAnnotation, TestAnnotationArtifact, TestArtifact, TestArtifactBase, TestArtifactLocation, TestArtifactRegistry, TestAttachment, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, recordArtifact, suite, test } from '@vitest/runner';
6
6
  import { Awaitable } from '@vitest/utils';
7
7
  export { ParsedStack, SerializedError, TestError } from '@vitest/utils';
8
- import { U as UserConsoleLog, L as LabelColor, M as ModuleGraphData, b as BirpcReturn, P as ProvidedContext } from './chunks/worker.d.ZGohxCEd.js';
9
- export { A as AfterSuiteRunMeta, C as ContextRPC, d as ContextTestEnvironment, c as RunnerRPC, R as RuntimeRPC, T as TestExecutionMethod, W as WorkerGlobalState } from './chunks/worker.d.ZGohxCEd.js';
10
- import { S as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.d.BTfZNUu9.js';
11
- export { b as RuntimeConfig, a as SerializedCoverageConfig } from './chunks/config.d.BTfZNUu9.js';
8
+ import { U as UserConsoleLog, L as LabelColor, M as ModuleGraphData, b as BirpcReturn, P as ProvidedContext } from './chunks/worker.d.B_PZTrCQ.js';
9
+ export { A as AfterSuiteRunMeta, C as ContextRPC, d as ContextTestEnvironment, c as RunnerRPC, R as RuntimeRPC, T as TestExecutionMethod, W as WorkerGlobalState } from './chunks/worker.d.B_PZTrCQ.js';
10
+ import { S as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/traces.d.B8ukBJqA.js';
11
+ export { b as RuntimeConfig, a as SerializedCoverageConfig } from './chunks/traces.d.B8ukBJqA.js';
12
12
  import { ExpectStatic } from '@vitest/expect';
13
13
  export { Assertion, AsymmetricMatchersContaining, DeeplyAllowMatchers, ExpectPollOptions, ExpectStatic, JestAssertion, Matchers, chai } from '@vitest/expect';
14
14
  import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy';
@@ -23,6 +23,7 @@ export { DiffOptions } from '@vitest/utils/diff';
23
23
  export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
24
24
  import '@vitest/pretty-format';
25
25
  import './chunks/environment.d.CrsxCzP1.js';
26
+ import '@opentelemetry/api';
26
27
  import '@vitest/mocker';
27
28
  import '@vitest/runner/utils';
28
29
 
@@ -67,17 +68,18 @@ interface WebSocketHandlers {
67
68
  }
68
69
  interface WebSocketEvents {
69
70
  onCollected?: (files?: File[]) => Awaitable<void>;
70
- onFinished?: (files: File[], errors: unknown[], coverage?: unknown) => Awaitable<void>;
71
+ onFinished?: (files: File[], errors: unknown[], coverage?: unknown, executionTime?: number) => Awaitable<void>;
71
72
  onTestAnnotate?: (testId: string, annotation: TestAnnotation) => Awaitable<void>;
73
+ onTestArtifactRecord?: (testId: string, artifact: TestArtifact) => Awaitable<void>;
72
74
  onTaskUpdate?: (packs: TaskResultPack[], events: TaskEventPack[]) => Awaitable<void>;
73
75
  onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
74
76
  onPathsCollected?: (paths?: string[]) => Awaitable<void>;
75
- onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable<void>;
77
+ onSpecsCollected?: (specs?: SerializedTestSpecification[], startTime?: number) => Awaitable<void>;
76
78
  onFinishedReportCoverage: () => void;
77
79
  }
78
80
  type WebSocketRPC = BirpcReturn<WebSocketEvents, WebSocketHandlers>;
79
81
 
80
- declare function createExpect(test?: TaskPopulated): ExpectStatic;
82
+ declare function createExpect(test?: Test | TaskPopulated): ExpectStatic;
81
83
  declare const globalExpect: ExpectStatic;
82
84
  declare const assert: Chai.Assert;
83
85
  declare const should: () => Chai.Should;
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- export { b as assert, c as createExpect, g as expect, i as inject, s as should, v as vi, d as vitest } from './chunks/vi.CyIUVSoU.js';
1
+ export { b as assert, c as createExpect, g as expect, i as inject, s as should, v as vi, d as vitest } from './chunks/vi.BiaV1qII.js';
2
2
  export { b as bench } from './chunks/benchmark.B3N2zMcH.js';
3
3
  export { V as EvaluatedModules } from './chunks/evaluatedModules.Dg1zASAC.js';
4
- export { a as assertType } from './chunks/index.CGezRSGU.js';
4
+ export { a as assertType } from './chunks/index.DBx1AtPJ.js';
5
5
  export { expectTypeOf } from 'expect-type';
6
- export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
6
+ export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, recordArtifact, suite, test } from '@vitest/runner';
7
7
  export { chai } from '@vitest/expect';
8
8
  import '@vitest/runner/utils';
9
9
  import './chunks/utils.DvEY5TfP.js';
@@ -14,7 +14,7 @@ import '@vitest/utils/helpers';
14
14
  import '@vitest/spy';
15
15
  import '@vitest/utils/offset';
16
16
  import '@vitest/utils/source-map';
17
- import './chunks/_commonjsHelpers.BFTU3MAI.js';
17
+ import './chunks/_commonjsHelpers.D26ty3Ew.js';
18
18
  import './chunks/date.Bq6ZW5rf.js';
19
19
  import 'pathe';
20
20
  import 'vite/module-runner';
@@ -1,14 +1,15 @@
1
1
  import 'vite/module-runner';
2
- export { b as VitestModuleEvaluator, a as VitestModuleEvaluatorOptions, c as createImportMetaEnvProxy, g as getDefaultRequestStubs, i as isPrimitive, u as unwrapId, w as wrapId } from './chunks/moduleRunner.d.BxT-OjLR.js';
2
+ export { b as VitestModuleEvaluator, a as VitestModuleEvaluatorOptions, c as createImportMetaEnvProxy, g as getDefaultRequestStubs, i as isPrimitive, u as unwrapId, w as wrapId } from './chunks/moduleRunner.d.B5SW5pMI.js';
3
3
  import 'node:vm';
4
+ import './chunks/traces.d.B8ukBJqA.js';
4
5
  import '@vitest/spy';
5
- import './chunks/worker.d.ZGohxCEd.js';
6
+ import './chunks/worker.d.B_PZTrCQ.js';
6
7
  import '@vitest/runner';
7
- import './chunks/config.d.BTfZNUu9.js';
8
- import '@vitest/pretty-format';
9
- import '@vitest/snapshot';
10
- import '@vitest/utils/diff';
11
8
  import './chunks/environment.d.CrsxCzP1.js';
12
9
  import '@vitest/utils';
10
+ import '@vitest/snapshot';
13
11
  import '@vitest/mocker';
14
12
  import './chunks/mocker.d.BE_2ls6u.js';
13
+ import '@vitest/pretty-format';
14
+ import '@vitest/utils/diff';
15
+ import '@opentelemetry/api';
@@ -3,6 +3,7 @@ import { pathToFileURL } from 'node:url';
3
3
  import vm from 'node:vm';
4
4
  import { isAbsolute } from 'pathe';
5
5
  import { ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey } from 'vite/module-runner';
6
+ import { T as Traces } from './chunks/traces.BVPrsYso.js';
6
7
 
7
8
  const performanceNow = performance.now.bind(performance);
8
9
  class ModuleDebug {
@@ -38,8 +39,10 @@ class VitestModuleEvaluator {
38
39
  compiledFunctionArgumentsValues = [];
39
40
  primitives;
40
41
  debug = new ModuleDebug();
42
+ _otel;
41
43
  constructor(vmOptions, options = {}) {
42
44
  this.options = options;
45
+ this._otel = options.traces || new Traces({ enabled: false });
43
46
  this.vm = vmOptions;
44
47
  this.stubs = getDefaultRequestStubs(vmOptions?.context);
45
48
  if (options.compiledFunctionArgumentsNames) this.compiledFunctionArgumentsNames = options.compiledFunctionArgumentsNames;
@@ -53,6 +56,7 @@ class VitestModuleEvaluator {
53
56
  }
54
57
  convertIdToImportUrl(id) {
55
58
  // TODO: vitest returns paths for external modules, but Vite returns file://
59
+ // REMOVE WHEN VITE 6 SUPPORT IS OVER
56
60
  // unfortunetly, there is a bug in Vite where ID is resolved incorrectly, so we can't return files until the fix is merged
57
61
  // https://github.com/vitejs/vite/pull/20449
58
62
  if (!isWindows || isBuiltin(id) || /^(?:node:|data:|http:|https:|file:)/.test(id)) return id;
@@ -63,7 +67,7 @@ class VitestModuleEvaluator {
63
67
  async runExternalModule(id) {
64
68
  if (id in this.stubs) return this.stubs[id];
65
69
  const file = this.convertIdToImportUrl(id);
66
- const namespace = this.vm ? await this.vm.externalModulesExecutor.import(file) : await import(file);
70
+ const namespace = await this._otel.$("vitest.module.external", { attributes: { "code.file.path": file } }, () => this.vm ? this.vm.externalModulesExecutor.import(file) : import(file));
67
71
  if (!this.shouldInterop(file, namespace)) return namespace;
68
72
  const { mod, defaultExport } = interopModule(namespace);
69
73
  const { Proxy, Reflect } = this.primitives;
@@ -88,6 +92,9 @@ class VitestModuleEvaluator {
88
92
  });
89
93
  }
90
94
  async runInlinedModule(context, code, module) {
95
+ return this._otel.$("vitest.module.inline", (span) => this._runInlinedModule(context, code, module, span));
96
+ }
97
+ async _runInlinedModule(context, code, module, span) {
91
98
  context.__vite_ssr_import_meta__.env = this.env;
92
99
  const { Reflect, Proxy, Object } = this.primitives;
93
100
  const exportsObject = context[ssrModuleExportsKey];
@@ -102,9 +109,11 @@ class VitestModuleEvaluator {
102
109
  },
103
110
  getPrototypeOf: () => Object.prototype,
104
111
  set: (_, p, value) => {
112
+ span.addEvent(`cjs export proxy is triggered for ${String(p)}`);
105
113
  // treat "module.exports =" the same as "exports.default =" to not have nested "default.default",
106
114
  // so "exports.default" becomes the actual module
107
115
  if (p === "default" && this.shouldInterop(module.file, { default: value }) && cjsExports !== value) {
116
+ span.addEvent("`exports.default` is assigned, copying values");
108
117
  exportAll(cjsExports, value);
109
118
  exportsObject.default = value;
110
119
  return true;
@@ -113,6 +122,7 @@ class VitestModuleEvaluator {
113
122
  // returns undefined, when accessing named exports, if default is not an object
114
123
  // but is still present inside hasOwnKeys, this is Node behaviour for CJS
115
124
  if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) {
125
+ span.addEvent(`\`exports.${String(p)}\` is assigned, but module.exports is a primitive. assigning "undefined" values instead to comply with ESM`);
116
126
  defineExport(exportsObject, p, () => void 0);
117
127
  return true;
118
128
  }
@@ -123,6 +133,7 @@ class VitestModuleEvaluator {
123
133
  });
124
134
  const moduleProxy = {
125
135
  set exports(value) {
136
+ span.addEvent("`module.exports` is assigned directly, copying all properties to `exports`");
126
137
  exportAll(cjsExports, value);
127
138
  exportsObject.default = value;
128
139
  moduleExports = value;
@@ -138,6 +149,7 @@ class VitestModuleEvaluator {
138
149
  }
139
150
  const filename = meta.filename;
140
151
  const dirname = meta.dirname;
152
+ span.setAttributes({ "code.file.path": filename });
141
153
  const require = this.createRequire(filename);
142
154
  const argumentsList = [
143
155
  ssrModuleExportsKey,
@@ -153,6 +165,7 @@ class VitestModuleEvaluator {
153
165
  "require"
154
166
  ];
155
167
  if (this.compiledFunctionArgumentsNames) argumentsList.push(...this.compiledFunctionArgumentsNames);
168
+ span.setAttribute("vitest.module.arguments", argumentsList);
156
169
  // add 'use strict' since ESM enables it by default
157
170
  const codeDefinition = `'use strict';async (${argumentsList.join(",")})=>{{`;
158
171
  const wrappedCode = `${codeDefinition}${code}\n}}`;
@@ -1,11 +1,12 @@
1
1
  export { VitestModuleEvaluator } from './module-evaluator.js';
2
- export { a as VITEST_VM_CONTEXT_SYMBOL, V as VitestModuleRunner, s as startVitestModuleRunner } from './chunks/startModuleRunner.DLjmA_wU.js';
2
+ export { a as VITEST_VM_CONTEXT_SYMBOL, V as VitestModuleRunner, s as startVitestModuleRunner } from './chunks/startModuleRunner.DaBMy1JT.js';
3
3
  export { g as getWorkerState } from './chunks/utils.DvEY5TfP.js';
4
4
  import 'node:module';
5
5
  import 'node:url';
6
6
  import 'node:vm';
7
7
  import 'pathe';
8
8
  import 'vite/module-runner';
9
+ import './chunks/traces.BVPrsYso.js';
9
10
  import 'node:fs';
10
11
  import '@vitest/utils/helpers';
11
12
  import './path.js';