Skip to content

Commit 68cd6c0

Browse files
committed
even better print
1 parent fbe9906 commit 68cd6c0

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

scripts/audit-implementation.mjs

+43-39
Original file line numberDiff line numberDiff line change
@@ -116,45 +116,51 @@ async function createReport(results) {
116116
report += '\n';
117117
}
118118

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+
119158
if (grouped.warn.length) {
120159
report += `## Warnings\n`;
121160
report += `The server _SHOULD_ support these, but is not required.\n`;
122161
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);
158164
}
159165
report += '\n';
160166
}
@@ -163,10 +169,8 @@ async function createReport(results) {
163169
report += `## Errors\n`;
164170
report += `The server _MUST_ support these.\n`;
165171
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);
170174
}
171175
}
172176

0 commit comments

Comments
 (0)