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 80b2680 commit a6d3786
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/lighthouse-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,27 @@ jobs:
# Debug information
echo "Current directory: $(pwd)"
echo "Listing directory contents:"
ls -la
echo "Listing all directories recursively:"
find . -type f -name "lighthouse-report.html"
find . -type f -name "report.json"
# Check both possible locations for the HTML report
HTML_REPORT=""
if [ -f "lighthouse-report.html" ]; then
echo "Found HTML report"
HTML_REPORT="lighthouse-report.html"
elif [ -f "lighthouse-reports/lighthouse-report.html" ]; then
HTML_REPORT="lighthouse-reports/lighthouse-report.html"
fi
if [ -n "$HTML_REPORT" ]; then
echo "Found HTML report at: $HTML_REPORT"
node -e "
const core = require('@actions/core');
const fs = require('fs');
const path = require('path');
try {
const htmlReport = fs.readFileSync('lighthouse-report.html', 'utf8');
const htmlReport = fs.readFileSync('${HTML_REPORT}', 'utf8');
const jsonReport = fs.readFileSync('lighthouse-reports/report.json', 'utf8');
const results = JSON.parse(jsonReport);
Expand All @@ -208,7 +217,7 @@ jobs:
.addRaw('## Performance Scores\n\n');
Object.entries(results.categories).forEach(([key, value]) => {
summary.addRaw(`### ${value.title}\n📊 Score: ${Math.floor(value.score * 100)}%\n\n`);
summary.addRaw(\`### \${value.title}\n📊 Score: \${Math.floor(value.score * 100)}%\n\n\`);
});
summary
Expand All @@ -223,13 +232,15 @@ jobs:
console.log('Summary generated successfully');
} catch (error) {
console.error('Error generating summary:', error);
console.error('File contents:', fs.readdirSync('.'));
process.exit(1);
}
"
else
echo "Error: Lighthouse report file not found in $(pwd)"
echo "Error: Lighthouse report file not found"
echo "Directory contents:"
ls -la
ls -la lighthouse-reports/
exit 1
fi
env:
Expand Down
41 changes: 25 additions & 16 deletions AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ const __dirname = dirname(__filename);
await page.setViewport({ width: 1920, height: 1080 });

// Login process
await page.goto("http://localhost:8080/Portal", {
waitUntil: "networkidle0",
});
await page.goto(
"http://localhost:8080/Portal/pro/portal/1549F58C18A6C562/DashboardPage.ivp?dashboardId=1",
{
waitUntil: "networkidle0",
}
);

await page.evaluate((data) => {
const form = document.createElement("form");
Expand Down Expand Up @@ -81,27 +84,33 @@ const __dirname = dirname(__filename);
const scriptDir = dirname(fileURLToPath(import.meta.url));
const reportsDir = path.join(scriptDir, "lighthouse-reports");

console.log("Script directory:", scriptDir);
console.log("Reports directory:", reportsDir);

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

if (typeof runnerResult.report === "string") {
// Save HTML report in the same directory as the script
const htmlPath = path.join(scriptDir, "lighthouse-report.html");
fs.writeFileSync(htmlPath, runnerResult.report);
console.log("HTML report saved successfully to:", htmlPath);
}
if (runnerResult && runnerResult.report) {
// Save both HTML files (for compatibility)
const htmlPaths = [
path.join(scriptDir, "lighthouse-report.html"),
path.join(reportsDir, "lighthouse-report.html"),
];

if (runnerResult.lhr) {
// Save JSON report in the reports directory
htmlPaths.forEach((htmlPath) => {
fs.writeFileSync(htmlPath, runnerResult.report);
console.log("HTML report saved to:", htmlPath);
});

// Save JSON report
const jsonPath = path.join(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) {
throw new Error("No valid report data generated");
console.log("JSON report saved to:", jsonPath);
} else {
console.error("Runner result:", runnerResult);
throw new Error("No valid report data in runner result");
}
} catch (error) {
console.error("Error saving reports:", error);
Expand Down

0 comments on commit a6d3786

Please sign in to comment.