Skip to content

Commit

Permalink
hack
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Feb 10, 2025
1 parent d69bddd commit ca0de16
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/audits/insights/image-delivery-insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class ImageDeliveryInsight extends Audit {
wastedBytes: image.byteSavings,
subItems: {
type: /** @type {const} */ ('subitems'),
// TODO: when strings update to remove number from "reason" uistrings, update this
// to use `image.optimizations.map(...)` and construct strings from the type.
items: (relatedEventsMap?.get(image.request) ?? []).map((reason, i) => ({
reason,
wastedBytes: image.optimizations[i].byteSavings,
Expand Down
8 changes: 7 additions & 1 deletion core/audits/insights/insight-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ async function adaptInsightToAuditProduct(artifacts, context, insightName, creat
metricSavings = {...metricSavings, LCP: /** @type {any} */ (0)};
}

let score = insight.shouldShow ? 0 : 1;
// TODO: change insight model to denote passing/failing/informative. Until then... hack it.
if (insightName === 'LCPPhases') {
score = metricSavings?.LCP ?? 0 >= 1000 ? 0 : 1;
}

return {
scoreDisplayMode:
insight.metricSavings ? Audit.SCORING_MODES.METRIC_SAVINGS : Audit.SCORING_MODES.NUMERIC,
score: insight.shouldShow ? 0 : 1,
score,
metricSavings,
warnings: insight.warnings,
details,
Expand Down
4 changes: 2 additions & 2 deletions core/test/fixtures/user-flows/reports/sample-flow-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -3994,7 +3994,7 @@
"id": "lcp-phases-insight",
"title": "LCP by phase",
"description": "Each [phase has specific improvement strategies](https://web.dev/articles/optimize-lcp#lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.",
"score": 0,
"score": 1,
"scoreDisplayMode": "numeric",
"metricSavings": {
"LCP": 0
Expand Down Expand Up @@ -23087,7 +23087,7 @@
"id": "lcp-phases-insight",
"title": "LCP by phase",
"description": "Each [phase has specific improvement strategies](https://web.dev/articles/optimize-lcp#lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.",
"score": 0,
"score": 1,
"scoreDisplayMode": "numeric",
"metricSavings": {
"LCP": 0
Expand Down
2 changes: 1 addition & 1 deletion core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6107,7 +6107,7 @@
"id": "lcp-phases-insight",
"title": "LCP by phase",
"description": "Each [phase has specific improvement strategies](https://web.dev/articles/optimize-lcp#lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.",
"score": 0,
"score": 1,
"scoreDisplayMode": "numeric",
"metricSavings": {
"LCP": 0
Expand Down

0 comments on commit ca0de16

Please sign in to comment.