@@ -28,7 +28,14 @@ function readFile(filePath) {
28
28
}
29
29
30
30
function 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 ) } ,` ;
32
39
}
33
40
34
41
function shouldIgnoreField ( fieldName ) {
@@ -37,47 +44,61 @@ function shouldIgnoreField(fieldName) {
37
44
fieldName === "proposeCorrectionTo" ;
38
45
}
39
46
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
+
40
69
// This function is only called when no matching result was found and therefore will only display
41
70
// the diff between the two items.
42
- function betterLookingDiff ( entry , data ) {
71
+ function betterLookingDiff ( expected , testOutput ) {
43
72
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 ) ) {
47
76
continue ;
48
77
}
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" ;
51
80
continue ;
52
81
}
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" ;
56
85
output += "+" + spaces + contentToDiffLine ( key , value ) + "\n" ;
57
86
} else {
58
- output += spaces + contentToDiffLine ( key , value ) + "\n" ;
87
+ output += spaces + " " + contentToDiffLine ( key , value ) + "\n" ;
59
88
}
60
89
}
61
90
return output + " }" ;
62
91
}
63
92
64
- function lookForEntry ( entry , data ) {
65
- return data . findIndex ( data_entry => {
93
+ function lookForEntry ( expected , testOutput ) {
94
+ return testOutput . findIndex ( testOutputEntry => {
66
95
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 ) ) {
69
98
continue ;
70
99
}
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 ] ) {
81
102
allGood = false ;
82
103
break ;
83
104
}
0 commit comments