-
Notifications
You must be signed in to change notification settings - Fork 9.6k
core(lightwallet): add resource-summary audit #8522
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
Changes from 1 commit
51d7a40
b1404da
7ba2fb2
f8e5177
fae0051
838060c
2ee8053
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,114 @@ | ||||||
| /** | ||||||
| * @license Copyright 2019 Google Inc. All Rights Reserved. | ||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||||||
| */ | ||||||
| 'use strict'; | ||||||
|
|
||||||
| const Audit = require('./audit.js'); | ||||||
| const NetworkRecords = require('../computed/network-records.js'); | ||||||
| const ComputedResourceSummary = require('../computed/resource-summary.js'); | ||||||
| const i18n = require('../lib/i18n/i18n.js'); | ||||||
| const MainResource = require('../computed/main-resource.js'); | ||||||
|
|
||||||
| const UIStrings = { | ||||||
| /** Imperative title of a Lighthouse audit that tells the user to minimize the size and quantity of resources used to load the page. */ | ||||||
| title: 'Keep request counts and transfer sizes small', | ||||||
| /** Description of a Lighthouse audit that tells the user that they can setup a budgets for the quantity and size of page resources. No character length limits. */ | ||||||
| description: 'To set budgets for the quantity and size of page resources,' + | ||||||
|
Collaborator
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. sorry if I already said this but are we gonna link this up to a doc? :)
Collaborator
Author
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 was planning on doing that in a separate PR once we know where that lives.
Contributor
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 also added it to #8331 in the lightwallet section |
||||||
| ' add a budget.json file.', | ||||||
| /** [ICU Syntax] Label for an audit identifying the number of requests and kilobytes used to load the page. */ | ||||||
| displayValue: `{requestCount, plural, =1 {1 request} other {# requests}}` + | ||||||
| ` • { byteCount, number, bytes } KB`, | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all resources loaded by a web page. */ | ||||||
| totalResourceType: 'Total', | ||||||
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all 'Document' resources loaded by a web page. */ | ||||||
| documentResourceType: 'Document', | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all 'Script' resources loaded by a web page. */ | ||||||
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| scriptResourceType: 'Script', | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all 'Stylesheet' resources loaded by a web page. */ | ||||||
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| stylesheetResourceType: 'Stylesheet', | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all 'Image' resources loaded by a web page */ | ||||||
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| imageResourceType: 'Image', | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all 'Media' resources loaded by a web page */ | ||||||
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| mediaResourceType: 'Media', | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all 'Font' resources loaded by a web page */ | ||||||
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| fontResourceType: 'Font', | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all resources loaded by a web page that don't fit into the categories of Document, Script, Stylesheet, Image, Media, & Font.*/ | ||||||
| otherResourceType: 'Other', | ||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all third-part resources loaded by a web page */ | ||||||
|
||||||
| /** Label for a row in a data table; entries will be the total number and byte size of all third-part resources loaded by a web page */ | |
| /** Label for a row in a data table; entries will be the total number and byte size of all third-party resources loaded by a web page. 'Third-party resources are items loaded from URLs that aren't controlled by the owner of the web page. */ |
khempenius marked this conversation as resolved.
Show resolved
Hide resolved
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
khempenius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * @license Copyright 2019 Google Inc. All Rights Reserved. | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
| */ | ||
| 'use strict'; | ||
|
|
||
| const ResourceSummaryAudit = require('../../audits/resource-summary.js'); | ||
| const assert = require('assert'); | ||
| const networkRecordsToDevtoolsLog = require('../network-records-to-devtools-log.js'); | ||
khempenius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /* eslint-env jest */ | ||
|
|
||
| describe('Performance: Resource summary audit', () => { | ||
| let artifacts; | ||
| let context; | ||
| beforeEach(() => { | ||
| context = {computedCache: new Map()}; | ||
|
|
||
| artifacts = { | ||
| devtoolsLogs: { | ||
| defaultPass: networkRecordsToDevtoolsLog([ | ||
| {url: 'http://example.com/file.html', resourceType: 'Document', transferSize: 30}, | ||
| {url: 'http://example.com/app.js', resourceType: 'Script', transferSize: 10}, | ||
| {url: 'http://third-party.com/script.js', resourceType: 'Script', transferSize: 50}, | ||
| {url: 'http://third-party.com/file.jpg', resourceType: 'Image', transferSize: 70}, | ||
| ])}, | ||
| URL: { requestedUrl: 'https://example.com', finalUrl: 'https://example.com' }, | ||
| }; | ||
| }); | ||
|
|
||
khempenius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it('includes all resource types, regardless of whether page contains them', () => { | ||
| return ResourceSummaryAudit.audit(artifacts, context).then(result => { | ||
| assert.equal(Object.keys(result.details.items).length, 9); | ||
| }); | ||
| }); | ||
|
|
||
| it('it displays "0" if there are no resources of that type', () => { | ||
| return ResourceSummaryAudit.audit(artifacts, context).then(result => { | ||
| const fontItem = result.details.items.find(item => item.resourceType === 'font'); | ||
| assert.equal(fontItem.count, 0); | ||
| assert.equal(fontItem.size, 0); | ||
| }); | ||
| }); | ||
|
|
||
| it('it sorts items by size (descending)', () => { | ||
| return ResourceSummaryAudit.audit(artifacts, context).then(result => { | ||
| const items = result.details.items; | ||
| assert.ok(items[0].size >= items[1].size); | ||
| assert.ok(items[1].size >= items[2].size); | ||
| assert.ok(items[2].size >= items[3].size); | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.