From 539412ef49c331d5f8c124fc7689c95708726123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 27 Sep 2024 13:19:53 +0200 Subject: [PATCH] chore: fix formatLighthouseReport() CI (#10527) --- admin/scripts/formatLighthouseReport.js | 37 +++++++++++++------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/admin/scripts/formatLighthouseReport.js b/admin/scripts/formatLighthouseReport.js index 0b1343bc4f56..d4bff682116c 100644 --- a/admin/scripts/formatLighthouseReport.js +++ b/admin/scripts/formatLighthouseReport.js @@ -41,16 +41,22 @@ function createURL(url) { * @param {Object} param0 * @param {string} param0.url * @param {LighthouseSummary} param0.summary - * @param {string} param0.reportUrl + * @param {string | undefined} param0.reportUrl + * @return {string} */ -const createMarkdownTableRow = ({url, summary, reportUrl}) => - [ - `| [${createURL(url).pathname}](${url})`, +const createMarkdownTableRow = ({url, summary, reportUrl}) => { + const columns = [ + `[${createURL(url).pathname}](${url})`, + .../** @type {(keyof LighthouseSummary)[]} */ ( Object.keys(summaryKeys) ).map((k) => scoreEntry(summary[k])), - `[Report](${reportUrl}) |`, - ].join(' | '); + + reportUrl ? `Report N/A` : `[Report](${reportUrl})`, + ]; + + return `| ${columns.join(' | ')} |`; +}; const createMarkdownTableHeader = () => [ ['| URL', ...Object.values(summaryKeys), 'Report |'].join(' | '), @@ -64,18 +70,15 @@ const createMarkdownTableHeader = () => [ * @param {Record} param0.links * @param {{url: string, summary: LighthouseSummary}[]} param0.results */ -const createLighthouseReport = ({results, links}) => { +export default function formatLighthouseReport({results, links}) { const tableHeader = createMarkdownTableHeader(); const tableBody = results.map((result) => { - const testUrl = /** @type {string} */ ( - Object.keys(links).find((key) => key === result.url) - ); - const reportPublicUrl = /** @type {string} */ (links[testUrl]); - + const {url, summary} = result; + const reportUrl = /** @type {string | undefined} */ (links[result.url]); return createMarkdownTableRow({ - url: testUrl, - summary: result.summary, - reportUrl: reportPublicUrl, + url, + summary, + reportUrl, }); }); const comment = [ @@ -86,6 +89,4 @@ const createLighthouseReport = ({results, links}) => { '', ]; return comment.join('\n'); -}; - -export default createLighthouseReport; +}