@casoon/auditmysite
Version:
A comprehensive command-line tool for automated accessibility, security, performance, and SEO testing using Playwright and pa11y, based on sitemap URLs
52 lines • 2.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LighthouseIntegration = void 0;
// Lighthouse import
const lighthouse_1 = __importDefault(require("lighthouse"));
class LighthouseIntegration {
constructor(browserManager) {
this.browserManager = browserManager;
}
async runLighthouse(url, options = {}) {
console.log(`📊 Running Lighthouse for ${url}...`);
const lighthouseOptions = {
logLevel: 'info',
output: 'json',
onlyCategories: ['performance', 'accessibility', 'best-practices', 'seo'],
port: this.browserManager.getPort(),
...options
};
try {
const runnerResult = await (0, lighthouse_1.default)(url, lighthouseOptions, undefined);
const lhr = runnerResult?.lhr;
if (!lhr) {
throw new Error('Lighthouse result is undefined');
}
return {
performance: Math.round((lhr.categories.performance.score || 0) * 100),
accessibility: Math.round((lhr.categories.accessibility.score || 0) * 100),
bestPractices: Math.round((lhr.categories['best-practices']?.score || 0) * 100),
seo: Math.round((lhr.categories.seo.score || 0) * 100),
metrics: {
firstContentfulPaint: lhr.audits['first-contentful-paint']?.numericValue || 0,
largestContentfulPaint: lhr.audits['largest-contentful-paint']?.numericValue || 0,
firstInputDelay: lhr.audits['max-potential-fid']?.numericValue || 0,
cumulativeLayoutShift: lhr.audits['cumulative-layout-shift']?.numericValue || 0,
totalBlockingTime: lhr.audits['total-blocking-time']?.numericValue || 0,
speedIndex: lhr.audits['speed-index']?.numericValue || 0
},
opportunities: lhr.audits['opportunities'] ? [lhr.audits['opportunities']] : [],
diagnostics: lhr.audits['diagnostics'] ? [lhr.audits['diagnostics']] : []
};
}
catch (error) {
console.error(`❌ Lighthouse failed for ${url}:`, error);
throw error;
}
}
}
exports.LighthouseIntegration = LighthouseIntegration;
//# sourceMappingURL=lighthouse-integration.js.map