lighthouse 9.5.0-dev.20220828 → 9.5.0-dev.20220829

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,31 @@
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
+ * List of smoke tests excluded per runner. eg: 'cli': ['a11y', 'dbw']
9
+ * @type {Record<string, Array<string>>}
10
+ */
11
+ const exclusions = {
12
+ 'bundle': [],
13
+ 'cli': [],
14
+ 'devtools': [
15
+ // Disabled because normal Chrome usage makes DevTools not function on
16
+ // these poorly constructed pages
17
+ 'errors-expired-ssl', 'errors-infinite-loop', 'dbw' /* dialog prompt */,
18
+ // Disabled because Chrome will follow the redirect first, and Lighthouse will
19
+ // only ever see/run the final URL.
20
+ 'redirects-client-paint-server', 'redirects-multiple-server',
21
+ 'redirects-single-server', 'redirects-single-client',
22
+ 'redirects-history-push-state', 'redirects-scripts',
23
+ // Disabled because these tests use settings that cannot be fully configured in
24
+ // DevTools (e.g. throttling method "provided").
25
+ 'metrics-tricky-tti', 'metrics-tricky-tti-late-fcp', 'screenshot',
26
+ // Disabled because of differences that need further investigation
27
+ 'byte-efficiency', 'byte-gzip', 'perf-preload',
28
+ ],
29
+ };
30
+
31
+ export default exclusions;
@@ -24,6 +24,7 @@ import log from 'lighthouse-logger';
24
24
  import {runSmokehouse, getShardedDefinitions} from '../smokehouse.js';
25
25
  import {updateTestDefnFormat} from './back-compat-util.js';
26
26
  import {LH_ROOT} from '../../../../root.js';
27
+ import exclusions from '../config/exclusions.js';
27
28
 
28
29
  const coreTestDefnsPath =
29
30
  path.join(LH_ROOT, 'cli/test/smokehouse/core-tests.js');
@@ -69,6 +70,7 @@ function getDefinitionsToRun(allTestDefns, requestedIds, {invertMatch}) {
69
70
  });
70
71
  if (unmatchedIds.length) {
71
72
  console.log(log.redify(`Smoketests not found for: ${unmatchedIds.join(' ')}`));
73
+ console.log(`Check test exclusions (${requestedIds.join(' ')})\n`);
72
74
  console.log(usage);
73
75
  }
74
76
 
@@ -193,8 +195,11 @@ async function begin() {
193
195
  const requestedTestIds = argv._;
194
196
  const {default: rawTestDefns} = await import(url.pathToFileURL(testDefnPath).href);
195
197
  const allTestDefns = updateTestDefnFormat(rawTestDefns);
198
+ const excludedTests = new Set(exclusions[argv.runner] || []);
199
+ const filteredTestDefns = allTestDefns.filter(test => !excludedTests.has(test.id));
196
200
  const invertMatch = argv.invertMatch;
197
- const requestedTestDefns = getDefinitionsToRun(allTestDefns, requestedTestIds, {invertMatch});
201
+ const requestedTestDefns = getDefinitionsToRun(filteredTestDefns,
202
+ requestedTestIds, {invertMatch});
198
203
  const testDefns = getShardedDefinitions(requestedTestDefns, argv.shard);
199
204
 
200
205
  let smokehouseResult;
@@ -5773,6 +5773,16 @@ function swapLocale(lhr, requestedLocale) {
5773
5773
  function registerLocaleData(locale, lhlMessages) {
5774
5774
  // Stub function only included for types
5775
5775
  }
5776
- const format = {registerLocaleData};
5776
+
5777
+ /**
5778
+ * Returns whether the requestedLocale is registered and available for use
5779
+ * @param {LH.Locale} requestedLocale
5780
+ * @return {boolean}
5781
+ */
5782
+ function hasLocale(requestedLocale) {
5783
+ // Stub function only included for types
5784
+ return false;
5785
+ }
5786
+ const format = {registerLocaleData, hasLocale};
5777
5787
 
5778
5788
  export { DOM, ReportRenderer, ReportUIFeatures, format, renderReport, swapLocale };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lighthouse",
3
3
  "type": "module",
4
- "version": "9.5.0-dev.20220828",
4
+ "version": "9.5.0-dev.20220829",
5
5
  "description": "Automated auditing, performance metrics, and best practices for the web.",
6
6
  "main": "./core/index.js",
7
7
  "bin": {
@@ -133,7 +133,7 @@ body {
133
133
  </head>
134
134
  <body >
135
135
  <noscript>PSI requires JavaScript. Please enable.</noscript>
136
- <button type=button id="translate">→ Español</button>
136
+ <button type=button id="translate">rotate locale</button>
137
137
  <div class="page">
138
138
  <button type=button id="reanalyze">Reanalyze</button>
139
139
  <div class="tabset">
@@ -13,77 +13,84 @@ const lighthouseRenderer = window['report'];
13
13
 
14
14
  const wait = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms));
15
15
 
16
-
17
16
  (async function __initPsiReports__() {
18
- renderLHReport();
19
-
20
17
  document.querySelector('button#reanalyze')?.addEventListener('click', () => {
21
- renderLHReport();
18
+ __initPsiReports__();
22
19
  });
23
20
 
24
21
  document.querySelector('button#translate')?.addEventListener('click', async () => {
25
- await swapLhrLocale('es');
26
- renderLHReport();
22
+ const hash = location.hash.slice(1);
23
+ const someLocales = ['es', 'ja', 'ru', 'ar', 'en-US'];
24
+ // Just rotate to the next one
25
+ const nextLocale = someLocales[(someLocales.indexOf(hash) + 1) % someLocales.length];
26
+ location.hash = `#${nextLocale}`;
27
+ location.reload();
27
28
  });
28
- })();
29
29
 
30
- async function renderLHReport() {
31
- // @ts-expect-error
32
- const mobileLHR = window.__LIGHTHOUSE_JSON__;
33
- const desktopLHR = JSON.parse(JSON.stringify(mobileLHR));
30
+ const hash = location.hash.slice(1);
31
+ if (hash) {
32
+ // @ts-expect-error Can't do string to LH.Locale
33
+ await swapLhrLocale(hash);
34
+ }
34
35
 
35
- const lhrs = {
36
- 'mobile': mobileLHR,
37
- 'desktop': desktopLHR,
38
- };
36
+ // We deliberately want the non-blocking await behavior w/ forEach
37
+ ['mobile', 'desktop'].forEach(async id => {
38
+ const container = document.querySelector(`section#${id} .reportContainer`);
39
+ if (!container) throw new Error('Unexpected DOM. Bailing.');
40
+ container.textContent = 'Analyzing…';
41
+ await wait(id === 'desktop' ? 3000 : 500);
39
42
 
40
- for (const [tabId, lhr] of Object.entries(lhrs)) {
41
- await distinguishLHR(lhr, tabId);
43
+ // @ts-expect-error
44
+ const lhr = JSON.parse(JSON.stringify(window.__LIGHTHOUSE_JSON__));
45
+ await distinguishLHR(lhr, id);
42
46
 
43
- const container = document.querySelector(`section#${tabId} .reportContainer`);
44
- if (!container) throw new Error('Unexpected DOM. Bailing.');
47
+ renderLHReport(lhr, container);
48
+ });
49
+ })();
45
50
 
46
- try {
47
- container.textContent = 'Analyzing…';
48
- await wait(500);
49
- for (const el of container.childNodes) el.remove();
50
-
51
- const reportRootEl = lighthouseRenderer.renderReport(lhr, {
52
- omitTopbar: true,
53
- disableFireworks: true,
54
- disableDarkMode: true,
55
- });
56
- // TODO: display warnings if appropriate.
57
- for (const el of reportRootEl.querySelectorAll('.lh-warnings--toplevel')) {
58
- el.setAttribute('hidden', 'true');
59
- }
60
-
61
- // Move env block
62
- const metaItemsEl = reportRootEl.querySelector('.lh-meta__items');
63
- if (metaItemsEl) {
64
- reportRootEl.querySelector('.lh-metrics-container')?.parentNode?.insertBefore(
65
- metaItemsEl,
66
- reportRootEl.querySelector('.lh-buttons')
67
- );
68
- reportRootEl.querySelector('.lh-metrics-container')?.closest('.lh-category')?.classList
69
- .add('lh--hoisted-meta');
70
- }
71
-
72
- container.append(reportRootEl);
73
-
74
- // Override some LH styles. (To find .lh-vars we must descend from reportRootEl's parent)
75
- for (const el of container.querySelectorAll('article.lh-vars')) {
76
- // Ensure these css var names are not stale.
77
- el.style.setProperty('--report-content-max-width', '100%');
78
- el.style.setProperty('--edge-gap-padding', '0');
79
- }
80
- for (const el of reportRootEl.querySelectorAll('footer.lh-footer')) {
81
- el.style.display = 'none';
82
- }
83
- } catch (e) {
84
- console.error(e);
85
- container.textContent = 'Error: LHR failed to render.';
51
+ /**
52
+ * @param {any} lhr
53
+ * @param {Element} container
54
+ */
55
+ async function renderLHReport(lhr, container) {
56
+ try {
57
+ for (const el of container.childNodes) el.remove();
58
+
59
+ const reportRootEl = lighthouseRenderer.renderReport(lhr, {
60
+ omitTopbar: true,
61
+ disableFireworks: true,
62
+ disableDarkMode: true,
63
+ });
64
+ // TODO: display warnings if appropriate.
65
+ for (const el of reportRootEl.querySelectorAll('.lh-warnings--toplevel')) {
66
+ el.setAttribute('hidden', 'true');
86
67
  }
68
+
69
+ // Move env block
70
+ const metaItemsEl = reportRootEl.querySelector('.lh-meta__items');
71
+ if (metaItemsEl) {
72
+ reportRootEl.querySelector('.lh-metrics-container')?.parentNode?.insertBefore(
73
+ metaItemsEl,
74
+ reportRootEl.querySelector('.lh-buttons')
75
+ );
76
+ reportRootEl.querySelector('.lh-metrics-container')?.closest('.lh-category')?.classList
77
+ .add('lh--hoisted-meta');
78
+ }
79
+
80
+ container.append(reportRootEl);
81
+
82
+ // Override some LH styles. (To find .lh-vars we must descend from reportRootEl's parent)
83
+ for (const el of container.querySelectorAll('article.lh-vars')) {
84
+ // Ensure these css var names are not stale.
85
+ el.style.setProperty('--report-content-max-width', '100%');
86
+ el.style.setProperty('--edge-gap-padding', '0');
87
+ }
88
+ for (const el of reportRootEl.querySelectorAll('footer.lh-footer')) {
89
+ el.style.display = 'none';
90
+ }
91
+ } catch (e) {
92
+ console.error(e);
93
+ container.textContent = 'Error: LHR failed to render.';
87
94
  }
88
95
  }
89
96
 
@@ -91,13 +98,20 @@ async function renderLHReport() {
91
98
  * @param {LH.Locale} locale
92
99
  */
93
100
  async function swapLhrLocale(locale) {
94
- const response = await fetch(`https://www.gstatic.com/pagespeed/insights/ui/locales/${locale}.json`);
95
- /** @type {import('../../shared/localization/locales').LhlMessages} */
96
- const lhlMessages = await response.json();
97
- console.log(lhlMessages);
98
- if (!lhlMessages) throw new Error(`could not fetch data for locale: ${locale}`);
99
-
100
- lighthouseRenderer.format.registerLocaleData(locale, lhlMessages);
101
+ // @ts-expect-error LHR global
102
+ const lhrLocale = window.__LIGHTHOUSE_JSON__['configSettings']['locale'];
103
+
104
+ // Only fetch and swapLocale if necessary.
105
+ if (lhrLocale === locale) return;
106
+
107
+ if (!lighthouseRenderer.format.hasLocale(locale)) {
108
+ // Requires running a server in LH root and viewing localhost:XXXX/dist/sample-reports/⌣.psi.english/index.html
109
+ const response = await fetch(`/shared/localization/locales/${locale}.json`);
110
+ /** @type {import('../../shared/localization/locales').LhlMessages} */
111
+ const lhlMessages = await response.json();
112
+ if (!lhlMessages) throw new Error(`could not fetch data for locale: ${locale}`);
113
+ lighthouseRenderer.format.registerLocaleData(locale, lhlMessages);
114
+ }
101
115
  // @ts-expect-error LHR global
102
116
  window.__LIGHTHOUSE_JSON__ = lighthouseRenderer.swapLocale(window.__LIGHTHOUSE_JSON__, locale)
103
117
  .lhr;
@@ -381,7 +381,7 @@ function _getLocaleMessages(locale) {
381
381
  }
382
382
 
383
383
  /**
384
- * Returns whether the `requestedLocale` can be used.
384
+ * Returns whether the `requestedLocale` is registered and available for use
385
385
  * @param {LH.Locale} requestedLocale
386
386
  * @return {boolean}
387
387
  */