lighthouse 9.5.0-dev.20220618 → 9.5.0-dev.20220621
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`getAssertionReport works (trivial failing) 1`] = `
|
|
4
|
+
"X difference at cumulative-layout-shift audit.details.items.length
|
|
5
|
+
expected: []
|
|
6
|
+
found: [{\\"cumulativeLayoutShiftMainFrame\\":0.13570762803819444,\\"totalCumulativeLayoutShift\\":0.13570762803819444}]
|
|
7
|
+
|
|
8
|
+
found result:
|
|
9
|
+
{
|
|
10
|
+
\\"id\\": \\"cumulative-layout-shift\\",
|
|
11
|
+
\\"title\\": \\"Cumulative Layout Shift\\",
|
|
12
|
+
\\"description\\": \\"Cumulative Layout Shift measures the movement of visible elements within the viewport. [Learn more](https://web.dev/cls/).\\",
|
|
13
|
+
\\"score\\": 0.8,
|
|
14
|
+
\\"scoreDisplayMode\\": \\"numeric\\",
|
|
15
|
+
\\"numericValue\\": 0.13570762803819444,
|
|
16
|
+
\\"numericUnit\\": \\"unitless\\",
|
|
17
|
+
\\"displayValue\\": \\"0.136\\",
|
|
18
|
+
\\"details\\": {
|
|
19
|
+
\\"type\\": \\"debugdata\\",
|
|
20
|
+
\\"items\\": [
|
|
21
|
+
{
|
|
22
|
+
\\"cumulativeLayoutShiftMainFrame\\": 0.13570762803819444,
|
|
23
|
+
\\"totalCumulativeLayoutShift\\": 0.13570762803819444
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}"
|
|
28
|
+
`;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2022 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* 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
|
|
4
|
+
* 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.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-control-regex */
|
|
8
|
+
|
|
9
|
+
import {findDifference, getAssertionReport} from './report-assert.js';
|
|
10
|
+
import {readJson} from '../../../root.js';
|
|
11
|
+
|
|
12
|
+
describe('findDifference', () => {
|
|
13
|
+
const testCases = {
|
|
14
|
+
'works (trivial passing)': {
|
|
15
|
+
actual: {},
|
|
16
|
+
expected: {},
|
|
17
|
+
diff: null,
|
|
18
|
+
},
|
|
19
|
+
'works (trivial fail)': {
|
|
20
|
+
actual: {},
|
|
21
|
+
expected: {a: 1},
|
|
22
|
+
diff: {path: '.a', actual: undefined, expected: 1},
|
|
23
|
+
},
|
|
24
|
+
'works (trivial fail, nested)': {
|
|
25
|
+
actual: {a: {b: 2}},
|
|
26
|
+
expected: {a: {b: 1}},
|
|
27
|
+
diff: {path: '.a.b', actual: 2, expected: 1},
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
'range (1)': {
|
|
31
|
+
actual: {duration: 100},
|
|
32
|
+
expected: {duration: '>=100'},
|
|
33
|
+
diff: null,
|
|
34
|
+
},
|
|
35
|
+
'range (2)': {
|
|
36
|
+
actual: {},
|
|
37
|
+
expected: {duration: '>=100'},
|
|
38
|
+
diff: {path: '.duration', actual: undefined, expected: '>=100'},
|
|
39
|
+
},
|
|
40
|
+
'range (3)': {
|
|
41
|
+
actual: {duration: 100},
|
|
42
|
+
expected: {duration: '>100'},
|
|
43
|
+
diff: {path: '.duration', actual: 100, expected: '>100'},
|
|
44
|
+
},
|
|
45
|
+
'range (4)': {
|
|
46
|
+
actual: {duration: 100},
|
|
47
|
+
expected: {duration: '<100'},
|
|
48
|
+
diff: {path: '.duration', actual: 100, expected: '<100'},
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
'array (1)': {
|
|
52
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
53
|
+
expected: {prices: {length: 6}},
|
|
54
|
+
diff: null,
|
|
55
|
+
},
|
|
56
|
+
'array (2)': {
|
|
57
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
58
|
+
expected: {prices: {length: '>0'}},
|
|
59
|
+
diff: null,
|
|
60
|
+
},
|
|
61
|
+
'array (3)': {
|
|
62
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
63
|
+
expected: {prices: [0, 1, 2, 3, 4, 5]},
|
|
64
|
+
diff: null,
|
|
65
|
+
},
|
|
66
|
+
'array (4)': {
|
|
67
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
68
|
+
expected: {prices: [0, 1, 2, 3, 4, 5, 6]},
|
|
69
|
+
diff: {path: '.prices[6]', actual: undefined, expected: 6},
|
|
70
|
+
},
|
|
71
|
+
'array (5)': {
|
|
72
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
73
|
+
expected: {prices: []},
|
|
74
|
+
diff: {path: '.prices.length', actual: [0, 1, 2, 3, 4, 5], expected: []},
|
|
75
|
+
},
|
|
76
|
+
'array (6)': {
|
|
77
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
78
|
+
expected: {prices: {'3': '>=3'}},
|
|
79
|
+
diff: null,
|
|
80
|
+
},
|
|
81
|
+
'array (7)': {
|
|
82
|
+
actual: {prices: [0, 1, 2, {nested: 3}, 4, 5]},
|
|
83
|
+
expected: {prices: {'3': {nested: '>3'}}},
|
|
84
|
+
diff: {path: '.prices[3].nested', actual: 3, expected: '>3'},
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
'_includes (1)': {
|
|
88
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
89
|
+
expected: {prices: {_includes: [4]}},
|
|
90
|
+
diff: null,
|
|
91
|
+
},
|
|
92
|
+
'_includes (2)': {
|
|
93
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
94
|
+
expected: {prices: {_includes: [4, 4]}},
|
|
95
|
+
diff: {path: '.prices', actual: 'Item not found in array', expected: 4},
|
|
96
|
+
},
|
|
97
|
+
'_includes (3)': {
|
|
98
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
99
|
+
expected: {prices: {_includes: [100]}},
|
|
100
|
+
diff: {path: '.prices', actual: 'Item not found in array', expected: 100},
|
|
101
|
+
},
|
|
102
|
+
'_includes (4)': {
|
|
103
|
+
actual: {prices: ['0', '1', '2', '3', '4', '5']},
|
|
104
|
+
expected: {prices: {_includes: [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/]}},
|
|
105
|
+
diff: null,
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
'_excludes (1)': {
|
|
109
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
110
|
+
expected: {prices: {_excludes: [100]}},
|
|
111
|
+
diff: null,
|
|
112
|
+
},
|
|
113
|
+
'_excludes (2)': {
|
|
114
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
115
|
+
expected: {prices: {_excludes: [2]}},
|
|
116
|
+
diff: {path: '.prices', actual: 2, expected: {
|
|
117
|
+
expectedExclusion: 2,
|
|
118
|
+
message: 'Expected to not find matching entry via _excludes',
|
|
119
|
+
}},
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
'_includes and _excludes (1)': {
|
|
123
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
124
|
+
expected: {prices: {_includes: [2], _excludes: [2]}},
|
|
125
|
+
diff: null,
|
|
126
|
+
},
|
|
127
|
+
// Order matters.
|
|
128
|
+
'_includes and _excludes (2)': {
|
|
129
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
130
|
+
expected: {prices: {_excludes: [2], _includes: [2]}},
|
|
131
|
+
diff: {path: '.prices', actual: 2, expected: {
|
|
132
|
+
expectedExclusion: 2,
|
|
133
|
+
message: 'Expected to not find matching entry via _excludes',
|
|
134
|
+
}},
|
|
135
|
+
},
|
|
136
|
+
'_includes and _excludes (3)': {
|
|
137
|
+
actual: {prices: [0, 1, 2, 3, 4, 5]},
|
|
138
|
+
expected: {prices: {_includes: [2], _excludes: [2, 1]}},
|
|
139
|
+
diff: {path: '.prices', actual: 1, expected: {
|
|
140
|
+
expectedExclusion: 1,
|
|
141
|
+
message: 'Expected to not find matching entry via _excludes',
|
|
142
|
+
}},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
for (const [testName, {actual, expected, diff}] of Object.entries(testCases)) {
|
|
147
|
+
it(testName, () => {
|
|
148
|
+
expect(findDifference('', actual, expected)).toEqual(diff);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Removes ANSI codes.
|
|
155
|
+
* TODO: should make it so logger can disable these.
|
|
156
|
+
* @param {string} text
|
|
157
|
+
*/
|
|
158
|
+
function clean(text) {
|
|
159
|
+
return text
|
|
160
|
+
.replace(/\x1B.*?m/g, '')
|
|
161
|
+
.replace(/\x1b.*?m/g, '')
|
|
162
|
+
.replace(/[✘×]/g, 'X')
|
|
163
|
+
.trim();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
describe('getAssertionReport', () => {
|
|
167
|
+
const lhr = readJson('lighthouse-core/test/results/sample_v2.json');
|
|
168
|
+
const artifacts = readJson('lighthouse-core/test/results/artifacts/artifacts.json');
|
|
169
|
+
|
|
170
|
+
it('works (trivial passing)', () => {
|
|
171
|
+
const report = getAssertionReport({lhr, artifacts}, {
|
|
172
|
+
lhr: {
|
|
173
|
+
audits: {},
|
|
174
|
+
requestedUrl: 'http://localhost:10200/dobetterweb/dbw_tester.html',
|
|
175
|
+
finalUrl: 'http://localhost:10200/dobetterweb/dbw_tester.html',
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
expect(report).toMatchObject({passed: 3, failed: 0, log: ''});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('works (trivial failing)', () => {
|
|
182
|
+
const report = getAssertionReport({lhr, artifacts}, {
|
|
183
|
+
lhr: {
|
|
184
|
+
audits: {
|
|
185
|
+
'cumulative-layout-shift': {
|
|
186
|
+
details: {
|
|
187
|
+
items: [],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
requestedUrl: 'http://localhost:10200/dobetterweb/dbw_tester.html',
|
|
192
|
+
finalUrl: 'http://localhost:10200/dobetterweb/dbw_tester.html',
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
expect(report).toMatchObject({passed: 3, failed: 1});
|
|
196
|
+
expect(clean(report.log)).toMatchSnapshot();
|
|
197
|
+
});
|
|
198
|
+
});
|
package/package.json
CHANGED