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 d3120ba commit 932b3f6
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,28 @@ const __dirname = dirname(__filename);
}

// Save reports
const htmlReport = runnerResult.report;
if (htmlReport) {
fs.writeFileSync("lighthouse-report.html", htmlReport);
fs.writeFileSync(
path.join(reportsDir, "report.json"),
JSON.stringify(runnerResult.lhr, null, 2)
);
console.log("Reports generated successfully");
} else {
throw new Error("Failed to generate Lighthouse report");
try {
if (typeof runnerResult.report === "string") {
// Save HTML report
fs.writeFileSync("lighthouse-report.html", runnerResult.report);
console.log("HTML report saved successfully");
}

if (runnerResult.lhr) {
// Save JSON report
fs.writeFileSync(
path.join(reportsDir, "report.json"),
JSON.stringify(runnerResult.lhr, null, 2)
);
console.log("JSON report saved successfully");
}

if (!runnerResult.report && !runnerResult.lhr) {
throw new Error("No valid report data generated");
}
} catch (error) {
console.error("Error saving reports:", error);
throw error;
}

await browser.close();
Expand Down

0 comments on commit 932b3f6

Please sign in to comment.