Skip to content

Commit

Permalink
Fix scoring exception in handlebars (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
paullewis authored and paulirish committed Jul 18, 2016
1 parent 47c2f96 commit bcff128
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lighthouse-core/aggregator/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"weight": 1
},
"content-width": {
"value": true,
"rawValue": true,
"weight": 1
}
}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/aggregator/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)', () => {
Expand Down

0 comments on commit bcff128

Please sign in to comment.