Skip to content

Commit

Permalink
core(oopifs): surface oopifs in audits
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Mar 29, 2019
1 parent bed02b4 commit 7186e26
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class OptimizedImages extends Gatherer {
/** @type {Set<string>} */
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions lighthouse-core/gather/gatherers/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ 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,
resourceSize: 7,
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',
Expand Down Expand Up @@ -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);
},
});

Expand All @@ -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));
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -200,15 +201,9 @@ describe('Optimized responses', () => {

// Change into SDK.networkRequest when examples are ready
function createNetworkRequests(traceData) {
debugger;
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;
});

Expand Down

0 comments on commit 7186e26

Please sign in to comment.