@@ -190,6 +190,30 @@ function loadThings(thingsToLoad, kindOfLoad, funcToCall, fileContent) {
190
190
return content ;
191
191
}
192
192
193
+ function contentToDiffLine ( key , value ) {
194
+ return `"${ key } ": "${ value } ",` ;
195
+ }
196
+
197
+ // This function is only called when no matching result was found and therefore will only display
198
+ // the diff between the two items.
199
+ function betterLookingDiff ( entry , data ) {
200
+ let output = ' {\n' ;
201
+ let spaces = ' ' ;
202
+ for ( let key in entry ) {
203
+ if ( ! entry . hasOwnProperty ( key ) ) {
204
+ continue ;
205
+ }
206
+ let value = data [ key ] ;
207
+ if ( value !== entry [ key ] ) {
208
+ output += '-' + spaces + contentToDiffLine ( key , entry [ key ] ) + '\n' ;
209
+ output += '+' + spaces + contentToDiffLine ( key , value ) + '\n' ;
210
+ } else {
211
+ output += spaces + contentToDiffLine ( key , value ) + '\n' ;
212
+ }
213
+ }
214
+ return output + ' }' ;
215
+ }
216
+
193
217
function lookForEntry ( entry , data ) {
194
218
for ( var i = 0 ; i < data . length ; ++ i ) {
195
219
var allGood = true ;
@@ -281,6 +305,13 @@ function runSearch(query, expected, index, loaded, loadedFile, queryName) {
281
305
if ( entry_pos === null ) {
282
306
error_text . push ( queryName + "==> Result not found in '" + key + "': '" +
283
307
JSON . stringify ( entry [ i ] ) + "'" ) ;
308
+ // By default, we just compare the two first items.
309
+ let item_to_diff = 0 ;
310
+ if ( ( ignore_order === false || exact_check === true ) && i < results [ key ] . length ) {
311
+ item_to_diff = i ;
312
+ }
313
+ error_text . push ( "Diff of first error:\n" +
314
+ betterLookingDiff ( entry [ i ] , results [ key ] [ item_to_diff ] ) ) ;
284
315
} else if ( exact_check === true && prev_pos + 1 !== entry_pos ) {
285
316
error_text . push ( queryName + "==> Exact check failed at position " + ( prev_pos + 1 ) +
286
317
": expected '" + JSON . stringify ( entry [ i ] ) + "' but found '" +
0 commit comments