chore: fix formatLighthouseReport() CI (#10527)

This commit is contained in:
Sébastien Lorber 2024-09-27 13:19:53 +02:00 committed by GitHub
parent 0692fe96b5
commit 539412ef49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,16 +41,22 @@ function createURL(url) {
* @param {Object} param0 * @param {Object} param0
* @param {string} param0.url * @param {string} param0.url
* @param {LighthouseSummary} param0.summary * @param {LighthouseSummary} param0.summary
* @param {string} param0.reportUrl * @param {string | undefined} param0.reportUrl
* @return {string}
*/ */
const createMarkdownTableRow = ({url, summary, reportUrl}) => const createMarkdownTableRow = ({url, summary, reportUrl}) => {
[ const columns = [
`| [${createURL(url).pathname}](${url})`, `[${createURL(url).pathname}](${url})`,
.../** @type {(keyof LighthouseSummary)[]} */ ( .../** @type {(keyof LighthouseSummary)[]} */ (
Object.keys(summaryKeys) Object.keys(summaryKeys)
).map((k) => scoreEntry(summary[k])), ).map((k) => scoreEntry(summary[k])),
`[Report](${reportUrl}) |`,
].join(' | '); reportUrl ? `Report N/A` : `[Report](${reportUrl})`,
];
return `| ${columns.join(' | ')} |`;
};
const createMarkdownTableHeader = () => [ const createMarkdownTableHeader = () => [
['| URL', ...Object.values(summaryKeys), 'Report |'].join(' | '), ['| URL', ...Object.values(summaryKeys), 'Report |'].join(' | '),
@ -64,18 +70,15 @@ const createMarkdownTableHeader = () => [
* @param {Record<string, string>} param0.links * @param {Record<string, string>} param0.links
* @param {{url: string, summary: LighthouseSummary}[]} param0.results * @param {{url: string, summary: LighthouseSummary}[]} param0.results
*/ */
const createLighthouseReport = ({results, links}) => { export default function formatLighthouseReport({results, links}) {
const tableHeader = createMarkdownTableHeader(); const tableHeader = createMarkdownTableHeader();
const tableBody = results.map((result) => { const tableBody = results.map((result) => {
const testUrl = /** @type {string} */ ( const {url, summary} = result;
Object.keys(links).find((key) => key === result.url) const reportUrl = /** @type {string | undefined} */ (links[result.url]);
);
const reportPublicUrl = /** @type {string} */ (links[testUrl]);
return createMarkdownTableRow({ return createMarkdownTableRow({
url: testUrl, url,
summary: result.summary, summary,
reportUrl: reportPublicUrl, reportUrl,
}); });
}); });
const comment = [ const comment = [
@ -86,6 +89,4 @@ const createLighthouseReport = ({results, links}) => {
'', '',
]; ];
return comment.join('\n'); return comment.join('\n');
}; }
export default createLighthouseReport;