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 4 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
9 changes: 6 additions & 3 deletions lighthouse-core/gather/computed/network-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ class NetworkThroughput extends ComputedArtifact {
/**
* Computes the average throughput for the given records in bytes/second.
* Excludes data URI, failed or otherwise incomplete, and cached requests.
* Returns Infinity if there were no analyzable network records.
*
* @param {?Array<!WebInspector.NetworkRequest>} networkRecords
* @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 +37,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 @@ -57,11 +57,20 @@ describe('Byte efficiency base audit', () => {
assert.ok(failingResult.score < 50, 'scores failing wastedMs');
});

it('should throw on invalid network throughput', () => {
assert.throws(() => {
ByteEfficiencyAudit.createAuditResult({
headings: [{key: 'value', text: 'Label'}],
results: [{wastedBytes: 350, totalBytes: 700, wastedPercent: 50}],
}, Infinity);
});
});

it('should populate Kb', () => {
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 +94,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
15 changes: 15 additions & 0 deletions lighthouse-core/test/report/v2/renderer/category-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ describe('CategoryRenderer', () => {
assert.ok(hintSparklineElement.title, 'did not render tooltip');
});

it('renders the performance hints with a debug string', () => {
const auditWithDebug = {
score: 0,
group: 'perf-hint',
result: {rawValue: 100, debugString: 'Yikes!', description: 'Bug'},
};

const fakeAudits = category.audits.concat(auditWithDebug);
const fakeCategory = Object.assign({}, category, {audits: fakeAudits});
const categoryDOM = renderer.render(fakeCategory, sampleResults.reportGroups);

const debugEl = categoryDOM.querySelector('.lh-perf-hint .lh-debug');
assert.ok(debugEl, 'did not render debug');
});

it('renders the performance hints with no extended info', () => {
const buggyAudit = {
score: 0,
Expand Down