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

Sometimes err.url is undefined. so It must has protect code. #893

Merged
merged 3 commits into from
Nov 4, 2016
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
5 changes: 3 additions & 2 deletions lighthouse-core/audits/dobetterweb/no-datenow.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ class NoDateNowAudit extends Audit {
const pageHost = url.parse(artifacts.URL.finalUrl).host;
// Filter usage from other hosts.
const results = artifacts.DateNowUse.usage.filter(err => {
return url.parse(err.url).host === pageHost;
return err.url ? url.parse(err.url).host === pageHost : true;
}).map(err => {
return Object.assign({
label: `line: ${err.line}, col: ${err.col}`
label: `line: ${err.line}, col: ${err.col}`,
url: err.url || ''
}, err);
});

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/dobetterweb/no-mutation-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NoMutationEventsAudit extends Audit {

const results = listeners.filter(loc => {
const isMutationEvent = this.MUTATION_EVENTS.indexOf(loc.type) !== -1;
const sameHost = url.parse(loc.url).host === pageHost;
const sameHost = loc.url ? url.parse(loc.url).host === pageHost : true;
return sameHost && isMutationEvent;
}).map(loc => {
const handler = loc.handler ? loc.handler.description : '...';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PassiveEventsAudit extends Audit {
const isScrollBlocking = this.SCROLL_BLOCKING_EVENTS.indexOf(loc.type) !== -1;
const mentionsPreventDefault = loc.handler.description.match(
/\.preventDefault\(\s*\)/g);
const sameHost = url.parse(loc.url).host === pageHost;
const sameHost = loc.url ? url.parse(loc.url).host === pageHost : true;
return sameHost && isScrollBlocking && !loc.passive &&
!mentionsPreventDefault;
}).map(loc => {
Expand Down
17 changes: 17 additions & 0 deletions lighthouse-core/test/audits/dobetterweb/no-datenow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,21 @@ describe('Page does not use Date.now()', () => {
assert.equal(auditResult.rawValue, false);
assert.equal(auditResult.extendedInfo.value.length, 2);
});

it('fails when usage hasn`t url', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe "only passes when has url property"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE!

const auditResult = DateNowUseAudit.audit({
DateNowUse: {
usage: [
{line: 1, col: 1},
{url: 'http://example.com/two', line: 10, col: 1},
{url: 'http://example2.com/two', line: 2, col: 22}
]
},
URL: {finalUrl: URL},
});

assert.equal(auditResult.rawValue, false);
assert.ok(auditResult.extendedInfo.value[0].url === '');
assert.equal(auditResult.extendedInfo.value.length, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check that extendedInfo.value has a url and is what you expect? From the first assert, it looks like extendedInfo.value will be the first to values in DateNowUse.usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ebidel
Thank you. I have misunderstood spec. 😭

});
});
10 changes: 10 additions & 0 deletions lighthouse-core/test/audits/dobetterweb/no-mutation-events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ describe('Page does not use mutation events', () => {
assert.equal(auditResult.rawValue, false);
assert.equal(auditResult.extendedInfo.value.length, 3);
});

it('fails when listener hasn`t url', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

fails when listener is missing a url property

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE!

const auditResult = NoMutationEventsAudit.audit({
PageLevelEventListeners: fixtureData,
URL: {finalUrl: URL},
});
assert.equal(auditResult.rawValue, false);
assert.ok(auditResult.extendedInfo.value[1].url === undefined);
assert.equal(auditResult.extendedInfo.value.length, 3);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ describe('Page uses passive events listeners where applicable', () => {
assert.equal(auditResult.rawValue, true);
assert.equal(auditResult.extendedInfo.value.length, 0);
});

it('fails when listener hasn`t url', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

fails when listener is missing a url property

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE!

const auditResult = PassiveEventsAudit.audit({
PageLevelEventListeners: fixtureData,
URL: {finalUrl: URL},
});
assert.equal(auditResult.rawValue, false);
assert.ok(auditResult.extendedInfo.value[1].url === undefined);
assert.equal(auditResult.extendedInfo.value.length, 5);
});
});
2 changes: 0 additions & 2 deletions lighthouse-core/test/fixtures/page-level-event-listeners.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
"description":"function remove() { [Command Line API] }",
"objectId":"{\"injectedScriptId\":3,\"id\":13}"
},
"url":"https://example.com",
"startLine":44,
"startColumn":8,
"endLine":194,
Expand Down Expand Up @@ -368,7 +367,6 @@
"description":"function remove() { [Command Line API] }",
"objectId":"{\"injectedScriptId\":3,\"id\":29}"
},
"url":"https://example.com",
"startLine":44,
"startColumn":8,
"endLine":194,
Expand Down