@@ -24,16 +24,16 @@ function findReports(pid, dir) {
24
24
return results ;
25
25
}
26
26
27
- function validate ( filepath ) {
27
+ function validate ( filepath , fields ) {
28
28
const report = fs . readFileSync ( filepath , 'utf8' ) ;
29
29
if ( process . report . compact ) {
30
30
const end = report . indexOf ( '\n' ) ;
31
31
assert . strictEqual ( end , report . length - 1 ) ;
32
32
}
33
- validateContent ( JSON . parse ( report ) ) ;
33
+ validateContent ( JSON . parse ( report ) , fields ) ;
34
34
}
35
35
36
- function validateContent ( report ) {
36
+ function validateContent ( report , fields = [ ] ) {
37
37
if ( typeof report === 'string' ) {
38
38
try {
39
39
report = JSON . parse ( report ) ;
@@ -43,7 +43,7 @@ function validateContent(report) {
43
43
}
44
44
}
45
45
try {
46
- _validateContent ( report ) ;
46
+ _validateContent ( report , fields ) ;
47
47
} catch ( err ) {
48
48
try {
49
49
err . stack += util . format ( '\n------\nFailing Report:\n%O' , report ) ;
@@ -52,7 +52,7 @@ function validateContent(report) {
52
52
}
53
53
}
54
54
55
- function _validateContent ( report ) {
55
+ function _validateContent ( report , fields = [ ] ) {
56
56
const isWindows = process . platform === 'win32' ;
57
57
58
58
// Verify that all sections are present as own properties of the report.
@@ -71,6 +71,26 @@ function _validateContent(report) {
71
71
assert ( typeof report [ section ] === 'object' && report [ section ] !== null ) ;
72
72
} ) ;
73
73
74
+ fields . forEach ( ( field ) => {
75
+ function checkLoop ( actual , rest , expect ) {
76
+ actual = actual [ rest . shift ( ) ] ;
77
+ if ( rest . length === 0 && actual !== undefined ) {
78
+ assert . strictEqual ( actual , expect ) ;
79
+ } else {
80
+ assert ( actual ) ;
81
+ checkLoop ( actual , rest , expect ) ;
82
+ }
83
+ }
84
+ let actual , expect ;
85
+ if ( Array . isArray ( field ) ) {
86
+ [ actual , expect ] = field ;
87
+ } else {
88
+ actual = field ;
89
+ expect = undefined ;
90
+ }
91
+ checkLoop ( report , actual . split ( '.' ) , expect ) ;
92
+ } ) ;
93
+
74
94
// Verify the format of the header section.
75
95
const header = report . header ;
76
96
const headerFields = [ 'event' , 'trigger' , 'filename' , 'dumpEventTime' ,
@@ -265,7 +285,7 @@ function _validateContent(report) {
265
285
266
286
// Verify the format of the workers section.
267
287
assert ( Array . isArray ( report . workers ) ) ;
268
- report . workers . forEach ( _validateContent ) ;
288
+ report . workers . forEach ( ( worker ) => _validateContent ( worker ) ) ;
269
289
}
270
290
271
291
function checkForUnknownFields ( actual , expected ) {
0 commit comments