-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: include finished state on hidden network-requests audit #10530
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ class NetworkRequests extends Audit { | |
url: URL.elideDataURI(record.url), | ||
startTime: timeToMs(record.startTime), | ||
endTime: timeToMs(record.endTime), | ||
finished: record.finished, | ||
transferSize: record.transferSize, | ||
resourceSize: record.resourceSize, | ||
statusCode: record.statusCode, | ||
|
@@ -62,6 +63,7 @@ class NetworkRequests extends Audit { | |
}; | ||
}); | ||
|
||
// NOTE(i18n): this audit is only for debug info in the LHR and does not appear in the report. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the other options are:
I'm fine with any of these. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like what we have here, continue to leave it un-i18n'd 👍 |
||
/** @type {LH.Audit.Details.Table['headings']} */ | ||
const headings = [ | ||
{key: 'url', itemType: 'url', text: 'URL'}, | ||
|
@@ -72,7 +74,7 @@ class NetworkRequests extends Audit { | |
itemType: 'bytes', | ||
displayUnit: 'kb', | ||
granularity: 1, | ||
text: 'Transfer Size', // TODO(exterkamp): i18n this when i18n'ing this file | ||
text: 'Transfer Size', | ||
}, | ||
{ | ||
key: 'resourceSize', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,28 +6,50 @@ | |
'use strict'; | ||
|
||
const NetworkRequests = require('../../audits/network-requests.js'); | ||
const assert = require('assert'); | ||
const networkRecordsToDevtoolsLog = require('../network-records-to-devtools-log.js'); | ||
|
||
const acceptableDevToolsLog = require('../fixtures/traces/progressive-app-m60.devtools.log.json'); | ||
const cutoffLoadDevtoolsLog = require('../fixtures/traces/cutoff-load-m83.devtoolslog.json'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. introduced a new test devtoolsLog/trace of a load of the report viewer, devtools throttling, cut off at 1500ms (via Seems handy to have a kind of gross load like that with relatively small fixture file sizes. |
||
|
||
/* eslint-env jest */ | ||
describe('Network requests audit', () => { | ||
it('should return network requests', () => { | ||
it('should report finished and unfinished network requests', async () => { | ||
const artifacts = { | ||
devtoolsLogs: { | ||
[NetworkRequests.DEFAULT_PASS]: acceptableDevToolsLog, | ||
[NetworkRequests.DEFAULT_PASS]: cutoffLoadDevtoolsLog, | ||
}, | ||
}; | ||
|
||
return NetworkRequests.audit(artifacts, {computedCache: new Map()}).then(output => { | ||
assert.equal(output.score, 1); | ||
assert.equal(output.details.items.length, 66); | ||
assert.equal(output.details.items[0].url, 'https://pwa.rocks/'); | ||
assert.equal(output.details.items[0].startTime, 0); | ||
assert.equal(Math.round(output.details.items[0].endTime), 280); | ||
assert.equal(output.details.items[0].statusCode, 200); | ||
assert.equal(output.details.items[0].transferSize, 5368); | ||
const output = await NetworkRequests.audit(artifacts, {computedCache: new Map()}); | ||
|
||
expect(output.details.items[0]).toMatchObject({ | ||
startTime: 0, | ||
endTime: expect.toBeApproximately(701, 0), | ||
finished: true, | ||
transferSize: 11358, | ||
resourceSize: 39471, | ||
statusCode: 200, | ||
mimeType: 'text/html', | ||
resourceType: 'Document', | ||
}); | ||
expect(output.details.items[2]).toMatchObject({ | ||
startTime: expect.toBeApproximately(711, 0), | ||
endTime: expect.toBeApproximately(1289, 0), | ||
finished: false, | ||
transferSize: 26441, | ||
resourceSize: 0, | ||
statusCode: 200, | ||
mimeType: 'image/png', | ||
resourceType: 'Image', | ||
}); | ||
expect(output.details.items[5]).toMatchObject({ | ||
startTime: expect.toBeApproximately(717, 0), | ||
endTime: expect.toBeApproximately(1296, 0), | ||
finished: false, | ||
transferSize: 58571, | ||
resourceSize: 0, | ||
statusCode: 200, | ||
mimeType: 'application/javascript', | ||
resourceType: 'Script', | ||
}); | ||
}); | ||
|
||
|
@@ -43,9 +65,15 @@ describe('Network requests audit', () => { | |
}, | ||
}; | ||
const output = await NetworkRequests.audit(artifacts, {computedCache: new Map()}); | ||
assert.equal(output.details.items[0].startTime, 0); | ||
assert.equal(output.details.items[0].endTime, 500); | ||
assert.equal(output.details.items[1].startTime, 500); | ||
assert.equal(output.details.items[1].endTime, undefined); | ||
|
||
expect(output.details.items).toMatchObject([{ | ||
startTime: 0, | ||
endTime: 500, | ||
finished: true, | ||
}, { | ||
startTime: 500, | ||
endTime: undefined, | ||
finished: true, | ||
}]); | ||
}); | ||
}); |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
/* eslint-env jest */ | ||
|
||
const i18n = require('../lib/i18n/i18n.js'); | ||
const {default: {toBeCloseTo}} = require('expect/build/matchers.js'); | ||
|
||
expect.extend({ | ||
toBeDisplayString(received, expected) { | ||
|
@@ -27,4 +28,16 @@ expect.extend({ | |
|
||
return {actual, message, pass}; | ||
}, | ||
|
||
// Expose toBeCloseTo() so it can be used as an asymmetric matcher. | ||
toBeApproximately(...args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's really dumb you can't use |
||
// If called asymmetrically, a fake matcher `this` object needs to be passed | ||
// in (see https://github.com/facebook/jest/issues/8295). There's no effect | ||
// because it's only used for the printing of full failures, which isn't | ||
// done for asymmetric matchers anyways. | ||
const thisObj = (this && this.utils) ? this : | ||
{isNot: false, promise: ''}; | ||
|
||
return toBeCloseTo.call(thisObj, ...args); | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's nice to have smoke coverage, but clearly we're not too worried about covering this audit's entire output given the assertions here (and two other places where we assert just
details.items.length
), so this could be removed if it feels excessiveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of asserting these somewhere so seems fine 🤷♂