Skip to content

Commit

Permalink
fix(cli): Don't report scores on nonscored items
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Oct 11, 2016
1 parent fde5452 commit 1c081c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lighthouse-cli/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function formatScore(score, suffix) {
if (typeof score !== 'number') {
return `${purple}${score}${reset}`;
}

let colorChoice = red;
if (score > 45) {
colorChoice = yellow;
Expand Down Expand Up @@ -123,7 +124,7 @@ function createOutput(results, outputMode) {
let score = (item.overall * 100).toFixed(0);

if (item.name) {
output += `${bold}${item.name}${reset}: ${formatScore(Number(score), '%')}\n`;
output += `${bold}${item.name}${reset}: ${item.scored ? formatScore(score, '%') : ''}\n`;
}

item.subItems.forEach(subitem => {
Expand Down
16 changes: 10 additions & 6 deletions lighthouse-core/aggregator/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ class Aggregate {
*/
static _getTotalWeight(expected) {
const expectedNames = Object.keys(expected);
let weight = expectedNames.reduce((last, e) => last + expected[e].weight, 0);
if (weight === 0) {
weight = 1;
let totalWeight = expectedNames.reduce((last, e) => last + (expected[e].weight || 0), 0);
if (totalWeight === 0) {
totalWeight = 1;
}

return weight;
return totalWeight;
}

/**
Expand Down Expand Up @@ -158,9 +157,10 @@ class Aggregate {
Aggregate._remapResultsByName(
Aggregate._filterResultsByAuditNames(results, item.audits)
);
const maxScore = Aggregate._getTotalWeight(item.audits);

const subItems = [];
let overallScore = 0;
let maxScore = 0;

// Step through each item in the expected results, and add them
// to the overall score and add each to the subItems list.
Expand Down Expand Up @@ -197,6 +197,10 @@ class Aggregate {
e);
});

if (aggregationIsScored) {
maxScore = Aggregate._getTotalWeight(item.audits);
}

return {
overall: (overallScore / maxScore),
name: item.name,
Expand Down

0 comments on commit 1c081c9

Please sign in to comment.