lighthouse 8.6.0 → 9.0.0

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.
Files changed (209) hide show
  1. package/dist/report/bundle.esm.js +5994 -0
  2. package/dist/report/flow.js +30 -13
  3. package/dist/report/standalone.js +41 -35
  4. package/flow-report/.eslintrc.cjs +2 -0
  5. package/flow-report/assets/standalone-flow-template.html +3 -2
  6. package/flow-report/assets/styles.css +108 -31
  7. package/flow-report/src/app.tsx +18 -18
  8. package/flow-report/src/common.tsx +28 -15
  9. package/flow-report/src/header.tsx +12 -13
  10. package/flow-report/src/help-dialog.tsx +3 -4
  11. package/flow-report/src/i18n/i18n.tsx +57 -16
  12. package/flow-report/src/i18n/ui-strings.js +50 -0
  13. package/flow-report/src/icons.tsx +36 -8
  14. package/flow-report/src/sidebar/flow.tsx +3 -3
  15. package/flow-report/src/sidebar/sidebar.tsx +35 -14
  16. package/flow-report/src/summary/category.tsx +97 -24
  17. package/flow-report/src/summary/summary.tsx +21 -14
  18. package/flow-report/src/topbar.tsx +9 -5
  19. package/flow-report/src/util.ts +33 -26
  20. package/flow-report/src/wrappers/category-score.tsx +0 -3
  21. package/flow-report/src/wrappers/markdown.tsx +27 -0
  22. package/flow-report/src/wrappers/report-renderer.tsx +10 -3
  23. package/flow-report/src/wrappers/report.tsx +27 -6
  24. package/flow-report/standalone-flow.tsx +4 -3
  25. package/flow-report/test/common-test.tsx +32 -17
  26. package/flow-report/test/flow-report-pptr-test.ts +46 -0
  27. package/flow-report/test/header-test.tsx +6 -6
  28. package/flow-report/test/setup/env-setup.ts +1 -1
  29. package/flow-report/test/sidebar/sidebar-test.tsx +43 -1
  30. package/flow-report/test/summary/category-test.tsx +120 -24
  31. package/flow-report/test/summary/summary-test.tsx +1 -1
  32. package/flow-report/test/topbar-test.tsx +1 -0
  33. package/flow-report/test/util-test.tsx +32 -11
  34. package/flow-report/test/wrappers/category-score-test.tsx +87 -0
  35. package/flow-report/test/wrappers/markdown-test.tsx +29 -0
  36. package/flow-report/tsconfig.json +1 -0
  37. package/jest.config.js +4 -2
  38. package/lighthouse-cli/.eslintrc.cjs +2 -0
  39. package/lighthouse-cli/cli-flags.js +1 -1
  40. package/lighthouse-cli/run.js +1 -1
  41. package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +0 -0
  42. package/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js +4 -2
  43. package/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js +1 -1
  44. package/lighthouse-cli/test/smokehouse/smokehouse.js +1 -1
  45. package/lighthouse-core/audits/accessibility/axe-audit.js +7 -1
  46. package/lighthouse-core/audits/audit.js +1 -1
  47. package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +2 -0
  48. package/lighthouse-core/audits/byte-efficiency/modern-image-formats.js +4 -2
  49. package/lighthouse-core/audits/byte-efficiency/offscreen-images.js +11 -10
  50. package/lighthouse-core/audits/byte-efficiency/uses-optimized-images.js +5 -3
  51. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images-snapshot.js +2 -1
  52. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +2 -1
  53. package/lighthouse-core/audits/deprecations.js +33 -11
  54. package/lighthouse-core/audits/dobetterweb/uses-http2.js +27 -11
  55. package/lighthouse-core/audits/errors-in-console.js +0 -2
  56. package/lighthouse-core/audits/image-aspect-ratio.js +5 -5
  57. package/lighthouse-core/audits/image-size-responsive.js +6 -6
  58. package/lighthouse-core/audits/installable-manifest.js +5 -3
  59. package/lighthouse-core/audits/preload-lcp-image.js +7 -5
  60. package/lighthouse-core/audits/script-treemap-data.js +1 -1
  61. package/lighthouse-core/audits/unsized-images.js +2 -3
  62. package/lighthouse-core/computed/image-records.js +4 -3
  63. package/lighthouse-core/computed/metrics/lantern-total-blocking-time.js +3 -4
  64. package/lighthouse-core/computed/metrics/tbt-utils.js +57 -0
  65. package/lighthouse-core/computed/metrics/total-blocking-time.js +3 -53
  66. package/lighthouse-core/computed/resource-summary.js +1 -1
  67. package/lighthouse-core/config/config-helpers.js +21 -10
  68. package/lighthouse-core/config/constants.js +3 -4
  69. package/lighthouse-core/config/default-config.js +61 -71
  70. package/lighthouse-core/fraggle-rock/config/config.js +1 -1
  71. package/lighthouse-core/fraggle-rock/config/default-config.js +4 -5
  72. package/lighthouse-core/fraggle-rock/gather/base-gatherer.js +6 -1
  73. package/lighthouse-core/fraggle-rock/gather/session.js +3 -4
  74. package/lighthouse-core/gather/connections/cri.js +1 -1
  75. package/lighthouse-core/gather/driver/storage.js +0 -1
  76. package/lighthouse-core/gather/driver.js +3 -7
  77. package/lighthouse-core/gather/fetcher.js +4 -7
  78. package/lighthouse-core/gather/gather-runner.js +29 -6
  79. package/lighthouse-core/gather/gatherers/accessibility.js +27 -0
  80. package/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +1 -0
  81. package/lighthouse-core/gather/gatherers/image-elements.js +0 -3
  82. package/lighthouse-core/gather/gatherers/inspector-issues.js +5 -0
  83. package/lighthouse-core/lib/asset-saver.js +7 -4
  84. package/lighthouse-core/lib/emulation.js +45 -1
  85. package/lighthouse-core/lib/i18n/i18n.js +19 -8
  86. package/lighthouse-core/lib/lh-env.js +2 -0
  87. package/lighthouse-core/lib/proto-preprocessor.js +14 -2
  88. package/lighthouse-core/lib/tappable-rects.js +8 -15
  89. package/lighthouse-core/lib/url-shim.js +1 -1
  90. package/lighthouse-core/runner.js +1 -1
  91. package/lighthouse-core/util-commonjs.js +65 -46
  92. package/package.json +27 -17
  93. package/readme.md +3 -3
  94. package/report/.eslintrc.cjs +2 -0
  95. package/report/README.md +1 -1
  96. package/report/assets/standalone-template.html +2 -3
  97. package/report/assets/styles.css +360 -254
  98. package/report/assets/templates.html +21 -76
  99. package/report/clients/bundle.js +1 -0
  100. package/report/clients/standalone.js +6 -15
  101. package/report/generator/README.md +1 -1
  102. package/report/renderer/api.js +32 -0
  103. package/report/renderer/category-renderer.js +59 -19
  104. package/report/renderer/components.js +59 -110
  105. package/report/renderer/crc-details-renderer.js +15 -12
  106. package/report/renderer/dom.js +16 -1
  107. package/report/renderer/drop-down-menu.js +2 -2
  108. package/report/renderer/element-screenshot-renderer.js +8 -8
  109. package/report/renderer/features-util.js +1 -1
  110. package/report/renderer/open-tab.js +9 -3
  111. package/report/renderer/performance-category-renderer.js +55 -34
  112. package/report/renderer/pwa-category-renderer.js +0 -10
  113. package/report/renderer/report-renderer.js +91 -44
  114. package/report/renderer/report-ui-features.js +36 -33
  115. package/report/renderer/swap-locale-feature.js +3 -3
  116. package/report/renderer/topbar-features.js +53 -48
  117. package/report/renderer/util.js +66 -46
  118. package/report/test/clients/bundle-test.js +70 -0
  119. package/report/test/renderer/category-renderer-test.js +48 -3
  120. package/report/test/renderer/i18n-test.js +0 -7
  121. package/report/test/renderer/performance-category-renderer-test.js +51 -14
  122. package/report/test/renderer/pwa-category-renderer-test.js +6 -6
  123. package/report/test/renderer/report-renderer-axe-test.js +10 -12
  124. package/report/test/renderer/report-renderer-test.js +23 -22
  125. package/report/test/renderer/report-ui-features-test.js +20 -10
  126. package/report/test/renderer/text-encoding-test.js +1 -1
  127. package/report/test/renderer/util-test.js +35 -31
  128. package/report/test-assets/faux-psi-template.html +3 -11
  129. package/report/test-assets/faux-psi.js +26 -22
  130. package/report/types/html-renderer.d.ts +2 -0
  131. package/report/types/report-renderer.d.ts +23 -0
  132. package/shared/localization/format.js +64 -30
  133. package/shared/localization/locales/ar-XB.json +72 -75
  134. package/shared/localization/locales/ar.json +72 -75
  135. package/shared/localization/locales/bg.json +72 -75
  136. package/shared/localization/locales/ca.json +72 -75
  137. package/shared/localization/locales/cs.json +89 -92
  138. package/shared/localization/locales/da.json +72 -75
  139. package/shared/localization/locales/de.json +89 -92
  140. package/shared/localization/locales/el.json +72 -75
  141. package/shared/localization/locales/en-GB.json +72 -75
  142. package/shared/localization/locales/en-US.json +75 -75
  143. package/shared/localization/locales/en-XA.json +72 -75
  144. package/shared/localization/locales/en-XL.json +75 -75
  145. package/shared/localization/locales/es-419.json +90 -93
  146. package/shared/localization/locales/es.json +90 -93
  147. package/shared/localization/locales/fi.json +72 -75
  148. package/shared/localization/locales/fil.json +72 -75
  149. package/shared/localization/locales/fr.json +89 -92
  150. package/shared/localization/locales/he.json +73 -76
  151. package/shared/localization/locales/hi.json +72 -75
  152. package/shared/localization/locales/hr.json +72 -75
  153. package/shared/localization/locales/hu.json +89 -92
  154. package/shared/localization/locales/id.json +89 -92
  155. package/shared/localization/locales/it.json +89 -92
  156. package/shared/localization/locales/ja.json +89 -92
  157. package/shared/localization/locales/ko.json +89 -92
  158. package/shared/localization/locales/lt.json +89 -92
  159. package/shared/localization/locales/lv.json +95 -98
  160. package/shared/localization/locales/nl.json +89 -92
  161. package/shared/localization/locales/no.json +72 -75
  162. package/shared/localization/locales/pl.json +72 -75
  163. package/shared/localization/locales/pt-PT.json +72 -75
  164. package/shared/localization/locales/pt.json +89 -92
  165. package/shared/localization/locales/ro.json +90 -93
  166. package/shared/localization/locales/ru.json +89 -92
  167. package/shared/localization/locales/sk.json +89 -92
  168. package/shared/localization/locales/sl.json +89 -92
  169. package/shared/localization/locales/sr-Latn.json +89 -92
  170. package/shared/localization/locales/sr.json +89 -92
  171. package/shared/localization/locales/sv.json +72 -75
  172. package/shared/localization/locales/ta.json +89 -92
  173. package/shared/localization/locales/te.json +89 -92
  174. package/shared/localization/locales/th.json +89 -92
  175. package/shared/localization/locales/tr.json +89 -92
  176. package/shared/localization/locales/uk.json +92 -95
  177. package/shared/localization/locales/vi.json +89 -92
  178. package/shared/localization/locales/zh-HK.json +89 -92
  179. package/shared/localization/locales/zh-TW.json +89 -92
  180. package/shared/localization/locales/zh.json +89 -92
  181. package/shared/localization/locales.js +6 -0
  182. package/shared/test/localization/format-test.js +45 -9
  183. package/shared/test/localization/swap-locale-test.js +0 -12
  184. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +19 -11
  185. package/third-party/chromium-synchronization/installability-errors-test.js +2 -0
  186. package/third-party/download-content-shell/download-content-shell.js +2 -2
  187. package/third-party/download-content-shell/utils.js +0 -24
  188. package/tsconfig-all.json +2 -2
  189. package/tsconfig.json +0 -1
  190. package/types/artifacts.d.ts +7 -7
  191. package/types/enquirer.d.ts +3 -1
  192. package/types/lhr/audit-details.d.ts +6 -5
  193. package/types/lhr/flow.d.ts +3 -2
  194. package/types/lhr/lhr.d.ts +1 -1
  195. package/types/node.d.ts +5 -5
  196. package/types/rollup-plugin-postprocess.d.ts +10 -0
  197. package/changelog.md +0 -5490
  198. package/lighthouse-core/audits/dobetterweb/appcache-manifest.js +0 -67
  199. package/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js +0 -96
  200. package/lighthouse-core/audits/redirects-http.js +0 -59
  201. package/lighthouse-core/gather/gatherers/dobetterweb/appcache.js +0 -34
  202. package/lighthouse-core/gather/gatherers/http-redirect.js +0 -46
  203. package/lighthouse-core/lib/i18n/locales/en-US.ctc.json +0 -6699
  204. package/lighthouse-core/lib/i18n/locales/en-XL.ctc.json +0 -6672
  205. package/lighthouse-core/scripts/package.json +0 -4
  206. package/report/clients/psi.js +0 -158
  207. package/report/test/clients/psi-test.js +0 -143
  208. package/shared/localization/locales/en-US.ctc.json +0 -6877
  209. package/shared/localization/locales/en-XL.ctc.json +0 -6852
@@ -1,4 +0,0 @@
1
- {
2
- "type": "module",
3
- "//": "Any directory that uses `import ... from` or `export ...` must be type module. Temporary file until root package.json is type: module"
4
- }
@@ -1,158 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2018 The Lighthouse Authors. All Rights Reserved.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS-IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- 'use strict';
18
-
19
- import {DetailsRenderer} from '../renderer/details-renderer.js';
20
- import {DOM} from '../renderer/dom.js';
21
- import {ElementScreenshotRenderer} from '../renderer/element-screenshot-renderer.js';
22
- import {I18n} from '../renderer/i18n.js';
23
- import {openTreemap} from '../renderer/open-tab.js';
24
- import {PerformanceCategoryRenderer} from '../renderer/performance-category-renderer.js';
25
- import {ReportUIFeatures} from '../renderer/report-ui-features.js';
26
- import {Util} from '../renderer/util.js';
27
-
28
- /** @typedef {{scoreGaugeEl: Element, perfCategoryEl: Element, finalScreenshotDataUri: string|null, scoreScaleEl: Element, installFeatures: Function}} PrepareLabDataResult */
29
-
30
- /**
31
- * Returns all the elements that PSI needs to render the report
32
- * We expose this helper method to minimize the 'public' API surface of the renderer
33
- * and allow us to refactor without two-sided patches.
34
- *
35
- * const {scoreGaugeEl, perfCategoryEl, finalScreenshotDataUri} = prepareLabData(
36
- * LHResultJsonString,
37
- * document
38
- * );
39
- *
40
- * @param {LH.Result | string} LHResult The stringified version of {LH.Result}
41
- * @param {Document} document The host page's window.document
42
- * @return {PrepareLabDataResult}
43
- */
44
- export function prepareLabData(LHResult, document) {
45
- const lhResult = (typeof LHResult === 'string') ?
46
- /** @type {LH.Result} */ (JSON.parse(LHResult)) : LHResult;
47
-
48
- const dom = new DOM(document);
49
- const reportLHR = Util.prepareReportResult(lhResult);
50
- const i18n = new I18n(reportLHR.configSettings.locale, {
51
- // Set missing renderer strings to default (english) values.
52
- ...Util.UIStrings,
53
- ...reportLHR.i18n.rendererFormattedStrings,
54
- });
55
- Util.i18n = i18n;
56
- Util.reportJson = reportLHR;
57
-
58
- const perfCategory = reportLHR.categories.performance;
59
- if (!perfCategory) throw new Error(`No performance category. Can't make lab data section`);
60
- if (!reportLHR.categoryGroups) throw new Error(`No category groups found.`);
61
-
62
- // Use custom title and description.
63
- reportLHR.categoryGroups.metrics.title = Util.i18n.strings.labDataTitle;
64
- reportLHR.categoryGroups.metrics.description =
65
- Util.i18n.strings.lsPerformanceCategoryDescription;
66
-
67
- const fullPageScreenshot =
68
- reportLHR.audits['full-page-screenshot'] && reportLHR.audits['full-page-screenshot'].details &&
69
- reportLHR.audits['full-page-screenshot'].details.type === 'full-page-screenshot' ?
70
- reportLHR.audits['full-page-screenshot'].details : undefined;
71
-
72
- const detailsRenderer = new DetailsRenderer(dom, {fullPageScreenshot});
73
- const perfRenderer = new PerformanceCategoryRenderer(dom, detailsRenderer);
74
- // PSI environment string will ensure the categoryHeader and permalink elements are excluded
75
- const perfCategoryEl = perfRenderer.render(
76
- perfCategory,
77
- reportLHR.categoryGroups,
78
- {environment: 'PSI', gatherMode: lhResult.gatherMode}
79
- );
80
- perfCategoryEl.append(dom.createComponent('styles'));
81
-
82
- const scoreGaugeEl = dom.find('.lh-score__gauge', perfCategoryEl);
83
- scoreGaugeEl.remove();
84
- const scoreGaugeWrapperEl = dom.find('.lh-gauge__wrapper', scoreGaugeEl);
85
- scoreGaugeWrapperEl.classList.add('lh-gauge__wrapper--huge');
86
- // Remove navigation link on gauge
87
- scoreGaugeWrapperEl.removeAttribute('href');
88
-
89
- const finalScreenshotDataUri = _getFinalScreenshot(perfCategory);
90
-
91
- const clonedScoreTemplate = dom.createComponent('scorescale');
92
- const scoreScaleEl = dom.find('.lh-scorescale', clonedScoreTemplate);
93
-
94
- const reportUIFeatures = new ReportUIFeatures(dom);
95
- reportUIFeatures.json = lhResult;
96
-
97
- /** @param {HTMLElement} reportEl */
98
- const installFeatures = (reportEl) => {
99
- if (fullPageScreenshot) {
100
- // 1) Add fpss css var to reportEl parent so any thumbnails will work
101
- ElementScreenshotRenderer.installFullPageScreenshot(
102
- reportEl, fullPageScreenshot.screenshot);
103
-
104
- // 2) Append the overlay element to a specific part of the DOM so that
105
- // the sticky tab group element renders correctly. If put in the reportEl
106
- // like normal, then the sticky header would bleed through the overlay
107
- // element.
108
- const screenshotsContainer = document.querySelector('.element-screenshots-container');
109
- if (!screenshotsContainer) {
110
- throw new Error('missing .element-screenshots-container');
111
- }
112
-
113
- const screenshotEl = document.createElement('div');
114
- screenshotsContainer.append(screenshotEl);
115
- ElementScreenshotRenderer.installOverlayFeature({
116
- dom,
117
- reportEl,
118
- overlayContainerEl: screenshotEl,
119
- fullPageScreenshot,
120
- });
121
- // Not part of the reportEl, so have to install the feature here too.
122
- ElementScreenshotRenderer.installFullPageScreenshot(
123
- screenshotEl, fullPageScreenshot.screenshot);
124
- }
125
-
126
- const showTreemapApp =
127
- lhResult.audits['script-treemap-data'] && lhResult.audits['script-treemap-data'].details;
128
- const buttonContainer = reportEl.querySelector('.lh-audit-group--metrics');
129
- if (showTreemapApp && buttonContainer) {
130
- reportUIFeatures.addButton({
131
- container: buttonContainer,
132
- text: Util.i18n.strings.viewTreemapLabel,
133
- icon: 'treemap',
134
- onClick: () => openTreemap(lhResult),
135
- });
136
- }
137
- };
138
-
139
- return {scoreGaugeEl, perfCategoryEl, finalScreenshotDataUri, scoreScaleEl, installFeatures};
140
- }
141
-
142
- /**
143
- * @param {LH.ReportResult.Category} perfCategory
144
- * @return {null|string}
145
- */
146
- function _getFinalScreenshot(perfCategory) {
147
- const auditRef = perfCategory.auditRefs.find(audit => audit.id === 'final-screenshot');
148
- if (!auditRef || !auditRef.result || auditRef.result.scoreDisplayMode === 'error') return null;
149
- const details = auditRef.result.details;
150
- if (!details || details.type !== 'screenshot') return null;
151
- return details.data;
152
- }
153
-
154
- // TODO: remove with report API refactor.
155
- if (typeof window !== 'undefined') {
156
- // @ts-expect-error
157
- window.prepareLabData = prepareLabData;
158
- }
@@ -1,143 +0,0 @@
1
- /**
2
- * @license Copyright 2017 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
- 'use strict';
7
-
8
- import {strict as assert} from 'assert';
9
- import fs from 'fs';
10
-
11
- import jsdom from 'jsdom';
12
-
13
- import testUtils from '../../../lighthouse-core/test/test-utils.js';
14
- import {prepareLabData} from '../../clients/psi.js';
15
- import {Util} from '../../renderer/util.js';
16
- import {I18n} from '../../renderer/i18n.js';
17
- import {DOM} from '../../renderer/dom.js';
18
- import {CategoryRenderer} from '../../renderer/category-renderer.js';
19
- import {PerformanceCategoryRenderer} from '../../renderer/performance-category-renderer.js';
20
- import {DetailsRenderer} from '../../renderer/details-renderer.js';
21
- import {CriticalRequestChainRenderer} from '../../renderer/crc-details-renderer.js';
22
- import {ElementScreenshotRenderer} from '../../renderer/element-screenshot-renderer.js';
23
- import {ReportUIFeatures} from '../../renderer/report-ui-features.js';
24
- import {LH_ROOT} from '../../../root.js';
25
-
26
- const {itIfProtoExists, sampleResultsRoundtripStr} = testUtils.getProtoRoundTrip();
27
- const sampleResultsStr =
28
- fs.readFileSync(LH_ROOT + '/lighthouse-core/test/results/sample_v2.json', 'utf-8');
29
-
30
- /* eslint-env jest */
31
-
32
- describe('PSI', () => {
33
- let document;
34
- beforeAll(() => {
35
- global.Util = Util;
36
- global.I18n = I18n;
37
- global.DOM = DOM;
38
- global.CategoryRenderer = CategoryRenderer;
39
- global.DetailsRenderer = DetailsRenderer;
40
- global.PerformanceCategoryRenderer = PerformanceCategoryRenderer;
41
- global.CriticalRequestChainRenderer = CriticalRequestChainRenderer;
42
- global.ElementScreenshotRenderer = ElementScreenshotRenderer;
43
- global.ReportUIFeatures = ReportUIFeatures;
44
-
45
- const {window} = new jsdom.JSDOM();
46
- document = window.document;
47
- });
48
-
49
- afterAll(() => {
50
- global.I18n = undefined;
51
- global.Util = undefined;
52
- global.DOM = undefined;
53
- global.CategoryRenderer = undefined;
54
- global.DetailsRenderer = undefined;
55
- global.PerformanceCategoryRenderer = undefined;
56
- global.CriticalRequestChainRenderer = undefined;
57
- global.ElementScreenshotRenderer = undefined;
58
- global.ReportUIFeatures = undefined;
59
- });
60
-
61
- describe('psi prepareLabData helpers', () => {
62
- describe('prepareLabData', () => {
63
- itIfProtoExists('succeeds with LHResult object (roundtrip) input', () => {
64
- const roundTripLHResult = /** @type {LH.Result} */ JSON.parse(sampleResultsRoundtripStr);
65
- const result = prepareLabData(roundTripLHResult, document);
66
-
67
- // Check that the report exists and has some content.
68
- assert.ok(result.perfCategoryEl instanceof document.defaultView.Element);
69
- assert.ok(result.perfCategoryEl.outerHTML.length > 50000, 'perfCategory HTML is populated');
70
- // Assume using default locale.
71
- const title = result.perfCategoryEl.querySelector('.lh-audit-group--metrics')
72
- .querySelector('.lh-audit-group__title').textContent;
73
- assert.equal(title, Util.UIStrings.labDataTitle);
74
- });
75
-
76
- it('succeeds with stringified LHResult input', () => {
77
- const result = prepareLabData(sampleResultsStr, document);
78
- assert.ok(result.scoreGaugeEl instanceof document.defaultView.Element);
79
- assert.equal(result.scoreGaugeEl.querySelector('.lh-gauge__wrapper').href, '');
80
- assert.ok(result.scoreGaugeEl.outerHTML.includes('<svg'), 'score gauge comes with SVG');
81
-
82
- assert.ok(result.perfCategoryEl instanceof document.defaultView.Element);
83
- assert.ok(result.perfCategoryEl.outerHTML.length > 50000, 'perfCategory HTML is populated');
84
-
85
- assert.equal(typeof result.finalScreenshotDataUri, 'string');
86
- assert.ok(result.finalScreenshotDataUri.startsWith('data:image/jpeg;base64,'));
87
- });
88
-
89
- it('throws if there is no perf category', () => {
90
- const lhrWithoutPerf = JSON.parse(sampleResultsStr);
91
- delete lhrWithoutPerf.categories.performance;
92
- const lhrWithoutPerfStr = JSON.stringify(lhrWithoutPerf);
93
-
94
- assert.throws(() => {
95
- prepareLabData(lhrWithoutPerfStr, document);
96
- }, /no performance category/i);
97
- });
98
-
99
- it('throws if there is no category groups', () => {
100
- const lhrWithoutGroups = JSON.parse(sampleResultsStr);
101
- delete lhrWithoutGroups.categoryGroups;
102
- const lhrWithoutGroupsStr = JSON.stringify(lhrWithoutGroups);
103
-
104
- assert.throws(() => {
105
- prepareLabData(lhrWithoutGroupsStr, document);
106
- }, /no category groups/i);
107
- });
108
-
109
- it('includes custom title and description', () => {
110
- const {perfCategoryEl} = prepareLabData(sampleResultsStr, document);
111
- const metricsGroupEl = perfCategoryEl.querySelector('.lh-audit-group--metrics');
112
-
113
- // Assume using default locale.
114
- // Replacing markdown because ".textContent" will be post-markdown.
115
- const expectedDescription = Util.UIStrings.lsPerformanceCategoryDescription
116
- .replace('[Lighthouse](https://developers.google.com/web/tools/lighthouse/)', 'Lighthouse');
117
-
118
- // Assume using default locale.
119
- const title = metricsGroupEl.querySelector('.lh-audit-group__title').textContent;
120
- const description =
121
- metricsGroupEl.querySelector('.lh-audit-group__description').textContent;
122
- assert.equal(title, Util.UIStrings.labDataTitle);
123
- assert.equal(description, expectedDescription);
124
- });
125
- });
126
- });
127
-
128
- describe('_getFinalScreenshot', () => {
129
- it('gets a datauri as a string', () => {
130
- const datauri = prepareLabData(sampleResultsStr, document).finalScreenshotDataUri;
131
- assert.equal(typeof datauri, 'string');
132
- assert.ok(datauri.startsWith('data:image/jpeg;base64,'));
133
- });
134
-
135
- it('returns null if there is no final-screenshot audit', () => {
136
- const clonedResults = JSON.parse(sampleResultsStr);
137
- delete clonedResults.audits['final-screenshot'];
138
- const LHResultJsonString = JSON.stringify(clonedResults);
139
- const datauri = prepareLabData(LHResultJsonString, document).finalScreenshotDataUri;
140
- assert.equal(datauri, null);
141
- });
142
- });
143
- });