( a: Record<string, any>, b: Record<string, any>, options?: DiffOptions, memorize: Memorize = DEFAULT_MEMORIZE, )
| 174 | } |
| 175 | |
| 176 | function 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 | |
| 211 | export function getDefaultFormatOptions(options?: DiffOptions): PrettyFormatOptions { |
| 212 | return getFormatOptions(FORMAT_OPTIONS, options) |
no test coverage detected