Skip to content

Commit

Permalink
fix(report): drop custom performance for lighthouse metrics (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
revolunet authored May 6, 2024
1 parent a3884e4 commit 576b268
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 82 deletions.
45 changes: 0 additions & 45 deletions report/src/summary/lighthouse.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,11 @@
const { scoreToGrade } = require("../utils");

// compute a performance score from 0 to 100 from lighthouse report
/**
* @param {LighthouseReport} reportData
*
* @returns {number}
*/
const getPerformanceScore = (reportData) => {
/* @type {LighthouseReport} */
if (!reportData) {
return 0;
}
const numRequests =
reportData.audits &&
reportData.audits.diagnostics &&
reportData.audits.diagnostics.details?.items &&
reportData.audits.diagnostics.details?.items[0].numRequests;
const totalByteWeight =
reportData.audits &&
reportData.audits.diagnostics &&
reportData.audits.diagnostics.details?.items &&
reportData.audits.diagnostics.details?.items[0].totalByteWeight;

const maxRequests = 50;
const maxByteWeight = 1024 * 1024;

let score = 100;

// penalty for additional requests : -5 per additionnal request
if (numRequests > maxRequests) {
score -= Math.min(100 / 2, (numRequests - maxRequests) * 5);
}
// penalty for big totalByteWeight : -20 per Mb
if (totalByteWeight > maxByteWeight) {
score -= Math.min(
100 / 2,
((totalByteWeight - maxByteWeight) / (1024 * 1024)) * 20
);
}
score = Math.max(0, score / 100);
return score;
};

/** @param {LighthouseReport} report */
const summary = (report) => {
/* @type {LighthouseReport} */
const reportData = (report && Array.isArray(report) && report[0]) || report; // use first lhr report
if (reportData && reportData.categories) {
const lhrCategories = reportData.categories;
if (lhrCategories["performance"]) {
lhrCategories["performance"].score = getPerformanceScore(reportData);
}

return Object.keys(lhrCategories).reduce((scores, key) => {
const score = lhrCategories[key].score;
Expand Down
8 changes: 4 additions & 4 deletions report/src/summary/lighthouse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const tests = [
report: {
categories: {
performance: {
score: 42,
score: 1,
},
seo: {
score: 0.5,
Expand Down Expand Up @@ -71,7 +71,7 @@ const tests = [
report: {
categories: {
performance: {
score: 42,
score: 0.1,
},
seo: {
score: 0.1,
Expand All @@ -94,8 +94,8 @@ const tests = [
},
},
expected: {
lighthouse_performance: 0.3,
lighthouse_performanceGrade: "E",
lighthouse_performance: 0.1,
lighthouse_performanceGrade: "F",
lighthouse_seo: 0.1,
lighthouse_seoGrade: "F",
lighthouse_stuff: 0,
Expand Down
4 changes: 0 additions & 4 deletions report/www/src/components/LightHouse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { btoa } from "../utils";
import { BadgeUpdatedAt } from "./BadgeUpdatedAt";
import { Gauge } from "./Gauge";
import { Panel } from "./Panel";
import { getPerformanceScore } from "../lib/lighthouse/getPerformanceScore";
import { AccessibilityWarnings } from "../lib/lighthouse/AccessibilityWarnings";
import styles from "./lightHouse.module.scss";

Expand Down Expand Up @@ -95,9 +94,6 @@ export const LightHouse: React.FC<LighthouseProps> = ({ data, url }) => {
</div>

{audits.map((audit) => {
// use custom performance scoring
audit.categories.performance.score = getPerformanceScore(audit);

const highlights = {
"First contentful Paint":
audit.audits.metrics.details &&
Expand Down
29 changes: 0 additions & 29 deletions report/www/src/lib/lighthouse/getPerformanceScore.ts

This file was deleted.

0 comments on commit 576b268

Please sign in to comment.