Skip to content

Commit

Permalink
handle Date.now uses with call site URL (GoogleChrome#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel authored and andrewrota committed Jan 13, 2017
1 parent fb045b3 commit c9492ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lighthouse-core/audits/dobetterweb/no-datenow.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ class NoDateNowAudit extends Audit {

const pageHost = new URL(artifacts.URL.finalUrl).host;
// Filter usage from other hosts and keep eval'd code.
// If there is no .url in the violation, include it in the results because
// we cannot determine if it was from the user's page or a third party.
// TODO: better extendedInfo for violations with no URL.
// https://github.com/GoogleChrome/lighthouse/issues/1263
const results = artifacts.DateNowUse.usage.filter(err => {
return err.isEval ? !!err.url : new URL(err.url).host === pageHost;
if (err.isEval) {
return !!err.url;
}
return err.url ? new URL(err.url).host === pageHost : true;
}).map(err => {
return Object.assign({
label: `line: ${err.line}, col: ${err.col}`,
Expand Down
15 changes: 15 additions & 0 deletions lighthouse-core/test/audits/dobetterweb/no-datenow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,19 @@ describe('Page does not use Date.now()', () => {
assert.equal(auditResult.rawValue, false);
assert.equal(auditResult.extendedInfo.value.length, 3);
});

it('includes results when there is no .url', () => {
const auditResult = DateNowUseAudit.audit({
DateNowUse: {
usage: [
{line: 10, col: 1},
{line: 2, col: 22}
]
},
URL: {finalUrl: URL},
});

assert.equal(auditResult.rawValue, false);
assert.equal(auditResult.extendedInfo.value.length, 2);
});
});

0 comments on commit c9492ba

Please sign in to comment.