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 932b3f6 commit 84a5956
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";
import path from "path";
import puppeteer from "puppeteer";
import lighthouse from "lighthouse";
import { fileURLToPath } from "url";
Expand Down Expand Up @@ -75,27 +76,25 @@ const __dirname = dirname(__filename);
},
});

// Ensure directory exists
const reportsDir = "lighthouse-reports";
if (!fs.existsSync(reportsDir)) {
fs.mkdirSync(reportsDir, { recursive: true });
}

// Save reports
try {
const reportsDir = "lighthouse-reports";
if (!fs.existsSync(reportsDir)) {
fs.mkdirSync(reportsDir, { recursive: true });
}

if (typeof runnerResult.report === "string") {
// Save HTML report
fs.writeFileSync("lighthouse-report.html", runnerResult.report);
console.log("HTML report saved successfully");
const htmlPath = path.join(process.cwd(), "lighthouse-report.html");
fs.writeFileSync(htmlPath, runnerResult.report);
console.log("HTML report saved successfully to:", htmlPath);
}

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");
const jsonPath = path.join(process.cwd(), reportsDir, "report.json");
fs.writeFileSync(jsonPath, JSON.stringify(runnerResult.lhr, null, 2));
console.log("JSON report saved successfully to:", jsonPath);
}

if (!runnerResult.report && !runnerResult.lhr) {
Expand Down

0 comments on commit 84a5956

Please sign in to comment.