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

Function compareObjects

packages/utils/src/diff/index.ts:176–209  ·  view source on GitHub ↗
(
  a: Record<string, any>,
  b: Record<string, any>,
  options?: DiffOptions,
  memorize: Memorize = DEFAULT_MEMORIZE,
)

Source from the content-addressed store, hash-verified

174}
175
176function compareObjects(
177 a: Record<string, any>,
178 b: Record<string, any>,
179 options?: DiffOptions,
180 memorize: Memorize = DEFAULT_MEMORIZE,
181) {
182 let difference
183 let hasThrown = false
184
185 try {
186 const formatOptions = getFormatOptions(FORMAT_OPTIONS, options)
187 difference = getObjectsDifference(a, b, formatOptions, options, memorize)
188 }
189 catch {
190 hasThrown = true
191 }
192
193 const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options)
194 // If the comparison yields no results, compare again but this time
195 // without calling `toJSON`. It's also possible that toJSON might throw.
196 if (difference === undefined || difference === noDiffMessage) {
197 const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options)
198 difference = getObjectsDifference(a, b, formatOptions, options, memorize)
199
200 if (difference !== noDiffMessage && !hasThrown) {
201 difference = `${getCommonMessage(
202 SIMILAR_MESSAGE,
203 options,
204 )}\n\n${difference}`
205 }
206 }
207
208 return difference
209}
210
211export function getDefaultFormatOptions(options?: DiffOptions): PrettyFormatOptions {
212 return getFormatOptions(FORMAT_OPTIONS, options)

Callers 1

diffFunction · 0.85

Calls 3

getFormatOptionsFunction · 0.85
getObjectsDifferenceFunction · 0.85
getCommonMessageFunction · 0.85

Tested by

no test coverage detected