Skip to content

Commit 205a30f

Browse files
committed
even better print
1 parent 7ca0a2a commit 205a30f

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
@@ -128,45 +128,51 @@ async function createReport(results) {
128128
report += '\n';
129129
}
130130

131+
/**
132+
* @param {AuditFail} result
133+
*/
134+
async function printAuditFail(result) {
135+
let report = '';
136+
report += '<details>\n';
137+
report += `<summary>${truncate(result.reason)}</summary>\n`;
138+
report += '\n';
139+
report += '```json\n';
140+
const res = result.response;
141+
/** @type {Record<string, string>} */
142+
const headers = {};
143+
for (const [key, val] of res.headers.entries()) {
144+
headers[key] = val;
145+
}
146+
let text, json;
147+
try {
148+
text = await res.text();
149+
json = JSON.parse(text);
150+
} catch {
151+
// noop
152+
}
153+
report +=
154+
JSON.stringify(
155+
{
156+
status: res.status,
157+
statusText: res.statusText,
158+
headers,
159+
body: json || text,
160+
},
161+
null,
162+
' ',
163+
) + '\n';
164+
report += '```\n';
165+
report += '</details>\n';
166+
report += '\n';
167+
return report;
168+
}
169+
131170
if (grouped.warn.length) {
132171
report += `## Warnings\n`;
133172
report += `The server _SHOULD_ support these, but is not required.\n`;
134173
for (const [i, result] of grouped.warn.entries()) {
135-
report += `${i + 1}. ${escapeMarkdown(result.name)}<br />\n`;
136-
report += '```\n';
137-
report += `${truncate(result.reason)}\n`;
138-
report += '```\n';
139-
report += '<details>\n';
140-
report += '<summary>Response</summary>\n';
141-
report += '\n';
142-
report += '```json\n';
143-
const res = result.response;
144-
/** @type {Record<string, string>} */
145-
const headers = {};
146-
for (const [key, val] of res.headers.entries()) {
147-
headers[key] = val;
148-
}
149-
let text, json;
150-
try {
151-
text = await res.text();
152-
json = JSON.parse(text);
153-
} catch {
154-
// noop
155-
}
156-
report +=
157-
JSON.stringify(
158-
{
159-
status: res.status,
160-
statusText: res.statusText,
161-
headers,
162-
body: json || text,
163-
},
164-
null,
165-
' ',
166-
) + '\n';
167-
report += '```\n';
168-
report += '</details>\n';
169-
report += '\n\n';
174+
report += `${i + 1}. ${escapeMarkdown(result.name)}<br />\n\n`;
175+
report += await printAuditFail(result);
170176
}
171177
report += '\n';
172178
}
@@ -175,10 +181,8 @@ async function createReport(results) {
175181
report += `## Errors\n`;
176182
report += `The server _MUST_ support these.\n`;
177183
for (const [i, result] of grouped.error.entries()) {
178-
report += `${i + 1}. ${escapeMarkdown(result.name)}<br />\n`;
179-
report += '```\n';
180-
report += `${truncate(result.reason)}\n`;
181-
report += '```\n';
184+
report += `${i + 1}. ${escapeMarkdown(result.name)}<br />\n\n`;
185+
report += await printAuditFail(result);
182186
}
183187
}
184188

0 commit comments

Comments
 (0)