@@ -116,45 +116,51 @@ async function createReport(results) {
116
116
report += '\n' ;
117
117
}
118
118
119
+ /**
120
+ * @param {AuditFail } result
121
+ */
122
+ async function printAuditFail ( result ) {
123
+ let report = '' ;
124
+ report += '<details>\n' ;
125
+ report += `<summary>${ truncate ( result . reason ) } </summary>\n` ;
126
+ report += '\n' ;
127
+ report += '```json\n' ;
128
+ const res = result . response ;
129
+ /** @type {Record<string, string> } */
130
+ const headers = { } ;
131
+ for ( const [ key , val ] of res . headers . entries ( ) ) {
132
+ headers [ key ] = val ;
133
+ }
134
+ let text , json ;
135
+ try {
136
+ text = await res . text ( ) ;
137
+ json = JSON . parse ( text ) ;
138
+ } catch {
139
+ // noop
140
+ }
141
+ report +=
142
+ JSON . stringify (
143
+ {
144
+ status : res . status ,
145
+ statusText : res . statusText ,
146
+ headers,
147
+ body : json || text ,
148
+ } ,
149
+ null ,
150
+ ' ' ,
151
+ ) + '\n' ;
152
+ report += '```\n' ;
153
+ report += '</details>\n' ;
154
+ report += '\n' ;
155
+ return report ;
156
+ }
157
+
119
158
if ( grouped . warn . length ) {
120
159
report += `## Warnings\n` ;
121
160
report += `The server _SHOULD_ support these, but is not required.\n` ;
122
161
for ( const [ i , result ] of grouped . warn . entries ( ) ) {
123
- report += `${ i + 1 } . ${ escapeMarkdown ( result . name ) } <br />\n` ;
124
- report += '```\n' ;
125
- report += `${ truncate ( result . reason ) } \n` ;
126
- report += '```\n' ;
127
- report += '<details>\n' ;
128
- report += '<summary>Response</summary>\n' ;
129
- report += '\n' ;
130
- report += '```json\n' ;
131
- const res = result . response ;
132
- /** @type {Record<string, string> } */
133
- const headers = { } ;
134
- for ( const [ key , val ] of res . headers . entries ( ) ) {
135
- headers [ key ] = val ;
136
- }
137
- let text , json ;
138
- try {
139
- text = await res . text ( ) ;
140
- json = JSON . parse ( text ) ;
141
- } catch {
142
- // noop
143
- }
144
- report +=
145
- JSON . stringify (
146
- {
147
- status : res . status ,
148
- statusText : res . statusText ,
149
- headers,
150
- body : json || text ,
151
- } ,
152
- null ,
153
- ' ' ,
154
- ) + '\n' ;
155
- report += '```\n' ;
156
- report += '</details>\n' ;
157
- report += '\n\n' ;
162
+ report += `${ i + 1 } . ${ escapeMarkdown ( result . name ) } <br />\n\n` ;
163
+ report += await printAuditFail ( result ) ;
158
164
}
159
165
report += '\n' ;
160
166
}
@@ -163,10 +169,8 @@ async function createReport(results) {
163
169
report += `## Errors\n` ;
164
170
report += `The server _MUST_ support these.\n` ;
165
171
for ( const [ i , result ] of grouped . error . entries ( ) ) {
166
- report += `${ i + 1 } . ${ escapeMarkdown ( result . name ) } <br />\n` ;
167
- report += '```\n' ;
168
- report += `${ truncate ( result . reason ) } \n` ;
169
- report += '```\n' ;
172
+ report += `${ i + 1 } . ${ escapeMarkdown ( result . name ) } <br />\n\n` ;
173
+ report += await printAuditFail ( result ) ;
170
174
}
171
175
}
172
176
0 commit comments