MCPcopy
hub / github.com/vitest-dev/vitest / printer

Function printer

packages/pretty-format/src/index.ts:375–424  ·  view source on GitHub ↗
(
  val: unknown,
  config: Config,
  indentation: string,
  depth: number,
  refs: Refs,
  hasCalledToJSON?: boolean,
)

Source from the content-addressed store, hash-verified

373}
374
375function printer(
376 val: unknown,
377 config: Config,
378 indentation: string,
379 depth: number,
380 refs: Refs,
381 hasCalledToJSON?: boolean,
382): string {
383 let result: string
384
385 const plugin = findPlugin(config.plugins, val)
386 if (plugin !== null) {
387 result = printPlugin(plugin, val, config, indentation, depth, refs)
388 }
389 else {
390 const basicResult = printBasicValue(
391 val,
392 config.printFunctionName,
393 config.escapeRegex,
394 config.escapeString,
395 )
396 if (basicResult !== null) {
397 result = basicResult
398 }
399 else {
400 result = printComplexValue(
401 val,
402 config,
403 indentation,
404 depth,
405 refs,
406 hasCalledToJSON,
407 )
408 }
409 }
410
411 // Per-depth output budget (inspired by Node's util.inspect).
412 // Each depth level tracks output independently, so nested results
413 // don't inflate a single counter (which would undercount by ~Nx for
414 // N levels of nesting). Nodes at the same depth produce disjoint spans
415 // in the output string, so each bucket accurately reflects output at
416 // that level. Total output is bounded by maxDepth × maxOutputLength.
417 config._outputLengthPerDepth[depth] ??= 0
418 config._outputLengthPerDepth[depth] += result.length
419 if (config._outputLengthPerDepth[depth] > config.maxOutputLength) {
420 config.maxDepth = 0
421 }
422
423 return result
424}
425
426const DEFAULT_THEME: Theme = {
427 comment: 'gray',

Callers 14

printIteratorEntriesFunction · 0.85
printIteratorValuesFunction · 0.85
printListItemsFunction · 0.85
printObjectPropertiesFunction · 0.85
printComplexValueFunction · 0.85
printPluginFunction · 0.85
serializeFunction · 0.85
printPropsFunction · 0.85
printChildrenFunction · 0.85
serializeFunction · 0.85
serializeFunction · 0.85
serializeFunction · 0.85

Calls 4

findPluginFunction · 0.85
printPluginFunction · 0.85
printBasicValueFunction · 0.85
printComplexValueFunction · 0.85

Tested by 1

serializeFunction · 0.68