Lighthouse Service
The Lighthouse Service provides utilities for parsing and analyzing Lighthouse CI results. It helps in tracking web vitals and performance scores programmatically.
Usage
Reading Reports
The service can find and parse Lighthouse JSON report files generated by lighthouse-ci.
import { findLighthouseResult, getLighthouseResult } from '@orbitus/core/services/lighthouse';
// Find the latest report in the .lighthouseci directory
const reportPath = await findLighthouseResult();
if (reportPath) {
const result = await getLighthouseResult(reportPath);
console.log(`Performance Score: ${result.categories.performance.score * 100}`);
}Web Vitals Score
Calculate a single performance score based on core web vitals metrics.
import { calculatePerformanceScore } from '@orbitus/core/services/lighthouse';
const score = calculatePerformanceScore({
lcp: 1200, // Largest Contentful Paint (ms)
fid: 100, // First Input Delay (ms)
cls: 0.1, // Cumulative Layout Shift
inp: 200 // Interaction to Next Paint (ms)
});
console.log(`Calculated Score: ${score}`);Integration
This service is typically used in CI/CD pipelines or post-deployment scripts to verify that performance metrics meet the required thresholds.
Last updated on