File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,15 @@ class NoDateNowAudit extends Audit {
6363
6464 const pageHost = new URL ( artifacts . URL . finalUrl ) . host ;
6565 // Filter usage from other hosts and keep eval'd code.
66+ // If there is no .url in the violation, include it in the results because
67+ // we cannot determine if it was from the user's page or a third party.
68+ // TODO: better extendedInfo for violations with no URL.
69+ // https://github.com/GoogleChrome/lighthouse/issues/1263
6670 const results = artifacts . DateNowUse . usage . filter ( err => {
67- return err . isEval ? ! ! err . url : new URL ( err . url ) . host === pageHost ;
71+ if ( err . isEval ) {
72+ return ! ! err . url ;
73+ }
74+ return err . url ? new URL ( err . url ) . host === pageHost : true ;
6875 } ) . map ( err => {
6976 return Object . assign ( {
7077 label : `line: ${ err . line } , col: ${ err . col } ` ,
Original file line number Diff line number Diff line change @@ -99,4 +99,19 @@ describe('Page does not use Date.now()', () => {
9999 assert . equal ( auditResult . rawValue , false ) ;
100100 assert . equal ( auditResult . extendedInfo . value . length , 3 ) ;
101101 } ) ;
102+
103+ it ( 'includes results when there is no .url' , ( ) => {
104+ const auditResult = DateNowUseAudit . audit ( {
105+ DateNowUse : {
106+ usage : [
107+ { line : 10 , col : 1 } ,
108+ { line : 2 , col : 22 }
109+ ]
110+ } ,
111+ URL : { finalUrl : URL } ,
112+ } ) ;
113+
114+ assert . equal ( auditResult . rawValue , false ) ;
115+ assert . equal ( auditResult . extendedInfo . value . length , 2 ) ;
116+ } ) ;
102117} ) ;
You can’t perform that action at this time.
0 commit comments