From 134fa7bd4f6ef8533b6847e63084d85139054137 Mon Sep 17 00:00:00 2001 From: nhthinh-axonivy Date: Fri, 27 Dec 2024 17:33:08 +0700 Subject: [PATCH] feature/IVYPORTAL-17377-Create-pipeline-to-run-Lighthouse-report --- .../lighthouse/puppeteer-script.mjs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs b/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs index 6ef0640a94..9f88b8c545 100644 --- a/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs +++ b/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs @@ -93,16 +93,25 @@ const __dirname = dirname(__filename); } if (runnerResult && runnerResult.report) { - // Save both HTML files (for compatibility) - const htmlPaths = [ - path.join(scriptDir, "lighthouse-report.html"), - path.join(reportsDir, "lighthouse-report.html"), - ]; - - htmlPaths.forEach((htmlPath) => { - fs.writeFileSync(htmlPath, runnerResult.report); - console.log("HTML report saved to:", htmlPath); - }); + // Get the HTML report (it's the first output format) + const htmlReport = Array.isArray(runnerResult.report) + ? runnerResult.report[0] + : runnerResult.report; + + if (typeof htmlReport === "string") { + // Save HTML report in both locations + const htmlPaths = [ + path.join(scriptDir, "lighthouse-report.html"), + path.join(reportsDir, "lighthouse-report.html"), + ]; + + htmlPaths.forEach((htmlPath) => { + fs.writeFileSync(htmlPath, htmlReport); + console.log("HTML report saved to:", htmlPath); + }); + } else { + throw new Error("HTML report is not a string"); + } // Save JSON report const jsonPath = path.join(reportsDir, "report.json");