mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
V2 Feature overhaul and improvements
This commit is contained in:
@@ -174,9 +174,37 @@ async function _executeTest(url, options) {
|
||||
},
|
||||
userAgent: lhr.userAgent,
|
||||
isMobile: isMobile,
|
||||
filmstrip: captureFilmstrip ? (lhr.audits['screenshot-thumbnails']?.details?.items || []) : []
|
||||
filmstrip: captureFilmstrip ? (lhr.audits['screenshot-thumbnails']?.details?.items || []) : [],
|
||||
details: {
|
||||
lcpElement: lhr.audits['largest-contentful-paint-element']?.details?.items?.[0] || null,
|
||||
clsShifts: lhr.audits['layout-shifts']?.details?.items || [],
|
||||
longTasks: lhr.audits['long-tasks']?.details?.items || []
|
||||
}
|
||||
};
|
||||
|
||||
// Calculate Carbon Footprint
|
||||
try {
|
||||
const { checkGreenHosting, calculateCarbon } = require('./analysis/carbon-calculator');
|
||||
let transferSize = 0;
|
||||
const networkItems = lhr.audits['network-requests']?.details?.items || [];
|
||||
networkItems.forEach(item => {
|
||||
transferSize += item.transferSize || 0;
|
||||
});
|
||||
|
||||
const urlObj = new URL(lhr.finalUrl || url);
|
||||
const isGreen = await checkGreenHosting(urlObj.hostname);
|
||||
const carbonData = calculateCarbon(transferSize, isGreen);
|
||||
|
||||
summary.carbon = {
|
||||
co2: carbonData.co2,
|
||||
rating: carbonData.rating,
|
||||
isGreen: isGreen,
|
||||
transferSize: transferSize
|
||||
};
|
||||
} catch (carbonErr) {
|
||||
console.warn('Carbon calculation failed:', carbonErr);
|
||||
}
|
||||
|
||||
// Save JSON Summary
|
||||
let jsonPath = path.join(reportDir, `${testId}.json`);
|
||||
fs.writeFileSync(jsonPath, JSON.stringify(summary, null, 2));
|
||||
@@ -263,7 +291,7 @@ async function _executeTest(url, options) {
|
||||
options.userIp || null,
|
||||
isMobile,
|
||||
JSON.stringify(summary.scores),
|
||||
JSON.stringify(summary.metrics),
|
||||
JSON.stringify({ ...summary.metrics, carbon: summary.carbon, details: summary.details }),
|
||||
JSON.stringify(filmstripData)
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user