Skip to content

Commit 82c5051

Browse files
paullewisbrendankenny
authored andcommitted
Fixes TTI not being counted in overall score
Better checking of aggregation config to prevent happening again. Changes TTI audit rawValue to be a float not string.
1 parent 916b335 commit 82c5051

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

lighthouse-core/aggregator/aggregate.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,28 @@ class Aggregate {
6767
* @private
6868
* @param {!AuditResult} result The audit's output value.
6969
* @param {!AggregationCriterion} expected The aggregation's expected value and weighting for this result.
70+
* @param {!string} name The name of the audit.
7071
* @return {number} The weighted result.
7172
*/
72-
static _convertToWeight(result, expected) {
73+
static _convertToWeight(result, expected, name) {
7374
let weight = 0;
7475

7576
if (typeof expected === 'undefined' ||
7677
typeof expected.rawValue === 'undefined' ||
7778
typeof expected.weight === 'undefined') {
78-
return weight;
79+
const msg =
80+
`Config for ${name} is undefined or does not contain rawValue and weight properties`;
81+
throw new Error(msg);
7982
}
8083

8184
if (typeof result === 'undefined' ||
82-
typeof result.rawValue === 'undefined' ||
8385
typeof result.score === 'undefined') {
84-
return weight;
86+
const msg =
87+
`Audit result for ${name} is undefined or does not contain score property`;
88+
throw new Error(msg);
8589
}
8690

87-
if (typeof result.rawValue !== typeof expected.rawValue) {
91+
if (typeof result.score !== typeof expected.rawValue) {
8892
const msg =
8993
`Expected rawValue of type ${typeof expected.rawValue}, got ${typeof result.rawValue}`;
9094
throw new Error(msg);
@@ -181,7 +185,8 @@ class Aggregate {
181185

182186
overallScore += Aggregate._convertToWeight(
183187
filteredAndRemappedResults[e],
184-
item.criteria[e]);
188+
item.criteria[e],
189+
e);
185190
});
186191

187192
return {

lighthouse-core/audits/time-to-interactive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ class TTIMetric extends Audit {
121121
// Grab this latency and try the threshold again
122122
currentLatency = estLatency;
123123
}
124-
const timeToInteractive = startTime.toFixed(1);
124+
const timeToInteractive = parseFloat(startTime.toFixed(1));
125125

126126
// Use the CDF of a log-normal distribution for scoring.
127127
// < 1200ms: score≈100
128128
// 5000ms: score=50
129129
// >= 15000ms: score≈0
130130
const distribution = TracingProcessor.getLogNormalDistribution(SCORING_MEDIAN,
131131
SCORING_POINT_OF_DIMINISHING_RETURNS);
132-
let score = 100 * distribution.computeComplementaryPercentile(timeToInteractive);
132+
let score = 100 * distribution.computeComplementaryPercentile(startTime);
133133

134134
// Clamp the score to 0 <= x <= 100.
135135
score = Math.min(100, score);

lighthouse-core/config/default.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"weight": 1
110110
},
111111
"time-to-interactive": {
112-
"value": 100,
112+
"rawValue": 100,
113113
"weight": 1
114114
},
115115
"scrolling-60fps": {

lighthouse-core/test/aggregator/aggregate.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ describe('Aggregate', () => {
125125
'Cannot remap: test already exists');
126126
});
127127

128-
it('returns a weight of zero for undefined inputs', () => {
129-
return assert.equal(Aggregate._convertToWeight(), 0);
128+
it('throws for undefined inputs', () => {
129+
return assert.throws(_ => Aggregate._convertToWeight(), 0);
130130
});
131131

132-
it('returns a weight of zero for undefined results', () => {
132+
it('throws for undefined results', () => {
133133
const expected = {
134134
rawValue: true,
135135
weight: 10
136136
};
137-
return assert.equal(Aggregate._convertToWeight(undefined, expected), 0);
137+
return assert.throws(_ => Aggregate._convertToWeight(undefined, expected));
138138
});
139139

140140
it('returns a weight of zero for undefined expectations', () => {
@@ -143,7 +143,7 @@ describe('Aggregate', () => {
143143
score: true,
144144
displayValue: ''
145145
};
146-
return assert.equal(Aggregate._convertToWeight(result, undefined), 0);
146+
return assert.throws(_ => Aggregate._convertToWeight(result, undefined));
147147
});
148148

149149
it('returns the correct weight for a boolean result', () => {
@@ -176,7 +176,7 @@ describe('Aggregate', () => {
176176
return assert.equal(Aggregate._convertToWeight(result, expected), 5);
177177
});
178178

179-
it('returns the a weight of zero if weight is missing from the expected', () => {
179+
it('throws if weight is missing from the expected', () => {
180180
const expected = {
181181
rawValue: 100
182182
};
@@ -187,7 +187,7 @@ describe('Aggregate', () => {
187187
displayValue: '50'
188188
};
189189

190-
return assert.equal(Aggregate._convertToWeight(result, expected), 0);
190+
return assert.throws(_ => Aggregate._convertToWeight(result, expected), 0);
191191
});
192192

193193
it('returns a weight of zero for other inputs', () => {
@@ -296,6 +296,45 @@ describe('Aggregate', () => {
296296
});
297297
});
298298

299+
it('throws when given a result containing no score property', () => {
300+
const items = [{
301+
criteria: {
302+
test: {
303+
rawValue: true,
304+
weight: 1
305+
}
306+
}
307+
}];
308+
309+
const results = [{
310+
name: 'test',
311+
value: 'should be rawValue',
312+
displayValue: ''
313+
}];
314+
const scored = true;
315+
316+
return assert.throws(_ => Aggregate.compare(results, items, scored));
317+
});
318+
319+
it('throws when given a criterion containing no rawValue property', () => {
320+
const items = [{
321+
criteria: {
322+
test: {
323+
weight: 1
324+
}
325+
}
326+
}];
327+
328+
const results = [{
329+
name: 'test',
330+
score: false,
331+
displayValue: ''
332+
}];
333+
const scored = true;
334+
335+
return assert.throws(_ => Aggregate.compare(results, items, scored));
336+
});
337+
299338
it('filters a set correctly', () => {
300339
const items = [{
301340
criteria: {

0 commit comments

Comments
 (0)