vitest 4.0.11 → 4.0.13

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 (38) hide show
  1. package/dist/browser.d.ts +7 -11
  2. package/dist/chunks/{base.DiCUKpyF.js → base.Dqf2QAxh.js} +2 -2
  3. package/dist/chunks/{browser.d.D-d8eZY4.d.ts → browser.d.CDvMh6F9.d.ts} +1 -1
  4. package/dist/chunks/{cac.aVhqBj0-.js → cac.L-UbQ_Ix.js} +3 -3
  5. package/dist/chunks/{cli-api.-bIZD4XU.js → cli-api.CdZ6wo9-.js} +63 -57
  6. package/dist/chunks/{traces.d.B8ukBJqA.d.ts → config.d.g6OOauRt.d.ts} +1 -33
  7. package/dist/chunks/{global.d.uY4Q0M5z.d.ts → global.d.B15mdLcR.d.ts} +1 -1
  8. package/dist/chunks/{init-forks.DIuGPyId.js → init-forks.CglOH45c.js} +1 -1
  9. package/dist/chunks/{init-threads.jC_8JdoN.js → init-threads.BuMdIy1r.js} +1 -1
  10. package/dist/chunks/{init.B3IeC_yW.js → init.MkYs5nmh.js} +2 -2
  11. package/dist/chunks/{plugin.d.N8khPRFb.d.ts → plugin.d.B4l3vYM_.d.ts} +1 -1
  12. package/dist/chunks/{reporters.d.DgZLBdyd.d.ts → reporters.d.J2RlBlp9.d.ts} +5 -3
  13. package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
  14. package/dist/chunks/{startModuleRunner.DaBMy1JT.js → startModuleRunner.W28wBIgJ.js} +4 -1
  15. package/dist/chunks/{traces.BVPrsYso.js → traces.U4xDYhzZ.js} +21 -0
  16. package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
  17. package/dist/chunks/{vm.BKyGp1KW.js → vm.Y19jrZy2.js} +2 -2
  18. package/dist/chunks/{worker.d.B_PZTrCQ.d.ts → worker.d.DCy61tzi.d.ts} +5 -64
  19. package/dist/cli.js +1 -1
  20. package/dist/config.d.ts +10 -9
  21. package/dist/coverage.d.ts +8 -7
  22. package/dist/index.d.ts +16 -10
  23. package/dist/module-evaluator.d.ts +117 -13
  24. package/dist/module-evaluator.js +1 -1
  25. package/dist/module-runner.js +2 -2
  26. package/dist/node.d.ts +10 -9
  27. package/dist/node.js +4 -4
  28. package/dist/reporters.d.ts +10 -9
  29. package/dist/runners.d.ts +2 -2
  30. package/dist/worker.d.ts +6 -5
  31. package/dist/worker.js +4 -4
  32. package/dist/workers/forks.js +5 -5
  33. package/dist/workers/threads.js +5 -5
  34. package/dist/workers/vmForks.js +5 -5
  35. package/dist/workers/vmThreads.js +5 -5
  36. package/package.json +12 -12
  37. package/dist/chunks/mocker.d.BE_2ls6u.d.ts +0 -17
  38. package/dist/chunks/moduleRunner.d.B5SW5pMI.d.ts +0 -208
package/dist/browser.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/traces.d.B8ukBJqA.js';
1
+ import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.g6OOauRt.js';
2
2
  import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
3
3
  import { SerializedDiffOptions } from '@vitest/utils/diff';
4
- import { V as VitestModuleRunner } from './chunks/moduleRunner.d.B5SW5pMI.js';
5
4
  export { collectTests, startTests } from '@vitest/runner';
6
5
  import * as _vitest_spy from '@vitest/spy';
7
6
  export { _vitest_spy as SpyModule };
@@ -13,13 +12,6 @@ export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
13
12
  export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers';
14
13
  import '@vitest/pretty-format';
15
14
  import '@vitest/snapshot';
16
- import '@opentelemetry/api';
17
- import 'node:vm';
18
- import 'vite/module-runner';
19
- import './chunks/worker.d.B_PZTrCQ.js';
20
- import './chunks/environment.d.CrsxCzP1.js';
21
- import '@vitest/mocker';
22
- import './chunks/mocker.d.BE_2ls6u.js';
23
15
 
24
16
  declare function startCoverageInsideWorker(options: SerializedCoverageConfig | undefined, loader: RuntimeCoverageModuleLoader, runtimeOptions: {
25
17
  isolate: boolean;
@@ -29,9 +21,13 @@ declare function stopCoverageInsideWorker(options: SerializedCoverageConfig | un
29
21
  isolate: boolean;
30
22
  }): Promise<unknown>;
31
23
 
24
+ interface PublicModuleRunner {
25
+ import: (id: string) => Promise<any>;
26
+ }
27
+
32
28
  declare function setupCommonEnv(config: SerializedConfig): Promise<void>;
33
- declare function loadDiffConfig(config: SerializedConfig, moduleRunner: VitestModuleRunner): Promise<SerializedDiffOptions | undefined>;
34
- declare function loadSnapshotSerializers(config: SerializedConfig, moduleRunner: VitestModuleRunner): Promise<void>;
29
+ declare function loadDiffConfig(config: SerializedConfig, moduleRunner: PublicModuleRunner): Promise<SerializedDiffOptions | undefined>;
30
+ declare function loadSnapshotSerializers(config: SerializedConfig, moduleRunner: PublicModuleRunner): Promise<void>;
35
31
 
36
32
  interface FsOptions {
37
33
  encoding?: BufferEncoding;
@@ -1,9 +1,9 @@
1
1
  import { runInThisContext } from 'node:vm';
2
2
  import * as spyModule from '@vitest/spy';
3
3
  import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.CQwQ_SLL.js';
4
- import { l as loadEnvironment } from './init.B3IeC_yW.js';
4
+ import { l as loadEnvironment } from './init.MkYs5nmh.js';
5
5
  import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
6
- import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.DaBMy1JT.js';
6
+ import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.W28wBIgJ.js';
7
7
  import { performance as performance$1 } from 'node:perf_hooks';
8
8
  import { startTests, collectTests } from '@vitest/runner';
9
9
  import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.DGHc_BUK.js';
@@ -1,5 +1,5 @@
1
1
  import { FileSpecification } from '@vitest/runner';
2
- import { T as TestExecutionMethod } from './worker.d.B_PZTrCQ.js';
2
+ import { T as TestExecutionMethod } from './worker.d.DCy61tzi.js';
3
3
 
4
4
  type SerializedTestSpecification = [project: {
5
5
  name: string | undefined;
@@ -619,7 +619,7 @@ class CAC extends EventEmitter {
619
619
 
620
620
  const cac = (name = "") => new CAC(name);
621
621
 
622
- var version = "4.0.11";
622
+ var version = "4.0.13";
623
623
 
624
624
  const apiConfig = (port) => ({
625
625
  port: {
@@ -1371,7 +1371,7 @@ function normalizeCliOptions(cliFilters, argv) {
1371
1371
  }
1372
1372
  async function start(mode, cliFilters, options) {
1373
1373
  try {
1374
- const { startVitest } = await import('./cli-api.-bIZD4XU.js').then(function (n) { return n.p; });
1374
+ const { startVitest } = await import('./cli-api.CdZ6wo9-.js').then(function (n) { return n.p; });
1375
1375
  const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1376
1376
  if (!ctx.shouldKeepServer()) await ctx.exit();
1377
1377
  } catch (e) {
@@ -1393,7 +1393,7 @@ async function init(project) {
1393
1393
  }
1394
1394
  async function collect(mode, cliFilters, options) {
1395
1395
  try {
1396
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.-bIZD4XU.js').then(function (n) { return n.p; });
1396
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.CdZ6wo9-.js').then(function (n) { return n.p; });
1397
1397
  const ctx = await prepareVitest(mode, {
1398
1398
  ...normalizeCliOptions(cliFilters, options),
1399
1399
  watch: false,
@@ -12,7 +12,7 @@ import * as nodeos from 'node:os';
12
12
  import nodeos__default, { tmpdir } from 'node:os';
13
13
  import { generateHash as generateHash$1, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, hasFailed, generateFileHash, limitConcurrency, createFileTask as createFileTask$1, getTasks, isTestCase } from '@vitest/runner/utils';
14
14
  import { SnapshotManager } from '@vitest/snapshot/manager';
15
- import { v as version$1 } from './cac.aVhqBj0-.js';
15
+ import { v as version$1 } from './cac.L-UbQ_Ix.js';
16
16
  import { performance as performance$1 } from 'node:perf_hooks';
17
17
  import { c as createBirpc } from './index.0kCJoeWi.js';
18
18
  import { p as parse, d as stringify, e as TraceMap, o as originalPositionFor, h as ancestor, i as printError, f as formatProjectName, w as withLabel, j as errorBanner, k as divider, l as Typechecker, m as generateCodeFrame, n as createDefinesScript, R as ReportersMap, B as BlobReporter, r as readBlobs, q as convertTasksToEvents, H as HangingProcessReporter } from './index.DWDW6mLz.js';
@@ -29,7 +29,7 @@ import require$$0$1 from 'buffer';
29
29
  import { g as getDefaultExportFromCjs } from './_commonjsHelpers.D26ty3Ew.js';
30
30
  import crypto, { createHash } from 'node:crypto';
31
31
  import { rootDir, distDir } from '../path.js';
32
- import { T as Traces } from './traces.BVPrsYso.js';
32
+ import { T as Traces } from './traces.U4xDYhzZ.js';
33
33
  import createDebug from 'debug';
34
34
  import { rm, readFile, writeFile, rename, stat, unlink, mkdir, copyFile } from 'node:fs/promises';
35
35
  import c from 'tinyrainbow';
@@ -5747,6 +5747,7 @@ const debugMemory = createDebugger("vitest:cache:memory");
5747
5747
  const cacheComment = "\n//# vitestCache=";
5748
5748
  const cacheCommentLength = 17;
5749
5749
  const METADATA_FILE = "_metadata.json";
5750
+ const parallelFsCacheRead = /* @__PURE__ */ new Map();
5750
5751
  /**
5751
5752
  * @experimental
5752
5753
  */
@@ -5786,25 +5787,30 @@ class FileSystemModuleCache {
5786
5787
  })));
5787
5788
  if (log) this.vitest.logger.log(`[cache] cleared fs module cache at ${uniquePaths.join(", ")}`);
5788
5789
  }
5790
+ readCachedFileConcurrently(cachedFilePath) {
5791
+ if (!parallelFsCacheRead.has(cachedFilePath)) parallelFsCacheRead.set(cachedFilePath, readFile(cachedFilePath, "utf-8").then((code) => {
5792
+ const matchIndex = code.lastIndexOf(cacheComment);
5793
+ if (matchIndex === -1) {
5794
+ debugFs?.(`${c.red("[empty]")} ${cachedFilePath} exists, but doesn't have a ${cacheComment} comment, transforming by vite instead`);
5795
+ return;
5796
+ }
5797
+ return {
5798
+ code,
5799
+ meta: this.fromBase64(code.slice(matchIndex + cacheCommentLength))
5800
+ };
5801
+ }).finally(() => {
5802
+ parallelFsCacheRead.delete(cachedFilePath);
5803
+ }));
5804
+ return parallelFsCacheRead.get(cachedFilePath);
5805
+ }
5789
5806
  async getCachedModule(cachedFilePath) {
5790
5807
  if (!existsSync(cachedFilePath)) {
5791
5808
  debugFs?.(`${c.red("[empty]")} ${cachedFilePath} doesn't exist, transforming by vite instead`);
5792
5809
  return;
5793
5810
  }
5794
- const code = await readFile(cachedFilePath, "utf-8");
5795
- const matchIndex = code.lastIndexOf(cacheComment);
5796
- if (matchIndex === -1) {
5797
- debugFs?.(`${c.red("[empty]")} ${cachedFilePath} exists, but doesn't have a ${cacheComment} comment, transforming by vite instead`);
5798
- return;
5799
- }
5800
- const meta = this.fromBase64(code.slice(matchIndex + cacheCommentLength));
5801
- if (meta.externalize) {
5802
- debugFs?.(`${c.green("[read]")} ${meta.externalize} is externalized inside ${cachedFilePath}`);
5803
- return {
5804
- externalize: meta.externalize,
5805
- type: meta.type
5806
- };
5807
- }
5811
+ const fileResult = await this.readCachedFileConcurrently(cachedFilePath);
5812
+ if (!fileResult) return;
5813
+ const { code, meta } = fileResult;
5808
5814
  debugFs?.(`${c.green("[read]")} ${meta.id} is cached in ${cachedFilePath}`);
5809
5815
  return {
5810
5816
  id: meta.id,
@@ -5816,10 +5822,7 @@ class FileSystemModuleCache {
5816
5822
  };
5817
5823
  }
5818
5824
  async saveCachedModule(cachedFilePath, fetchResult, importers = [], mappings = false) {
5819
- if ("externalize" in fetchResult) {
5820
- debugFs?.(`${c.yellow("[write]")} ${fetchResult.externalize} is externalized inside ${cachedFilePath}`);
5821
- await atomicWriteFile(cachedFilePath, `${cacheComment}${this.toBase64(fetchResult)}`);
5822
- } else if ("code" in fetchResult) {
5825
+ if ("code" in fetchResult) {
5823
5826
  const result = {
5824
5827
  file: fetchResult.file,
5825
5828
  id: fetchResult.id,
@@ -5853,7 +5856,6 @@ class FileSystemModuleCache {
5853
5856
  return result;
5854
5857
  }
5855
5858
  generateCachePath(vitestConfig, environment, resolver, id, fileContent) {
5856
- let hashString = "";
5857
5859
  // bail out if file has import.meta.glob because it depends on other files
5858
5860
  // TODO: figure out a way to still support it
5859
5861
  if (fileContent.includes("import.meta.glob(")) {
@@ -5861,6 +5863,7 @@ class FileSystemModuleCache {
5861
5863
  debugMemory?.(`${c.yellow("[write]")} ${id} was bailed out`);
5862
5864
  return null;
5863
5865
  }
5866
+ let hashString = "";
5864
5867
  for (const generator of this.fsCacheKeyGenerators) {
5865
5868
  const result = generator({
5866
5869
  environment,
@@ -5889,13 +5892,7 @@ class FileSystemModuleCache {
5889
5892
  plugins: config.plugins.map((p) => p.name),
5890
5893
  configFileDependencies: config.configFileDependencies.map((file) => tryReadFileSync(file)),
5891
5894
  environment: environment.name,
5892
- css: vitestConfig.css,
5893
- resolver: {
5894
- inline: resolver.options.inline,
5895
- external: resolver.options.external,
5896
- inlineFiles: resolver.options.inlineFiles,
5897
- moduleDirectories: resolver.options.moduleDirectories
5898
- }
5895
+ css: vitestConfig.css
5899
5896
  }, (_, value) => {
5900
5897
  if (typeof value === "function" || value instanceof RegExp) return value.toString();
5901
5898
  return value;
@@ -6156,7 +6153,7 @@ class ModuleFetcher {
6156
6153
  }
6157
6154
  recordResult(trace, result) {
6158
6155
  if ("externalize" in result) trace.setAttributes({
6159
- "vitest.module.external": result.externalize,
6156
+ "vitest.fetched_module.external": result.externalize,
6160
6157
  "vitest.fetched_module.type": result.type
6161
6158
  });
6162
6159
  if ("id" in result) {
@@ -6191,35 +6188,40 @@ class ModuleFetcher {
6191
6188
  return "";
6192
6189
  }
6193
6190
  async getCachedModule(cachePath, environment, moduleGraphModule) {
6191
+ if (moduleGraphModule.transformResult?.__vitestTmp) return {
6192
+ cached: true,
6193
+ file: moduleGraphModule.file,
6194
+ id: moduleGraphModule.id,
6195
+ tmp: moduleGraphModule.transformResult.__vitestTmp,
6196
+ url: moduleGraphModule.url,
6197
+ invalidate: false
6198
+ };
6194
6199
  const cachedModule = await this.fsCache.getCachedModule(cachePath);
6195
- if (cachedModule && "code" in cachedModule) {
6196
- // keep the module graph in sync
6197
- if (!moduleGraphModule.transformResult) {
6198
- let map = extractSourceMap(cachedModule.code);
6199
- if (map && cachedModule.file) map.file = cachedModule.file;
6200
- // mappings is a special source map identifier in rollup
6201
- if (!map && cachedModule.mappings) map = { mappings: "" };
6202
- moduleGraphModule.transformResult = {
6203
- code: cachedModule.code,
6204
- map,
6205
- ssr: true
6206
- };
6207
- // we populate the module graph to make the watch mode work because it relies on importers
6208
- cachedModule.importers.forEach((importer) => {
6209
- const environmentNode = environment.moduleGraph.getModuleById(importer);
6210
- if (environmentNode) moduleGraphModule.importers.add(environmentNode);
6211
- });
6212
- }
6213
- return {
6214
- cached: true,
6215
- file: cachedModule.file,
6216
- id: cachedModule.id,
6217
- tmp: cachePath,
6218
- url: cachedModule.url,
6219
- invalidate: false
6220
- };
6221
- }
6222
- return cachedModule;
6200
+ if (!cachedModule) return;
6201
+ // keep the module graph in sync
6202
+ let map = extractSourceMap(cachedModule.code);
6203
+ if (map && cachedModule.file) map.file = cachedModule.file;
6204
+ // mappings is a special source map identifier in rollup
6205
+ if (!map && cachedModule.mappings) map = { mappings: "" };
6206
+ moduleGraphModule.transformResult = {
6207
+ code: cachedModule.code,
6208
+ map,
6209
+ ssr: true,
6210
+ __vitestTmp: cachePath
6211
+ };
6212
+ // we populate the module graph to make the watch mode work because it relies on importers
6213
+ cachedModule.importers.forEach((importer) => {
6214
+ const environmentNode = environment.moduleGraph.getModuleById(importer);
6215
+ if (environmentNode) moduleGraphModule.importers.add(environmentNode);
6216
+ });
6217
+ return {
6218
+ cached: true,
6219
+ file: cachedModule.file,
6220
+ id: cachedModule.id,
6221
+ tmp: cachePath,
6222
+ url: cachedModule.url,
6223
+ invalidate: false
6224
+ };
6223
6225
  }
6224
6226
  async fetchAndProcess(environment, url, importer, moduleGraphModule, options) {
6225
6227
  const externalize = await this.resolver.shouldExternalize(moduleGraphModule.id);
@@ -9249,6 +9251,10 @@ function WorkspaceVitestPlugin(project, options) {
9249
9251
  vitestConfig.experimental ??= {};
9250
9252
  vitestConfig.experimental.fsModuleCache = project.vitest.config.experimental.fsModuleCache;
9251
9253
  }
9254
+ if (testConfig.experimental?.fsModuleCachePath == null && project.vitest.config.experimental?.fsModuleCachePath !== null) {
9255
+ vitestConfig.experimental ??= {};
9256
+ vitestConfig.experimental.fsModuleCachePath = project.vitest.config.experimental.fsModuleCachePath;
9257
+ }
9252
9258
  return {
9253
9259
  base: "/",
9254
9260
  environments: { __vitest__: { dev: {} } },
@@ -2,7 +2,6 @@ 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';
6
5
 
7
6
  /**
8
7
  * Names of clock methods that may be faked by install.
@@ -202,35 +201,4 @@ type RuntimeConfig = Pick<SerializedConfig, "allowOnly" | "testTimeout" | "hookT
202
201
  type RuntimeOptions = Partial<RuntimeConfig>;
203
202
  type BrowserTraceViewMode = "on" | "off" | "on-first-retry" | "on-all-retries" | "retain-on-failure";
204
203
 
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 };
204
+ export type { BrowserTraceViewMode as B, FakeTimerInstallOpts as F, RuntimeOptions as R, SerializedConfig as S, SerializedCoverageConfig as a, RuntimeConfig as b };
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
2
2
  import { Plugin } from '@vitest/pretty-format';
3
3
  import { SnapshotState } from '@vitest/snapshot';
4
4
  import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
5
- import { U as UserConsoleLog } from './worker.d.B_PZTrCQ.js';
5
+ import { U as UserConsoleLog } from './rpc.d.RH3apGEf.js';
6
6
 
7
7
  interface SnapshotMatcher<T> {
8
8
  <U extends { [P in keyof T] : any }>(snapshot: Partial<U>, hint?: string): void;
@@ -1,4 +1,4 @@
1
- import { i as init } from './init.B3IeC_yW.js';
1
+ import { i as init } from './init.MkYs5nmh.js';
2
2
 
3
3
  if (!process.send) throw new Error("Expected worker to be run in node:child_process");
4
4
  // Store globals in case tests overwrite them
@@ -1,5 +1,5 @@
1
1
  import { isMainThread, parentPort } from 'node:worker_threads';
2
- import { i as init } from './init.B3IeC_yW.js';
2
+ import { i as init } from './init.MkYs5nmh.js';
3
3
 
4
4
  if (isMainThread || !parentPort) throw new Error("Expected worker to be run in node:worker_threads");
5
5
  function workerInit(options) {
@@ -3,10 +3,10 @@ import { isBuiltin } from 'node:module';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { resolve } from 'pathe';
5
5
  import { ModuleRunner } from 'vite/module-runner';
6
- import { b as VitestTransport } from './startModuleRunner.DaBMy1JT.js';
6
+ import { b as VitestTransport } from './startModuleRunner.W28wBIgJ.js';
7
7
  import { e as environments } from './index.QWbK7rHY.js';
8
8
  import { serializeError } from '@vitest/utils/error';
9
- import { T as Traces } from './traces.BVPrsYso.js';
9
+ import { T as Traces } from './traces.U4xDYhzZ.js';
10
10
  import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.BytlcPfC.js';
11
11
  import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
12
12
  import { s as setupInspect } from './inspector.CvyFGlXm.js';
@@ -1,5 +1,5 @@
1
1
  import { DevEnvironment } from 'vite';
2
- import { V as Vitest, T as TestProject, b as TestProjectConfiguration } from './reporters.d.DgZLBdyd.js';
2
+ import { V as Vitest, T as TestProject, b as TestProjectConfiguration } from './reporters.d.J2RlBlp9.js';
3
3
 
4
4
  /**
5
5
  * Generate a unique cache identifier.
@@ -1,18 +1,20 @@
1
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.B_PZTrCQ.js';
3
+ import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, L as LabelColor } from './rpc.d.RH3apGEf.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, 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';
9
+ import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.g6OOauRt.js';
10
+ import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.CDvMh6F9.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';
14
14
  import { chai } from '@vitest/expect';
15
15
  import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
16
+ import { c as ContextTestEnvironment, d as WorkerTestEnvironment, e as WorkerExecuteContext } from './worker.d.DCy61tzi.js';
17
+ import { O as OTELCarrier } from './traces.d.402V_yFI.js';
16
18
  import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
17
19
  import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
18
20
  import { SnapshotManager } from '@vitest/snapshot/manager';
@@ -0,0 +1,64 @@
1
+ import { CancelReason, File, TestArtifact, TaskResultPack, TaskEventPack } from '@vitest/runner';
2
+ import { SnapshotResult } from '@vitest/snapshot';
3
+ import { FetchFunctionOptions, FetchResult } from 'vite/module-runner';
4
+ import { O as OTELCarrier } from './traces.d.402V_yFI.js';
5
+
6
+ interface AfterSuiteRunMeta {
7
+ coverage?: unknown;
8
+ testFiles: string[];
9
+ environment: string;
10
+ projectName?: string;
11
+ }
12
+ interface UserConsoleLog {
13
+ content: string;
14
+ origin?: string;
15
+ browser?: boolean;
16
+ type: "stdout" | "stderr";
17
+ taskId?: string;
18
+ time: number;
19
+ size: number;
20
+ }
21
+ interface ModuleGraphData {
22
+ graph: Record<string, string[]>;
23
+ externalized: string[];
24
+ inlined: string[];
25
+ }
26
+ interface ProvidedContext {}
27
+ interface ResolveFunctionResult {
28
+ id: string;
29
+ file: string;
30
+ url: string;
31
+ }
32
+ interface FetchCachedFileSystemResult {
33
+ cached: true;
34
+ tmp: string;
35
+ id: string;
36
+ file: string | null;
37
+ url: string;
38
+ invalidate: boolean;
39
+ }
40
+ type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
41
+
42
+ interface RuntimeRPC {
43
+ fetch: (id: string, importer: string | undefined, environment: string, options?: FetchFunctionOptions, otelCarrier?: OTELCarrier) => Promise<FetchResult | FetchCachedFileSystemResult>;
44
+ resolve: (id: string, importer: string | undefined, environment: string) => Promise<ResolveFunctionResult | null>;
45
+ transform: (id: string) => Promise<{
46
+ code?: string;
47
+ }>;
48
+ onUserConsoleLog: (log: UserConsoleLog) => void;
49
+ onUnhandledError: (err: unknown, type: string) => void;
50
+ onQueued: (file: File) => void;
51
+ onCollected: (files: File[]) => Promise<void>;
52
+ onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
53
+ onTaskArtifactRecord: <Artifact extends TestArtifact>(testId: string, artifact: Artifact) => Promise<Artifact>;
54
+ onTaskUpdate: (pack: TaskResultPack[], events: TaskEventPack[]) => Promise<void>;
55
+ onCancel: (reason: CancelReason) => void;
56
+ getCountOfFailedTests: () => number;
57
+ snapshotSaved: (snapshot: SnapshotResult) => void;
58
+ resolveSnapshotPath: (testPath: string) => string;
59
+ }
60
+ interface RunnerRPC {
61
+ onCancel: (reason: CancelReason) => void;
62
+ }
63
+
64
+ export type { AfterSuiteRunMeta as A, LabelColor as L, ModuleGraphData as M, ProvidedContext as P, RuntimeRPC as R, UserConsoleLog as U, RunnerRPC as a };
@@ -10,7 +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
+ import { T as Traces } from './traces.U4xDYhzZ.js';
14
14
 
15
15
  class VitestTransport {
16
16
  constructor(options) {
@@ -821,6 +821,9 @@ function startVitestModuleRunner(options) {
821
821
  externalize: toBuiltin(rawId),
822
822
  type: "builtin"
823
823
  };
824
+ // if module is invalidated, the worker will be recreated,
825
+ // so cached is always true in a single worker
826
+ if (options?.cached) return { cache: true };
824
827
  const otelCarrier = traces?.getContextCarrier();
825
828
  const result = await rpc().fetch(id, importer, environment(), options, otelCarrier);
826
829
  if ("cached" in result) return {
@@ -37,10 +37,16 @@ class Traces {
37
37
  isEnabled() {
38
38
  return !!this.#otel;
39
39
  }
40
+ /**
41
+ * @internal
42
+ */
40
43
  async waitInit() {
41
44
  if (this.#init) await this.#init;
42
45
  return this;
43
46
  }
47
+ /**
48
+ * @internal
49
+ */
44
50
  startContextSpan(name, currentContext) {
45
51
  if (!this.#otel) return {
46
52
  span: this.#noopSpan,
@@ -53,12 +59,18 @@ class Traces {
53
59
  context: this.#otel.trace.setSpan(activeContext, span)
54
60
  };
55
61
  }
62
+ /**
63
+ * @internal
64
+ */
56
65
  getContextFromCarrier(carrier) {
57
66
  if (!this.#otel) return this.#noopContext;
58
67
  const activeContext = this.#otel.context.active();
59
68
  if (!carrier) return activeContext;
60
69
  return this.#otel.propagation.extract(activeContext, carrier);
61
70
  }
71
+ /**
72
+ * @internal
73
+ */
62
74
  getContextCarrier(context) {
63
75
  if (!this.#otel) return;
64
76
  const carrier = {};
@@ -95,6 +107,9 @@ class Traces {
95
107
  if (!(result instanceof Promise)) span.end();
96
108
  }
97
109
  }
110
+ /**
111
+ * @internal
112
+ */
98
113
  $(name, optionsOrFn, fn) {
99
114
  const callback = typeof optionsOrFn === "function" ? optionsOrFn : fn;
100
115
  if (!this.#otel) return callback(this.#noopSpan);
@@ -104,11 +119,17 @@ class Traces {
104
119
  if (context) return otel.tracer.startActiveSpan(name, options, context, (span) => this.#callActiveSpan(span, callback));
105
120
  return otel.tracer.startActiveSpan(name, options, (span) => this.#callActiveSpan(span, callback));
106
121
  }
122
+ /**
123
+ * @internal
124
+ */
107
125
  startSpan(name, options, context) {
108
126
  if (!this.#otel) return this.#noopSpan;
109
127
  const { tracer } = this.#otel;
110
128
  return tracer.startSpan(name, options, context);
111
129
  }
130
+ /**
131
+ * @internal
132
+ */
112
133
  async finish() {
113
134
  await this.#sdk?.shutdown();
114
135
  }
@@ -0,0 +1,18 @@
1
+ interface OTELCarrier {
2
+ traceparent?: string;
3
+ tracestate?: string;
4
+ }
5
+ interface TracesOptions {
6
+ enabled: boolean;
7
+ watchMode?: boolean;
8
+ sdkPath?: string;
9
+ tracerName?: string;
10
+ }
11
+ declare class Traces {
12
+ #private;
13
+ constructor(options: TracesOptions);
14
+ isEnabled(): boolean;
15
+ }
16
+
17
+ export { Traces as T };
18
+ export type { OTELCarrier as O };
@@ -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.B3IeC_yW.js';
4
+ import { l as loadEnvironment } from './init.MkYs5nmh.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.DaBMy1JT.js';
14
+ import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.W28wBIgJ.js';
15
15
  import { p as provideWorkerState } from './utils.DvEY5TfP.js';
16
16
 
17
17
  function interopCommonJsModule(interopDefault, mod) {