lighthouse 9.5.0-dev.20220420 → 9.5.0-dev.20220423

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.
@@ -82,7 +82,8 @@ Arrays can be asserted to not match any elements using the special `_excludes` p
82
82
 
83
83
  ### Special environment checks
84
84
 
85
- If an expectation requires a minimum version of Chromium, use `_minChromiumMilestone: xx` to conditionally ignore that entire object in the expectation.
85
+ If an expectation requires a minimum version of Chromium, use `_minChromiumVersion: xx.x.x.x` to conditionally ignore that entire object in the expectation.
86
+ Can be as specific as you like (`_minChromiumVersion: xx` works too).
86
87
 
87
88
  **Examples**:
88
89
  ```js
@@ -90,7 +91,7 @@ If an expectation requires a minimum version of Chromium, use `_minChromiumMiles
90
91
  artifacts: {
91
92
  InspectorIssues: {
92
93
  // Mixed Content issues weren't added to the protocol until M84.
93
- _minChromiumMilestone: 84, // The entire `InspectorIssues` is ignored for older Chrome.
94
+ _minChromiumVersion: '84', // The entire `InspectorIssues` is ignored for older Chrome.
94
95
  mixedContent: [
95
96
  {
96
97
  resourceType: 'Image',
@@ -111,8 +112,8 @@ If an expectation requires a minimum version of Chromium, use `_minChromiumMiles
111
112
 
112
113
  All pruning checks:
113
114
 
114
- - `_minChromiumMilestone`
115
- - `_maxChromiumMilestone`
115
+ - `_minChromiumVersion`
116
+ - `_maxChromiumVersion`
116
117
  - `_legacyOnly`
117
118
  - `_fraggleRockOnly`
118
119
  - `_skipInBundled`
@@ -13,6 +13,7 @@ import _ from 'lodash';
13
13
  import log from 'lighthouse-logger';
14
14
 
15
15
  import {LocalConsole} from './lib/local-console.js';
16
+ import {chromiumVersionCheck} from './version-check.js';
16
17
 
17
18
  const {cloneDeep} = _;
18
19
 
@@ -227,22 +228,26 @@ function pruneExpectations(localConsole, lhr, expected, reportOptions) {
227
228
 
228
229
  /**
229
230
  * Lazily compute the Chrome version because some reports are explicitly asserting error conditions.
230
- * @returns {number}
231
+ * @returns {string}
231
232
  */
232
- function getChromeVersion() {
233
+ function getChromeVersionString() {
233
234
  const userAgent = lhr.environment.hostUserAgent;
234
- const userAgentMatch = /Chrome\/(\d+)/.exec(userAgent); // Chrome/85.0.4174.0
235
+ const userAgentMatch = /Chrome\/([\d.]+)/.exec(userAgent); // Chrome/85.0.4174.0
235
236
  if (!userAgentMatch) throw new Error('Could not get chrome version.');
236
- return Number(userAgentMatch[1]);
237
+ const versionString = userAgentMatch[1];
238
+ if (versionString.split('.').length !== 4) throw new Error(`unexpected ua: ${userAgent}`);
239
+ return versionString;
237
240
  }
238
241
 
239
242
  /**
240
243
  * @param {*} obj
241
244
  */
242
245
  function failsChromeVersionCheck(obj) {
243
- if (obj._minChromiumMilestone && getChromeVersion() < obj._minChromiumMilestone) return true;
244
- if (obj._maxChromiumMilestone && getChromeVersion() > obj._maxChromiumMilestone) return true;
245
- return false;
246
+ return !chromiumVersionCheck({
247
+ version: getChromeVersionString(),
248
+ min: obj._minChromiumVersion,
249
+ max: obj._maxChromiumVersion,
250
+ });
246
251
  }
247
252
 
248
253
  /**
@@ -271,7 +276,7 @@ function pruneExpectations(localConsole, lhr, expected, reportOptions) {
271
276
  localConsole.log([
272
277
  `[${key}] failed chrome version check, pruning expectation:`,
273
278
  JSON.stringify(value, null, 2),
274
- `Actual Chromium version: ${getChromeVersion()}`,
279
+ `Actual Chromium version: ${getChromeVersionString()}`,
275
280
  ].join(' '));
276
281
  remove(key);
277
282
  } else if (value._legacyOnly && isFraggleRock) {
@@ -307,8 +312,8 @@ function pruneExpectations(localConsole, lhr, expected, reportOptions) {
307
312
  delete obj._legacyOnly;
308
313
  delete obj._fraggleRockOnly;
309
314
  delete obj._skipInBundled;
310
- delete obj._minChromiumMilestone;
311
- delete obj._maxChromiumMilestone;
315
+ delete obj._minChromiumVersion;
316
+ delete obj._maxChromiumVersion;
312
317
  delete obj._runner;
313
318
  }
314
319
 
@@ -0,0 +1,45 @@
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
+ import {chromiumVersionCheck, compareVersions} from './version-check.js';
8
+
9
+ /* eslint-env jest */
10
+
11
+ describe('version check', () => {
12
+ it('compareVersions', async () => {
13
+ expect(compareVersions([100, 0, 0, 0], [100, 0, 0, 0])).toBe(0);
14
+ expect(compareVersions([101, 0, 0, 0], [100, 0, 0, 0])).toBe(1);
15
+ expect(compareVersions([99, 0, 0, 0], [100, 0, 0, 0])).toBe(-1);
16
+
17
+ expect(compareVersions([100, 0, 10, 0], [100, 0, 10, 0])).toBe(0);
18
+ expect(compareVersions([100, 0, 11, 0], [100, 0, 10, 0])).toBe(1);
19
+ expect(compareVersions([100, 0, 9, 0], [100, 0, 10, 0])).toBe(-1);
20
+
21
+ expect(compareVersions([100, 0, 0, 0], [100])).toBe(0);
22
+ expect(compareVersions([100, 0, 0, 1], [100])).toBe(1);
23
+ expect(compareVersions([99, 0, 0, 0], [100])).toBe(-1);
24
+ });
25
+
26
+ it('chromiumVersionCheck', async () => {
27
+ expect(chromiumVersionCheck({version: '100'})).toBe(true);
28
+ expect(chromiumVersionCheck({version: '100', min: '100'})).toBe(true);
29
+ expect(chromiumVersionCheck({version: '100', max: '100'})).toBe(true);
30
+ expect(chromiumVersionCheck({version: '100', min: '101'})).toBe(false);
31
+ expect(chromiumVersionCheck({version: '100', max: '99'})).toBe(false);
32
+
33
+ expect(chromiumVersionCheck({version: '100.0.2331.3'})).toBe(true);
34
+ expect(chromiumVersionCheck({version: '100.0.2331.3', min: '100.0.2331.3'})).toBe(true);
35
+ expect(chromiumVersionCheck({version: '100.0.2331.3', min: '100.0.0.0'})).toBe(true);
36
+ expect(chromiumVersionCheck({version: '100.0.2331.3', max: '100.0.3333.3'})).toBe(true);
37
+ expect(chromiumVersionCheck({version: '100.0.2331.3', min: '100.0.2331.2'})).toBe(true);
38
+ expect(chromiumVersionCheck({version: '100.0.2331.3', max: '99'})).toBe(false);
39
+
40
+ expect(chromiumVersionCheck({
41
+ version: '100.0.2331.3', min: '100.0.2331.0', max: '100.0.2331.10'})).toBe(true);
42
+ expect(chromiumVersionCheck({
43
+ version: '100.3.2331.3', min: '100.0.2331.0', max: '100.0.2331.10'})).toBe(false);
44
+ });
45
+ });
@@ -0,0 +1,48 @@
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
+ /**
8
+ * @fileoverview Compares chromium version strings: 103.0.5017.0
9
+ */
10
+
11
+ /**
12
+ * @param {string} versionString
13
+ * @return {number[]}
14
+ */
15
+ function parseVersion(versionString) {
16
+ const versionParts = versionString.split('.');
17
+ return versionParts.map(Number);
18
+ }
19
+
20
+ /**
21
+ * @param {number[]} versionA
22
+ * @param {number[]} versionB
23
+ */
24
+ function compareVersions(versionA, versionB) {
25
+ for (let i = 0; i < versionA.length; i++) {
26
+ if ((versionA[i] ?? 0) > (versionB[i] ?? 0)) return 1;
27
+ if ((versionA[i] ?? 0) < (versionB[i] ?? 0)) return -1;
28
+ }
29
+ return 0;
30
+ }
31
+
32
+ /**
33
+ * Returns false if fails check.
34
+ * @param {{version: string, min?: string, max?: string}} opts
35
+ */
36
+ function chromiumVersionCheck(opts) {
37
+ const version = parseVersion(opts.version);
38
+ const min = opts.min && parseVersion(opts.min);
39
+ const max = opts.max && parseVersion(opts.max);
40
+ if (min && compareVersions(version, min) === -1) return false;
41
+ if (max && compareVersions(version, max) === 1) return false;
42
+ return true;
43
+ }
44
+
45
+ export {
46
+ chromiumVersionCheck,
47
+ compareVersions,
48
+ };
@@ -64,6 +64,10 @@ class Deprecations extends Audit {
64
64
  let deprecations;
65
65
  if (artifacts.InspectorIssues.deprecationIssue.length) {
66
66
  deprecations = artifacts.InspectorIssues.deprecationIssue
67
+ // TODO: translate these strings.
68
+ // see https://github.com/GoogleChrome/lighthouse/issues/13895
69
+ // @ts-expect-error: .type hasn't released to npm yet
70
+ .filter(deprecation => !deprecation.type || deprecation.type === 'Untranslated')
67
71
  .map(deprecation => {
68
72
  const {scriptId, url, lineNumber, columnNumber} = deprecation.sourceCodeLocation;
69
73
  const bundle = bundles.find(bundle => bundle.script.scriptId === scriptId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.5.0-dev.20220420",
3
+ "version": "9.5.0-dev.20220423",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {
@@ -27,7 +27,7 @@ declare global {
27
27
 
28
28
  export type ExpectedRunnerResult = {
29
29
  lhr: ExpectedLHR,
30
- artifacts?: Partial<Record<keyof Artifacts|'_maxChromiumMilestone'|'_minChromiumMilestone', any>>
30
+ artifacts?: Partial<Record<keyof Artifacts|'_maxChromiumVersion'|'_minChromiumVersion', any>>
31
31
  networkRequests?: {length: number, _legacyOnly?: boolean, _fraggleRockOnly?: boolean};
32
32
  }
33
33