From bcff1282d0a98d3baf4db2b141b8310d11c5f253 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Mon, 18 Jul 2016 20:22:11 +0100 Subject: [PATCH] Fix scoring exception in handlebars (#509) --- lighthouse-core/aggregator/aggregate.js | 4 +++- lighthouse-core/audits/estimated-input-latency.js | 2 +- lighthouse-core/audits/first-meaningful-paint.js | 2 +- lighthouse-core/config/default.json | 2 +- lighthouse-core/test/aggregator/aggregate.js | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lighthouse-core/aggregator/aggregate.js b/lighthouse-core/aggregator/aggregate.js index 5f10f567e2d8..1d4d477f5f57 100644 --- a/lighthouse-core/aggregator/aggregate.js +++ b/lighthouse-core/aggregator/aggregate.js @@ -85,7 +85,9 @@ class Aggregate { } if (typeof result.rawValue !== typeof expected.rawValue) { - return weight; + const msg = + `Expected rawValue of type ${typeof expected.rawValue}, got ${typeof result.rawValue}`; + throw new Error(msg); } switch (typeof expected.rawValue) { diff --git a/lighthouse-core/audits/estimated-input-latency.js b/lighthouse-core/audits/estimated-input-latency.js index ad2401a4295f..e2708e9914bd 100644 --- a/lighthouse-core/audits/estimated-input-latency.js +++ b/lighthouse-core/audits/estimated-input-latency.js @@ -56,7 +56,7 @@ class EstimatedInputLatency extends Audit { const latencyPercentiles = TracingProcessor.getRiskToResponsiveness(model, trace, startTime); const ninetieth = latencyPercentiles.find(result => result.percentile === 0.9); - const rawValue = ninetieth.time.toFixed(1); + const rawValue = parseFloat(ninetieth.time.toFixed(1)); // Use the CDF of a log-normal distribution for scoring. // 10th Percentile ≈ 58ms diff --git a/lighthouse-core/audits/first-meaningful-paint.js b/lighthouse-core/audits/first-meaningful-paint.js index 6d5213367d0e..c23916a90e3c 100644 --- a/lighthouse-core/audits/first-meaningful-paint.js +++ b/lighthouse-core/audits/first-meaningful-paint.js @@ -80,7 +80,7 @@ class FirstMeaningfulPaint extends Audit { resolve(FirstMeaningfulPaint.generateAuditResult({ score: result.score, - rawValue: result.duration, + rawValue: parseFloat(result.duration), displayValue: `${result.duration}ms`, debugString: result.debugString, optimalValue: this.meta.optimalValue, diff --git a/lighthouse-core/config/default.json b/lighthouse-core/config/default.json index 10f964a2ed53..9becc46705b7 100644 --- a/lighthouse-core/config/default.json +++ b/lighthouse-core/config/default.json @@ -228,7 +228,7 @@ "weight": 1 }, "content-width": { - "value": true, + "rawValue": true, "weight": 1 } } diff --git a/lighthouse-core/test/aggregator/aggregate.js b/lighthouse-core/test/aggregator/aggregate.js index c3a0c5df9fd6..b8891ed71d9e 100644 --- a/lighthouse-core/test/aggregator/aggregate.js +++ b/lighthouse-core/test/aggregator/aggregate.js @@ -205,7 +205,7 @@ describe('Aggregate', () => { return assert.equal(Aggregate._convertToWeight(result, expected), 0); }); - it('returns a weight of zero if types do not match', () => { + it('throws if types do not match', () => { const expected = { rawValue: true, weight: 10 @@ -217,7 +217,7 @@ describe('Aggregate', () => { displayValue: '20' }; - return assert.equal(Aggregate._convertToWeight(result, expected), 0); + return assert.throws(_ => Aggregate._convertToWeight(result, expected)); }); it('scores a set correctly (contributesToScore: true)', () => {