Skip to content

Commit

Permalink
tempoary: cast boolean scores when creating arithmetic mean score.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Mar 9, 2018
1 parent e4784a2 commit fddb987
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lighthouse-core/scoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ class ReportScoring {
static arithmeticMean(items) {
const results = items.reduce(
(result, item) => {
const score = Number(item.score) || 0;
// HACK. remove this in the next PR
// Srsly. The score inconsitency has been very bad.
let itemScore = item.score;
if (typeof item.score === 'boolean') {
itemScore = item.score ? 100 : 0;
}

const score = Number(itemScore) || 0;
const weight = Number(item.weight) || 0;
return {
weight: result.weight + weight,
Expand Down Expand Up @@ -70,7 +77,7 @@ class ReportScoring {
const categoryScore = ReportScoring.arithmeticMean(scores);
// mutate config.categories[].score
category.score = categoryScore;
};
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('ReportRenderer V2', () => {
const container = renderer._dom._document.body;
const originalResults = JSON.parse(JSON.stringify(sampleResults));
renderer.renderReport(sampleResults, container);
assert.deepStrictEqual(sampleResults, originalResults)
assert.deepStrictEqual(sampleResults, originalResults);
}).timeout(2000);

it('renders a left nav', () => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ describe('Runner', () => {
assert.equal(results.initialUrl, url);
assert.equal(gatherRunnerRunSpy.called, true, 'GatherRunner.run was not called');
assert.equal(results.audits['content-width'].name, 'content-width');
assert.equal(results.audits['content-width'].score, 100);
assert.equal(results.audits['content-width'].score, true);
assert.equal(results.reportCategories[0].score, 100);
assert.equal(results.reportCategories[0].audits[0].id, 'content-width');
});
Expand Down

0 comments on commit fddb987

Please sign in to comment.