4c8714c12d
- Fixed all form tests (20/20 passing) - Fixed all performance tests (35/35 passing) - Fixed all SEO and accessibility tests (30/30 passing) - Enhanced test framework with custom reporting - Added performance baseline tracking - Improved test reliability and error handling
33 lines
1018 B
JavaScript
33 lines
1018 B
JavaScript
const lighthouse = require('lighthouse').default;
|
|
const chromeLauncher = require('chrome-launcher');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
async function runLighthouse(url, options = {}) {
|
|
const chrome = await chromeLauncher.launch({ chromeFlags: ['--headless'] });
|
|
options.port = chrome.port;
|
|
|
|
const runnerResult = await lighthouse(url, options);
|
|
await chrome.kill();
|
|
|
|
return runnerResult;
|
|
}
|
|
|
|
function generateReport(result, outputPath) {
|
|
const reportHtml = result.report;
|
|
fs.writeFileSync(outputPath, reportHtml);
|
|
return outputPath;
|
|
}
|
|
|
|
function extractMetrics(result) {
|
|
const categories = result.lhr?.categories || {};
|
|
return {
|
|
performance: categories.performance?.score * 100 || 0,
|
|
accessibility: categories.accessibility?.score * 100 || 0,
|
|
bestPractices: categories['best-practices']?.score * 100 || 0,
|
|
seo: categories.seo?.score * 100 || 0,
|
|
pwa: categories.pwa?.score * 100 || 0
|
|
};
|
|
}
|
|
|
|
module.exports = { runLighthouse, generateReport, extractMetrics }; |