From 1edb38d2bb519d61b51098f1396b7615a3b50659 Mon Sep 17 00:00:00 2001 From: Eric Bidelman Date: Fri, 23 Sep 2016 17:41:58 -0700 Subject: [PATCH] Feedback --- lighthouse-core/audits/dobetterweb/uses-http2.js | 8 +++++--- lighthouse-core/formatters/url-list.js | 7 ++++++- .../gather/gatherers/same-origin-resources.js | 9 +++------ .../test/audits/dobetterweb/uses-http2-test.js | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lighthouse-core/audits/dobetterweb/uses-http2.js b/lighthouse-core/audits/dobetterweb/uses-http2.js index 6e0f4f62924b..bab6f6b30d89 100644 --- a/lighthouse-core/audits/dobetterweb/uses-http2.js +++ b/lighthouse-core/audits/dobetterweb/uses-http2.js @@ -34,8 +34,8 @@ class UsesHTTP2Audit extends Audit { return { category: 'Performance', name: 'uses-http2', - description: 'Site resources use HTTP/2', - helpText: 'See HTTP2 FAQ.', + description: 'Site uses HTTP/2 for its own resources', + helpText: 'h2 offers many benefits over its predecessor HTTP/1.1: binary, multiplexing, server push, etc. See this FAQ for more information.', requiredArtifacts: ['SameOriginResources'] }; } @@ -53,7 +53,9 @@ class UsesHTTP2Audit extends Audit { }); } - // Filter the non http/2 resources. + console.log(artifacts.SameOriginResources.map(r => r.protocol)) + + // Filter the non h2 resources. const resources = artifacts.SameOriginResources.filter(record => { return /HTTP\/[01][\.\d]?/i.test(record.protocol); }); diff --git a/lighthouse-core/formatters/url-list.js b/lighthouse-core/formatters/url-list.js index 14378dbdcbe6..e5b66c86370e 100644 --- a/lighthouse-core/formatters/url-list.js +++ b/lighthouse-core/formatters/url-list.js @@ -30,7 +30,12 @@ class UrlList extends Formatter { if (!Array.isArray(resources)) { return ''; } - // TODO + + let output = ''; + resources.forEach(resource => { + output += ` ${resource.url} (${resource.protocol})\n`; + }); + return output; }; case 'html': diff --git a/lighthouse-core/gather/gatherers/same-origin-resources.js b/lighthouse-core/gather/gatherers/same-origin-resources.js index d5be54d5177e..442329a9386b 100644 --- a/lighthouse-core/gather/gatherers/same-origin-resources.js +++ b/lighthouse-core/gather/gatherers/same-origin-resources.js @@ -27,15 +27,12 @@ class SameOriginResources extends Gatherer { const initialHost = url.parse(options.initialUrl).host; // Find requests that are on the same origin as the page. - const results = tracingData.networkRecords.reduce((prev, record) => { + const results = tracingData.networkRecords.filter(record => { const requestHost = url.parse(record.url).host; const sameOrigin = requestHost === finalHost || requestHost === initialHost; - if (sameOrigin) { - prev.push(record); - } - return prev; - }, []); + return sameOrigin; + }); this.artifact = results; } diff --git a/lighthouse-core/test/audits/dobetterweb/uses-http2-test.js b/lighthouse-core/test/audits/dobetterweb/uses-http2-test.js index 303f5c2ab1ea..4c3cb61599d1 100644 --- a/lighthouse-core/test/audits/dobetterweb/uses-http2-test.js +++ b/lighthouse-core/test/audits/dobetterweb/uses-http2-test.js @@ -41,8 +41,8 @@ describe('Resources are fetched over http/2', () => { it('passes when all resources were requested via http/2', () => { const auditResult = UsesHTTP2Audit.audit({ SameOriginResources: [ - {url: 'http://example.com/one', protocol: 'http/2'}, - {url: 'http://example.com/two', protocol: 'http/2.0'} + {url: 'http://example.com/one', protocol: 'h2'}, + {url: 'http://example.com/two', protocol: 'h2'} ] }); assert.equal(auditResult.rawValue, true);