MCPcopy Create free account
hub / github.com/vitest-dev/vitest / getObjectsDifference

Function getObjectsDifference

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

Source from the content-addressed store, hash-verified

227}
228
229function getObjectsDifference(
230 a: Record<string, any>,
231 b: Record<string, any>,
232 formatOptions: PrettyFormatOptions,
233 options?: DiffOptions,
234 memorize: Memorize = DEFAULT_MEMORIZE,
235): string {
236 const formatOptionsZeroIndent = { ...formatOptions, indent: 0 }
237 const aCompare = prettyFormat(a, formatOptionsZeroIndent)
238 const bCompare = prettyFormat(b, formatOptionsZeroIndent)
239
240 if (aCompare === bCompare) {
241 return getCommonMessage(NO_DIFF_MESSAGE, options)
242 }
243 else {
244 const aDisplay = memorize('expected', prettyFormat(a, formatOptions))
245 const bDisplay = memorize('actual', prettyFormat(b, formatOptions))
246
247 return diffLinesUnified2(
248 aDisplay.split('\n'),
249 bDisplay.split('\n'),
250 aCompare.split('\n'),
251 bCompare.split('\n'),
252 options,
253 )
254 }
255}
256
257const MAX_DIFF_STRING_LENGTH = 20_000
258

Callers 1

compareObjectsFunction · 0.85

Calls 2

diffLinesUnified2Function · 0.90
getCommonMessageFunction · 0.85

Tested by

no test coverage detected