Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better debug message for missing network times #2451

Merged
merged 5 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class UnusedBytes extends Audit {
* @return {!AuditResult}
*/
static createAuditResult(result, networkThroughput) {
if (!Number.isFinite(networkThroughput) && result.results.length) {
throw new Error('Invalid network timing information');
}

const debugString = result.debugString;
const results = result.results
.map(item => {
Expand Down
8 changes: 5 additions & 3 deletions lighthouse-core/gather/computed/network-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class NetworkThroughput extends ComputedArtifact {
* @return {number}
*/
compute_(networkRecords) {
if (!networkRecords || !networkRecords.length) {
return 0;
}
networkRecords = networkRecords || [];

let totalBytes = 0;
const timeBoundaries = networkRecords.reduce((boundaries, record) => {
Expand All @@ -38,6 +36,10 @@ class NetworkThroughput extends ComputedArtifact {
return boundaries;
}, []).sort((a, b) => a.time - b.time);

if (!timeBoundaries.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document this in the jsdoc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return Infinity;
}

let inflight = 0;
let currentStart = 0;
let totalDuration = 0;
Expand Down
6 changes: 6 additions & 0 deletions lighthouse-core/report/v2/renderer/category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ class CategoryRenderer {
const descriptionEl = this._dom.createChildOf(element, 'div', 'lh-perf-hint__description');
descriptionEl.appendChild(this._dom.convertMarkdownLinkSnippets(audit.result.helpText));

if (audit.result.debugString) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this adding that wasn't there before? Not clear from the screenshot

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was, but not if it didn't completely fail (this was sort of drive by, there are other debugStrings that can be set)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test now for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was, but not if it didn't completely fail

it was...what? :P

const debugStrEl = this._dom.createChildOf(element, 'div', 'lh-debug');
debugStrEl.textContent = audit.result.debugString;
element.open = true;
}

if (audit.result.details) {
element.appendChild(this._detailsRenderer.render(audit.result.details));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Byte efficiency base audit', () => {
const result = ByteEfficiencyAudit.createAuditResult({
headings: [{key: 'value', text: 'Label'}],
results: [{wastedBytes: 2048, totalBytes: 4096, wastedPercent: 50}],
});
}, 1000);

assert.equal(result.extendedInfo.value.results[0].wastedKb, '2 KB');
assert.equal(result.extendedInfo.value.results[0].totalKb, '4 KB');
Expand All @@ -85,7 +85,7 @@ describe('Byte efficiency base audit', () => {
{wastedBytes: 450, totalBytes: 1000, wastedPercent: 50},
{wastedBytes: 400, totalBytes: 450, wastedPercent: 50},
],
});
}, 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need new tests, too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


assert.equal(result.extendedInfo.value.results[0].wastedBytes, 450);
assert.equal(result.extendedInfo.value.results[1].wastedBytes, 400);
Expand Down