Skip to content

Commit

Permalink
compare reports
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Khare <[email protected]>
  • Loading branch information
khareyash05 committed Dec 16, 2024
1 parent 4c075fc commit ef98b3d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ jobs:
- name: run Lighthouse CI for Keploy.io Deployed Website
run: |
npm install -g @lhci/[email protected]
lhci autorun --upload.target=temporary-public-storage --config=lighthouserckeploy.json || echo "LHCI failed!"
lhci autorun --upload.target=temporary-public-storage --config=lighthouserckeploy.json || echo "LHCI failed!"
- name: Compare Lighthouse Reports
run: |
node scripts/compare-lhci-reports.js
37 changes: 37 additions & 0 deletions compare-lhci-reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const fs = require('fs');

function loadReport(path) {
if (!fs.existsSync(path)) {
console.error(`Report not found at path: ${path}`);
process.exit(1);
}
const data = fs.readFileSync(path, 'utf8');
return JSON.parse(data);
}

const appReportPath = './lhci-reports/app/latest-run/report.json';
const keployReportPath = './lhci-reports/keploy.io/latest-run/report.json';

const appReport = loadReport(appReportPath);
const keployReport = loadReport(keployReportPath);

const categories = ['performance', 'accessibility', 'best-practices', 'seo'];

let allPass = true;

categories.forEach(category => {
const appScore = appReport.categories[category].score;
const keployScore = keployReport.categories[category].score;
console.log(`Comparing ${category}: App=${appScore} vs Keploy.io=${keployScore}`);
if (appScore < keployScore) {
console.error(`Score for ${category} is lower in the application (${appScore}) than Keploy.io (${keployScore})`);
allPass = false;
}
});

if (!allPass) {
console.error('Lighthouse scores are lower than the baseline. Failing the CI job.');
process.exit(1);
} else {
console.log('All Lighthouse scores are equal or better than the baseline.');
}
3 changes: 2 additions & 1 deletion lighthouserc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"ci": {
"upload": {
"target": "temporary-public-storage"
"target": "filesystem",
"outputDir": "./lhci-reports/app"
},
"collect": {
"startServerCommand": "npm run start",
Expand Down
3 changes: 2 additions & 1 deletion lighthouserckeploy.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"ci": {
"upload": {
"target": "temporary-public-storage"
"target": "filesystem",
"outputDir": "./lhci-reports/keploy.io"
},
"collect": {
"url": [
Expand Down

0 comments on commit ef98b3d

Please sign in to comment.