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: critical request chains error on empty #1620

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions lighthouse-core/audits/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class CriticalRequestChains extends Audit {
}

// Account for initial navigation
const initialNavigationKey = Object.keys(chains)[0];
const initialNavChildren = chains[initialNavigationKey].children;
const initialNavKey = Object.keys(chains)[0];
const initialNavChildren = initialNavKey && chains[initialNavKey].children;
if (initialNavChildren && Object.keys(initialNavChildren).length > 0) {
walk(initialNavChildren, 0);
}
Expand Down
9 changes: 9 additions & 0 deletions lighthouse-core/test/audits/critical-request-chains-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const PASSING_REQUEST_CHAIN = {
},
};

const EMPTY_REQUEST_CHAIN = {};

const mockArtifacts = (mockChain) => {
return {
networkRecords: {
Expand Down Expand Up @@ -119,4 +121,11 @@ describe('Performance: critical-request-chains audit', () => {
assert.equal(output.score, true);
});
});

it('calculates the correct chain result for empty example', () => {
return Audit.audit(mockArtifacts(EMPTY_REQUEST_CHAIN)).then(output => {
assert.equal(output.displayValue, 0);
assert.equal(output.score, true);
});
});
});