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

Function stringify

packages/utils/src/display.ts:49–97  ·  view source on GitHub ↗
(
  object: unknown,
  maxDepth = 10,
  { maxLength, filterNode, ...options }: StringifyOptions = {},
)

Source from the content-addressed store, hash-verified

47}
48
49export function stringify(
50 object: unknown,
51 maxDepth = 10,
52 { maxLength, filterNode, ...options }: StringifyOptions = {},
53): string {
54 const MAX_LENGTH = maxLength ?? 10000
55 let result
56
57 // Convert string selector to filter function
58 const filterFn = typeof filterNode === 'string'
59 ? createNodeFilterFromSelector(filterNode)
60 : filterNode
61
62 const plugins = filterFn
63 ? [
64 ReactTestComponent,
65 ReactElement,
66 createDOMElementFilter(filterFn),
67 DOMCollection,
68 Immutable,
69 AsymmetricMatcher,
70 ]
71 : PLUGINS
72
73 try {
74 result = prettyFormat(object, {
75 maxDepth,
76 escapeString: false,
77 // min: true,
78 plugins,
79 ...options,
80 })
81 }
82 catch {
83 result = prettyFormat(object, {
84 callToJSON: false,
85 maxDepth,
86 escapeString: false,
87 // min: true,
88 plugins,
89 ...options,
90 })
91 }
92
93 // Prevents infinite loop https://github.com/vitest-dev/vitest/issues/7249
94 return result.length >= MAX_LENGTH && maxDepth > 1
95 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), { maxLength, filterNode, ...options })
96 : result
97}
98
99function createNodeFilterFromSelector(selector: string): (node: any) => boolean {
100 const ELEMENT_NODE = 1

Callers 15

printReceivedFunction · 0.90
printExpectedFunction · 0.90
printReceivedFunction · 0.90
printExpectedFunction · 0.90
createClientFunction · 0.85
prettyDOMFunction · 0.85
printAttributeFunction · 0.85
getAttributeCommentFunction · 0.85
resolveOrchestratorFunction · 0.85
setupClientFunction · 0.85
formatArgFunction · 0.85
createClientFunction · 0.85

Calls 2

createDOMElementFilterFunction · 0.90

Tested by

no test coverage detected