Skip to content

Commit

Permalink
feature/IVYPORTAL-17377-Create-pipeline-to-run-Lighthouse-report
Browse files Browse the repository at this point in the history
  • Loading branch information
nhthinh-axonivy committed Dec 27, 2024
1 parent e8e73b0 commit d3120ba
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d3120ba

Please sign in to comment.