From 8941853deef8c70add763789596ab94159d707c2 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Thu, 28 Mar 2019 21:23:16 -0700 Subject: [PATCH] core(oopifs): surface oopifs in audits --- .../gatherers/dobetterweb/optimized-images.js | 4 ++-- .../dobetterweb/response-compression.js | 3 --- lighthouse-core/gather/gatherers/scripts.js | 2 -- .../dobetterweb/response-compression-test.js | 22 +++++++------------ 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js index a9a533cb5e92..8671cd500a80 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js @@ -45,8 +45,8 @@ class OptimizedImages extends Gatherer { /** @type {Set} */ const seenUrls = new Set(); return networkRecords.reduce((prev, record) => { - // Skip records that we've seen before, never finished, or came from OOPIFs. - if (seenUrls.has(record.url) || !record.finished || record.sessionId) { + // Skip records that we've seen before or never finished + if (seenUrls.has(record.url) || !record.finished) { return prev; } diff --git a/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js b/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js index ed58dcb2698f..235845617a4e 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js @@ -40,9 +40,6 @@ class ResponseCompression extends Gatherer { const unoptimizedResponses = []; networkRecords.forEach(record => { - // Ignore records from OOPIFs - if (record.sessionId) return; - const mimeType = record.mimeType; const resourceType = record.resourceType || NetworkRequest.TYPES.Other; const resourceSize = record.resourceSize; diff --git a/lighthouse-core/gather/gatherers/scripts.js b/lighthouse-core/gather/gatherers/scripts.js index fa0969fb44aa..19c4c3dad77e 100644 --- a/lighthouse-core/gather/gatherers/scripts.js +++ b/lighthouse-core/gather/gatherers/scripts.js @@ -58,8 +58,6 @@ class Scripts extends Gatherer { } const scriptRecords = loadData.networkRecords - // Ignore records from OOPIFs - .filter(record => !record.sessionId) // Only get the content of script requests .filter(record => record.resourceType === NetworkRequest.TYPES.Script); diff --git a/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js b/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js index d885acf95254..3a7d24190d54 100644 --- a/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js +++ b/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js @@ -55,8 +55,9 @@ const traceData = { content: '1234567', finished: true, }, + // This is an OOPIF request { - url: 'http://google.com/index.json', + url: 'http://google.com/oopif.json', _statusCode: 200, mimeType: 'application/json', requestId: 27, @@ -64,9 +65,9 @@ const traceData = { transferSize: 8, resourceType: 'XHR', responseHeaders: [], - content: '1234567', + content: '12345678', finished: true, - sessionId: 'oopif', // ignore for being from oopif + sessionId: 'oopif', }, { url: 'http://google.com/index.json', @@ -125,7 +126,7 @@ describe('Optimized responses', () => { responseCompression = new ResponseCompression(); const driver = Object.assign({}, mockDriver, { getRequestContent(id) { - return Promise.resolve(traceData.networkRecords[id].content); + return Promise.resolve(traceData.networkRecords.find(rec => rec.requestId === id).content); }, }); @@ -138,7 +139,7 @@ describe('Optimized responses', () => { it('returns only text and non encoded responses', () => { return responseCompression.afterPass(options, createNetworkRequests(traceData)) .then(artifact => { - assert.equal(artifact.length, 2); + assert.equal(artifact.length, 3); assert.ok(/index\.css$/.test(artifact[0].url)); assert.ok(/index\.json$/.test(artifact[1].url)); }); @@ -147,7 +148,7 @@ describe('Optimized responses', () => { it('computes sizes', () => { return responseCompression.afterPass(options, createNetworkRequests(traceData)) .then(artifact => { - assert.equal(artifact.length, 2); + assert.equal(artifact.length, 3); assert.equal(artifact[0].resourceSize, 6); assert.equal(artifact[0].gzipSize, 26); }); @@ -157,7 +158,7 @@ describe('Optimized responses', () => { options.driver.getRequestContent = () => Promise.reject(new Error('Failed')); return responseCompression.afterPass(options, createNetworkRequests(traceData)) .then(artifact => { - assert.equal(artifact.length, 2); + assert.equal(artifact.length, 3); assert.equal(artifact[0].resourceSize, 6); assert.equal(artifact[0].gzipSize, undefined); }); @@ -201,14 +202,7 @@ describe('Optimized responses', () => { // Change into SDK.networkRequest when examples are ready function createNetworkRequests(traceData) { traceData.networkRecords = traceData.networkRecords.map(record => { - record.url = record.url; record.statusCode = record._statusCode; - record.mimeType = record.mimeType; - record.resourceSize = record.resourceSize; - record.transferSize = record.transferSize; - record.responseHeaders = record.responseHeaders; - record.requestId = record.requestId; - return record; });