Skip to content

Commit

Permalink
add test for nonscored items on CLI printer
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Oct 11, 2016
1 parent 1c081c9 commit 1082ed3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
5 changes: 5 additions & 0 deletions lighthouse-cli/test/cli/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ describe('Printer', () => {
// Just check there's no HTML / JSON there.
assert.throws(_ => JSON.parse(prettyOutput));
assert.equal(/<!doctype/gim.test(prettyOutput), false);

const hasScoreOnNonScoredItem = /Using modern offline features.*?(0%|NaN)/.test(prettyOutput);
const hasAggregationPresent = prettyOutput.includes('Using modern offline features');
assert.equal(hasScoreOnNonScoredItem, false, 'non-scored item was scored');
assert.equal(hasAggregationPresent, true, 'non-scored aggregation item is not there');
});

it('creates HTML for results', () => {
Expand Down
34 changes: 34 additions & 0 deletions lighthouse-cli/test/fixtures/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@
"category": "JavaScript",
"description": "Page contains some content when its scripts are not available"
},
"appcache-manifest": {
"score": true,
"displayValue": "",
"rawValue": true,
"name": "appcache-manifest",
"category": "Offline",
"description": "Site is not using Application Cache",
"helpText": "Application Cache has been <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#offline\" target=\"_blank\">deprecated</a> by <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers\" target=\"_blank\">Service Workers</a>. Consider implementing an offline solution using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Cache\" target=\"_blank\">Cache Storage API</a>."
},
"no-websql": {
"score": true,
"displayValue": "",
"rawValue": true,
"name": "no-websql",
"category": "Offline",
"description": "Site is not using WebSQL DB.",
"helpText": "Web SQL Database is <a href=\"https://dev.w3.org/html5/webdatabase/\" target=\"_blank\">deprecated</a>. Consider implementing an offline solution using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB\" target=\"_blank\">IndexedDB</a>."
},
"first-meaningful-paint": {
"score": 100,
"displayValue": "615.8ms",
Expand Down Expand Up @@ -610,6 +628,22 @@
]
}
]
},
{
"name": "Do Better Web",
"description": "We've compiled some recommendations for modernizing your web app and avoiding performance pitfalls.",
"scored": false,
"categorizable": true,
"score": [
{
"overall": null,
"name": "Using modern offline features",
"subItems": [
"appcache-manifest",
"no-websql"
]
}
]
}
]
}
5 changes: 1 addition & 4 deletions lighthouse-core/aggregator/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ class Aggregate {
static _getTotalWeight(expected) {
const expectedNames = Object.keys(expected);
let totalWeight = expectedNames.reduce((last, e) => last + (expected[e].weight || 0), 0);
if (totalWeight === 0) {
totalWeight = 1;
}
return totalWeight;
}

Expand Down Expand Up @@ -160,7 +157,7 @@ class Aggregate {

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

// Step through each item in the expected results, and add them
// to the overall score and add each to the subItems list.
Expand Down
13 changes: 1 addition & 12 deletions lighthouse-core/test/aggregator/aggregate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,7 @@ describe('Aggregate', () => {
const a = {};

const weight = Aggregate._getTotalWeight(a);
return assert.equal(weight, 1);
});

it('returns a weight of at least 1', () => {
const a = {
x: {
weight: 0
}
};

const weight = Aggregate._getTotalWeight(a);
return assert.equal(weight, 1);
return assert.equal(weight, 0);
});

it('generates the correct total weight', () => {
Expand Down

0 comments on commit 1082ed3

Please sign in to comment.