MCPcopy
hub / github.com/jestjs/jest / stringify

Function stringify

packages/jest-matcher-utils/src/index.ts:94–126  ·  view source on GitHub ↗
(
  object: unknown,
  maxDepth = 10,
  maxWidth = 10,
)

Source from the content-addressed store, hash-verified

92);
93
94export const stringify = (
95 object: unknown,
96 maxDepth = 10,
97 maxWidth = 10,
98): string => {
99 const MAX_LENGTH = 10_000;
100 let result;
101
102 try {
103 result = prettyFormat(object, {
104 maxDepth,
105 maxWidth,
106 min: true,
107 plugins: PLUGINS,
108 });
109 } catch {
110 result = prettyFormat(object, {
111 callToJSON: false,
112 maxDepth,
113 maxWidth,
114 min: true,
115 plugins: PLUGINS,
116 });
117 }
118
119 if (result.length >= MAX_LENGTH && maxDepth > 1) {
120 return stringify(object, Math.floor(maxDepth / 2), maxWidth);
121 } else if (result.length >= MAX_LENGTH && maxWidth > 1) {
122 return stringify(object, maxDepth, Math.floor(maxWidth / 2));
123 } else {
124 return result;
125 }
126};
127
128export const highlightTrailingWhitespace = (text: string): string =>
129 text.replaceAll(/\s+$/gm, chalk.inverse('$&'));

Callers 15

printCloseToFunction · 0.90
toEqualFunction · 0.90
toHavePropertyFunction · 0.90
toMatchObjectFunction · 0.90
toStrictEqualFunction · 0.90
printCommonFunction · 0.90
printDiffCallFunction · 0.90

Calls

no outgoing calls

Tested by 2

testNotToMatchSnapshotsFunction · 0.68
testToMatchSnapshotsFunction · 0.68