@@ -28,7 +28,14 @@ function readFile(filePath) {
2828}
2929
3030function contentToDiffLine ( key , value ) {
31- return `"${ key } ": "${ value } ",` ;
31+ if ( typeof value === "object" && ! Array . isArray ( value ) && value !== null ) {
32+ const out = Object . entries ( value )
33+ . filter ( ( [ subKey , _ ] ) => [ "path" , "name" ] . includes ( subKey ) )
34+ . map ( ( [ subKey , subValue ] ) => `"${ subKey } ": ${ JSON . stringify ( subValue ) } ` )
35+ . join ( ", " ) ;
36+ return `"${ key } ": ${ out } ,` ;
37+ }
38+ return `"${ key } ": ${ JSON . stringify ( value ) } ,` ;
3239}
3340
3441function shouldIgnoreField ( fieldName ) {
@@ -37,47 +44,61 @@ function shouldIgnoreField(fieldName) {
3744 fieldName === "proposeCorrectionTo" ;
3845}
3946
47+ function valueMapper ( key , testOutput ) {
48+ const isAlias = testOutput [ "is_alias" ] ;
49+ let value = testOutput [ key ] ;
50+ // To make our life easier, if there is a "parent" type, we add it to the path.
51+ if ( key === "path" ) {
52+ if ( testOutput [ "parent" ] !== undefined ) {
53+ if ( value . length > 0 ) {
54+ value += "::" + testOutput [ "parent" ] [ "name" ] ;
55+ } else {
56+ value = testOutput [ "parent" ] [ "name" ] ;
57+ }
58+ } else if ( testOutput [ "is_alias" ] ) {
59+ value = valueMapper ( key , testOutput [ "original" ] ) ;
60+ }
61+ } else if ( isAlias && key === "alias" ) {
62+ value = testOutput [ "name" ] ;
63+ } else if ( isAlias && [ "name" ] . includes ( key ) ) {
64+ value = testOutput [ "original" ] [ key ] ;
65+ }
66+ return value ;
67+ }
68+
4069// This function is only called when no matching result was found and therefore will only display
4170// the diff between the two items.
42- function betterLookingDiff ( entry , data ) {
71+ function betterLookingDiff ( expected , testOutput ) {
4372 let output = " {\n" ;
44- const spaces = " " ;
45- for ( const key in entry ) {
46- if ( ! Object . prototype . hasOwnProperty . call ( entry , key ) ) {
73+ const spaces = " " ;
74+ for ( const key in expected ) {
75+ if ( ! Object . prototype . hasOwnProperty . call ( expected , key ) ) {
4776 continue ;
4877 }
49- if ( ! data || ! Object . prototype . hasOwnProperty . call ( data , key ) ) {
50- output += "-" + spaces + contentToDiffLine ( key , entry [ key ] ) + "\n" ;
78+ if ( ! testOutput || ! Object . prototype . hasOwnProperty . call ( testOutput , key ) ) {
79+ output += "-" + spaces + contentToDiffLine ( key , expected [ key ] ) + "\n" ;
5180 continue ;
5281 }
53- const value = data [ key ] ;
54- if ( value !== entry [ key ] ) {
55- output += "-" + spaces + contentToDiffLine ( key , entry [ key ] ) + "\n" ;
82+ const value = valueMapper ( key , testOutput ) ;
83+ if ( value !== expected [ key ] ) {
84+ output += "-" + spaces + contentToDiffLine ( key , expected [ key ] ) + "\n" ;
5685 output += "+" + spaces + contentToDiffLine ( key , value ) + "\n" ;
5786 } else {
58- output += spaces + contentToDiffLine ( key , value ) + "\n" ;
87+ output += spaces + " " + contentToDiffLine ( key , value ) + "\n" ;
5988 }
6089 }
6190 return output + " }" ;
6291}
6392
64- function lookForEntry ( entry , data ) {
65- return data . findIndex ( data_entry => {
93+ function lookForEntry ( expected , testOutput ) {
94+ return testOutput . findIndex ( testOutputEntry => {
6695 let allGood = true ;
67- for ( const key in entry ) {
68- if ( ! Object . prototype . hasOwnProperty . call ( entry , key ) ) {
96+ for ( const key in expected ) {
97+ if ( ! Object . prototype . hasOwnProperty . call ( expected , key ) ) {
6998 continue ;
7099 }
71- let value = data_entry [ key ] ;
72- // To make our life easier, if there is a "parent" type, we add it to the path.
73- if ( key === "path" && data_entry [ "parent" ] !== undefined ) {
74- if ( value . length > 0 ) {
75- value += "::" + data_entry [ "parent" ] [ "name" ] ;
76- } else {
77- value = data_entry [ "parent" ] [ "name" ] ;
78- }
79- }
80- if ( value !== entry [ key ] ) {
100+ const value = valueMapper ( key , testOutputEntry ) ;
101+ if ( value !== expected [ key ] ) {
81102 allGood = false ;
82103 break ;
83104 }
0 commit comments