From d3120baee4453ae3be75aa784d6e5ad64a56bc9f Mon Sep 17 00:00:00 2001 From: nhthinh-axonivy Date: Fri, 27 Dec 2024 15:56:07 +0700 Subject: [PATCH] feature/IVYPORTAL-17377-Create-pipeline-to-run-Lighthouse-report --- .../lighthouse/puppeteer-script.mjs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs b/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs index 24c1e5d4d5..f233b5c7e2 100644 --- a/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs +++ b/AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs @@ -60,22 +60,38 @@ const __dirname = dirname(__filename); await page.waitForNavigation(); // Run Lighthouse - const { lhr } = await lighthouse(page.url(), { + const runnerResult = await lighthouse(page.url(), { port: new URL(browser.wsEndpoint()).port, output: ["html", "json"], logLevel: "info", onlyCategories: ["performance", "accessibility", "best-practices", "seo"], + formFactor: "desktop", + screenEmulation: { + mobile: false, + width: 1920, + height: 1080, + deviceScaleFactor: 1, + disabled: false, + }, }); + // Ensure directory exists + const reportsDir = "lighthouse-reports"; + if (!fs.existsSync(reportsDir)) { + fs.mkdirSync(reportsDir, { recursive: true }); + } + // Save reports - if (lhr.report && lhr.report.length > 0) { - fs.writeFileSync("lighthouse-report.html", lhr.report[0]); + const htmlReport = runnerResult.report; + if (htmlReport) { + fs.writeFileSync("lighthouse-report.html", htmlReport); fs.writeFileSync( - "lighthouse-reports/report.json", - JSON.stringify(lhr, null, 2) + path.join(reportsDir, "report.json"), + JSON.stringify(runnerResult.lhr, null, 2) ); + console.log("Reports generated successfully"); } else { - throw new Error("Lighthouse report is undefined or empty"); + throw new Error("Failed to generate Lighthouse report"); } await browser.close();