forked from GoogleChrome/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf-preload.js
138 lines (133 loc) · 5.05 KB
/
perf-preload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* @license Copyright 2017 The Lighthouse Authors. 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.
*/
/** @type {LH.Config} */
const config = {
extends: 'lighthouse:default',
settings: {
throttlingMethod: 'devtools',
// preload-fonts isn't a performance audit, but can easily leverage the font
// webpages present here, hence the inclusion of 'best-practices'.
onlyCategories: ['performance', 'best-practices'],
// BF cache will request the page again, initiating additional network requests.
// Disable the audit so we only detect requests from the normal page load.
skipAudits: ['bf-cache'],
// A mixture of under, over, and meeting budget to exercise all paths.
budgets: [{
path: '/',
resourceCounts: [
{resourceType: 'total', budget: 8},
{resourceType: 'stylesheet', budget: 1}, // meets budget
{resourceType: 'image', budget: 1},
{resourceType: 'media', budget: 0},
{resourceType: 'font', budget: 2}, // meets budget
{resourceType: 'script', budget: 1},
{resourceType: 'document', budget: 0},
{resourceType: 'other', budget: 1},
{resourceType: 'third-party', budget: 0},
],
resourceSizes: [
{resourceType: 'total', budget: 100},
{resourceType: 'stylesheet', budget: 0},
{resourceType: 'image', budget: 30}, // meets budget
{resourceType: 'media', budget: 0},
{resourceType: 'font', budget: 75},
{resourceType: 'script', budget: 30},
{resourceType: 'document', budget: 1},
{resourceType: 'other', budget: 2}, // meets budget
{resourceType: 'third-party', budget: 0},
],
timings: [
{metric: 'first-contentful-paint', budget: 2000},
{metric: 'interactive', budget: 2000},
{metric: 'first-meaningful-paint', budget: 2000},
{metric: 'max-potential-fid', budget: 2000},
],
}],
},
};
/**
* @type {Smokehouse.ExpectedRunnerResult}
* Expected Lighthouse audit values for preload tests.
*/
const expectations = {
artifacts: {
LinkElements: {
_includes: [{
rel: 'preload',
href: 'http://localhost:10200/perf/level-2.js?warning&delay=500',
hrefRaw: '/perf/level-2.js?warning&delay=500',
hreflang: '',
as: 'script',
crossOrigin: 'use-credentials',
source: 'head',
fetchPriority: 'high',
}],
},
},
networkRequests: {
// DevTools loads the page three times, so this request count will not be accurate.
_excludeRunner: 'devtools',
// 8 requests made for normal page testing.
// 1 extra request made because stylesheets are evicted from the cache by the time DT opens.
length: 9,
},
lhr: {
requestedUrl: 'http://localhost:10200/preload.html',
finalDisplayedUrl: 'http://localhost:10200/preload.html',
audits: {
'speed-index': {
score: '>=0.80', // primarily just making sure it didn't fail/go crazy, specific value isn't that important
},
'first-meaningful-paint': {
score: '>=0.90', // primarily just making sure it didn't fail/go crazy, specific value isn't that important
},
'interactive': {
score: '>=0.90', // primarily just making sure it didn't fail/go crazy, specific value isn't that important
},
'server-response-time': {
// Can be flaky, so test float numericValue instead of binary score
numericValue: '<1000',
},
'network-requests': {
details: {
items: {
_includes: [
{url: 'http://localhost:10200/preload.html', isLinkPreload: undefined, experimentalFromMainFrame: true},
{url: 'http://localhost:10200/perf/level-2.js?warning&delay=500', isLinkPreload: true, experimentalFromMainFrame: true},
{url: 'http://localhost:10200/perf/preload_tester.js', isLinkPreload: undefined, experimentalFromMainFrame: true},
],
length: '>5',
},
},
},
'uses-rel-preload': {
scoreDisplayMode: 'notApplicable',
// Disabled for now, see https://github.com/GoogleChrome/lighthouse/issues/11960
// score: '<1',
// numericValue: '>500',
// warnings: {
// 0: /level-2.*warning/,
// length: 1,
// },
// details: {
// items: {
// length: 1,
// },
// },
},
'uses-rel-preconnect': {
score: 1,
warnings: [/localhost:10503/],
},
},
},
};
export default {
id: 'perf-preload',
expectations,
config,
runSerially: true,
};