lighthouse 8.0.0-dev.20210709 → 8.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 (299) hide show
  1. package/docs/architecture.md +101 -0
  2. package/docs/authenticated-pages.md +44 -0
  3. package/docs/bug-labels.md +35 -0
  4. package/docs/configuration.md +213 -0
  5. package/docs/emulation.md +32 -0
  6. package/docs/error-reporting.md +42 -0
  7. package/docs/hacking-tips.md +55 -0
  8. package/docs/headless-chrome.md +119 -0
  9. package/docs/lantern.md +55 -0
  10. package/docs/new-audits.md +99 -0
  11. package/docs/performance-budgets.md +187 -0
  12. package/docs/plugins.md +374 -0
  13. package/docs/puppeteer.md +95 -0
  14. package/docs/readme.md +164 -0
  15. package/docs/recipes/auth/README.md +129 -0
  16. package/docs/recipes/auth/example-lh-auth.js +81 -0
  17. package/docs/recipes/auth/package.json +11 -0
  18. package/docs/recipes/auth/server/public/dashboard-unauthenticated.html +21 -0
  19. package/docs/recipes/auth/server/public/dashboard.html +25 -0
  20. package/docs/recipes/auth/server/public/home-unauthenticated.html +27 -0
  21. package/docs/recipes/auth/server/public/home.html +17 -0
  22. package/docs/recipes/auth/server/public/unauthenticated.html +22 -0
  23. package/docs/recipes/auth/server/server.js +85 -0
  24. package/docs/recipes/custom-audit/custom-config.js +36 -0
  25. package/docs/recipes/custom-audit/package.json +8 -0
  26. package/docs/recipes/custom-audit/readme.md +32 -0
  27. package/docs/recipes/custom-audit/searchable-audit.js +46 -0
  28. package/docs/recipes/custom-audit/searchable-gatherer.js +32 -0
  29. package/docs/recipes/custom-gatherer-puppeteer/custom-audit.js +34 -0
  30. package/{root.js → docs/recipes/custom-gatherer-puppeteer/custom-config.js} +23 -2
  31. package/docs/recipes/custom-gatherer-puppeteer/custom-gatherer.js +51 -0
  32. package/docs/recipes/custom-gatherer-puppeteer/package.json +13 -0
  33. package/docs/recipes/custom-gatherer-puppeteer/readme.md +7 -0
  34. package/docs/recipes/custom-gatherer-puppeteer/test.sh +9 -0
  35. package/docs/recipes/gulp/gulpfile.js +79 -0
  36. package/docs/recipes/gulp/package.json +12 -0
  37. package/docs/recipes/gulp/public/index.html +22 -0
  38. package/docs/recipes/gulp/readme.md +6 -0
  39. package/docs/recipes/integration-test/README.md +14 -0
  40. package/docs/recipes/integration-test/example-lh-auth.test.js +160 -0
  41. package/docs/recipes/integration-test/package.json +9 -0
  42. package/docs/recipes/lighthouse-plugin-example/audits/preload-as.js +46 -0
  43. package/docs/recipes/lighthouse-plugin-example/package.json +11 -0
  44. package/docs/recipes/lighthouse-plugin-example/plugin-recipe-screenshot.png +0 -0
  45. package/docs/recipes/lighthouse-plugin-example/plugin.js +24 -0
  46. package/docs/recipes/lighthouse-plugin-example/readme.md +53 -0
  47. package/docs/releasing.md +164 -0
  48. package/docs/scoring.md +79 -0
  49. package/docs/throttling.md +150 -0
  50. package/docs/understanding-results.md +209 -0
  51. package/docs/v8-perf-faq.md +244 -0
  52. package/docs/variability.md +150 -0
  53. package/jest.config.js +0 -3
  54. package/lighthouse-cli/bin.js +8 -6
  55. package/lighthouse-core/audits/accessibility/aria-command-name.js +1 -1
  56. package/lighthouse-core/audits/accessibility/aria-meter-name.js +1 -1
  57. package/lighthouse-core/audits/accessibility/aria-progressbar-name.js +1 -1
  58. package/lighthouse-core/audits/accessibility/aria-tooltip-name.js +1 -1
  59. package/lighthouse-core/audits/accessibility/aria-treeitem-name.js +1 -1
  60. package/lighthouse-core/audits/apple-touch-icon.js +0 -1
  61. package/lighthouse-core/audits/audit.js +3 -3
  62. package/lighthouse-core/audits/autocomplete.js +2 -2
  63. package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +14 -29
  64. package/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js +2 -3
  65. package/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js +1 -1
  66. package/lighthouse-core/audits/byte-efficiency/legacy-javascript.js +2 -3
  67. package/lighthouse-core/audits/byte-efficiency/modern-image-formats.js +15 -55
  68. package/lighthouse-core/audits/byte-efficiency/offscreen-images.js +4 -8
  69. package/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js +8 -15
  70. package/lighthouse-core/audits/byte-efficiency/total-byte-weight.js +9 -10
  71. package/lighthouse-core/audits/byte-efficiency/unminified-css.js +1 -1
  72. package/lighthouse-core/audits/byte-efficiency/unminified-javascript.js +1 -1
  73. package/lighthouse-core/audits/byte-efficiency/unused-css-rules.js +1 -1
  74. package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -2
  75. package/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js +2 -2
  76. package/lighthouse-core/audits/byte-efficiency/uses-optimized-images.js +1 -2
  77. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +24 -46
  78. package/lighthouse-core/audits/byte-efficiency/uses-text-compression.js +1 -1
  79. package/lighthouse-core/audits/critical-request-chains.js +0 -1
  80. package/lighthouse-core/audits/csp-xss.js +1 -1
  81. package/lighthouse-core/audits/diagnostics.js +0 -1
  82. package/lighthouse-core/audits/dobetterweb/geolocation-on-start.js +0 -1
  83. package/lighthouse-core/audits/dobetterweb/inspector-issues.js +1 -1
  84. package/lighthouse-core/audits/dobetterweb/notification-on-start.js +0 -1
  85. package/lighthouse-core/audits/dobetterweb/uses-http2.js +0 -1
  86. package/lighthouse-core/audits/final-screenshot.js +4 -8
  87. package/lighthouse-core/audits/font-display.js +0 -1
  88. package/lighthouse-core/audits/installable-manifest.js +3 -4
  89. package/lighthouse-core/audits/largest-contentful-paint-element.js +0 -1
  90. package/lighthouse-core/audits/long-tasks.js +1 -1
  91. package/lighthouse-core/audits/maskable-icon.js +0 -1
  92. package/lighthouse-core/audits/metrics/first-contentful-paint-3g.js +2 -4
  93. package/lighthouse-core/audits/metrics/first-contentful-paint.js +2 -4
  94. package/lighthouse-core/audits/metrics/first-meaningful-paint.js +2 -4
  95. package/lighthouse-core/audits/metrics/interactive.js +2 -4
  96. package/lighthouse-core/audits/metrics/largest-contentful-paint.js +2 -4
  97. package/lighthouse-core/audits/metrics/max-potential-fid.js +2 -4
  98. package/lighthouse-core/audits/metrics/speed-index.js +2 -4
  99. package/lighthouse-core/audits/metrics/total-blocking-time.js +2 -10
  100. package/lighthouse-core/audits/metrics.js +2 -4
  101. package/lighthouse-core/audits/performance-budget.js +0 -1
  102. package/lighthouse-core/audits/predictive-perf.js +6 -9
  103. package/lighthouse-core/audits/preload-fonts.js +1 -11
  104. package/lighthouse-core/audits/preload-lcp-image.js +5 -18
  105. package/lighthouse-core/audits/redirects.js +8 -10
  106. package/lighthouse-core/audits/screenshot-thumbnails.js +13 -28
  107. package/lighthouse-core/audits/seo/canonical.js +1 -2
  108. package/lighthouse-core/audits/seo/font-size.js +4 -4
  109. package/lighthouse-core/audits/seo/hreflang.js +2 -3
  110. package/lighthouse-core/audits/seo/http-status-code.js +16 -21
  111. package/lighthouse-core/audits/seo/is-crawlable.js +3 -4
  112. package/lighthouse-core/audits/seo/robots-txt.js +2 -2
  113. package/lighthouse-core/audits/seo/tap-targets.js +5 -5
  114. package/lighthouse-core/audits/server-response-time.js +2 -20
  115. package/lighthouse-core/audits/splash-screen.js +0 -1
  116. package/lighthouse-core/audits/themed-omnibox.js +0 -1
  117. package/lighthouse-core/audits/third-party-facades.js +0 -1
  118. package/lighthouse-core/audits/third-party-summary.js +3 -1
  119. package/lighthouse-core/audits/timing-budget.js +2 -4
  120. package/lighthouse-core/audits/uses-rel-preconnect.js +9 -14
  121. package/lighthouse-core/audits/uses-rel-preload.js +2 -13
  122. package/lighthouse-core/computed/main-thread-tasks.js +2 -2
  123. package/lighthouse-core/computed/metrics/cumulative-layout-shift.js +3 -3
  124. package/lighthouse-core/computed/metrics/first-contentful-paint-all-frames.js +6 -6
  125. package/lighthouse-core/computed/metrics/first-contentful-paint.js +8 -9
  126. package/lighthouse-core/computed/metrics/first-meaningful-paint.js +9 -10
  127. package/lighthouse-core/computed/metrics/interactive.js +24 -25
  128. package/lighthouse-core/computed/metrics/lantern-first-contentful-paint.js +6 -6
  129. package/lighthouse-core/computed/metrics/lantern-first-meaningful-paint.js +6 -6
  130. package/lighthouse-core/computed/metrics/lantern-largest-contentful-paint.js +6 -6
  131. package/lighthouse-core/computed/metrics/lantern-metric.js +8 -16
  132. package/lighthouse-core/computed/metrics/largest-contentful-paint-all-frames.js +7 -7
  133. package/lighthouse-core/computed/metrics/largest-contentful-paint.js +9 -10
  134. package/lighthouse-core/computed/metrics/max-potential-fid.js +11 -8
  135. package/lighthouse-core/computed/metrics/metric.js +5 -32
  136. package/lighthouse-core/computed/metrics/speed-index.js +5 -6
  137. package/lighthouse-core/computed/metrics/timing-summary.js +45 -55
  138. package/lighthouse-core/computed/metrics/total-blocking-time.js +29 -36
  139. package/lighthouse-core/computed/page-dependency-graph.js +14 -14
  140. package/lighthouse-core/computed/resource-summary.js +7 -3
  141. package/lighthouse-core/computed/speedline.js +3 -3
  142. package/lighthouse-core/computed/trace-of-tab.js +86 -15
  143. package/lighthouse-core/computed/user-timings.js +5 -5
  144. package/lighthouse-core/config/default-config.js +0 -1
  145. package/lighthouse-core/fraggle-rock/config/config.js +7 -9
  146. package/lighthouse-core/fraggle-rock/config/default-config.js +2 -40
  147. package/lighthouse-core/fraggle-rock/config/filters.js +6 -39
  148. package/lighthouse-core/fraggle-rock/config/validation.js +4 -4
  149. package/lighthouse-core/fraggle-rock/gather/base-artifacts.js +19 -54
  150. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +10 -21
  151. package/lighthouse-core/fraggle-rock/gather/runner-helpers.js +2 -2
  152. package/lighthouse-core/fraggle-rock/gather/snapshot-runner.js +2 -2
  153. package/lighthouse-core/fraggle-rock/gather/timespan-runner.js +2 -2
  154. package/lighthouse-core/gather/driver/prepare.js +0 -3
  155. package/lighthouse-core/gather/fetcher.js +2 -0
  156. package/lighthouse-core/gather/gather-runner.js +14 -2
  157. package/lighthouse-core/gather/gatherers/image-elements.js +61 -24
  158. package/lighthouse-core/gather/gatherers/inspector-issues.js +2 -2
  159. package/lighthouse-core/gather/gatherers/script-elements.js +12 -45
  160. package/lighthouse-core/gather/gatherers/seo/font-size.js +5 -5
  161. package/lighthouse-core/gather/gatherers/seo/tap-targets.js +12 -64
  162. package/lighthouse-core/gather/gatherers/service-worker.js +3 -20
  163. package/lighthouse-core/gather/gatherers/trace-compat.js +1 -1
  164. package/lighthouse-core/gather/gatherers/trace-elements.js +3 -15
  165. package/lighthouse-core/gather/gatherers/trace.js +4 -13
  166. package/lighthouse-core/gather/gatherers/viewport-dimensions.js +1 -1
  167. package/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js +2 -13
  168. package/lighthouse-core/lib/emulation.js +2 -0
  169. package/lighthouse-core/lib/i18n/i18n.js +2 -2
  170. package/lighthouse-core/lib/i18n/locales/ar-XB.json +141 -141
  171. package/lighthouse-core/lib/i18n/locales/ar.json +143 -143
  172. package/lighthouse-core/lib/i18n/locales/bg.json +143 -143
  173. package/lighthouse-core/lib/i18n/locales/ca.json +141 -141
  174. package/lighthouse-core/lib/i18n/locales/cs.json +141 -141
  175. package/lighthouse-core/lib/i18n/locales/da.json +141 -141
  176. package/lighthouse-core/lib/i18n/locales/de.json +142 -142
  177. package/lighthouse-core/lib/i18n/locales/el.json +141 -141
  178. package/lighthouse-core/lib/i18n/locales/en-GB.json +141 -141
  179. package/lighthouse-core/lib/i18n/locales/en-US.ctc.json +6659 -0
  180. package/lighthouse-core/lib/i18n/locales/en-US.json +144 -150
  181. package/lighthouse-core/lib/i18n/locales/en-XA.json +141 -141
  182. package/lighthouse-core/lib/i18n/locales/en-XL.ctc.json +6628 -0
  183. package/lighthouse-core/lib/i18n/locales/en-XL.json +144 -150
  184. package/lighthouse-core/lib/i18n/locales/es-419.json +141 -141
  185. package/lighthouse-core/lib/i18n/locales/es.json +141 -141
  186. package/lighthouse-core/lib/i18n/locales/fi.json +143 -143
  187. package/lighthouse-core/lib/i18n/locales/fil.json +142 -142
  188. package/lighthouse-core/lib/i18n/locales/fr.json +141 -141
  189. package/lighthouse-core/lib/i18n/locales/he.json +142 -142
  190. package/lighthouse-core/lib/i18n/locales/hi.json +143 -143
  191. package/lighthouse-core/lib/i18n/locales/hr.json +141 -141
  192. package/lighthouse-core/lib/i18n/locales/hu.json +143 -143
  193. package/lighthouse-core/lib/i18n/locales/id.json +143 -143
  194. package/lighthouse-core/lib/i18n/locales/it.json +143 -143
  195. package/lighthouse-core/lib/i18n/locales/ja.json +143 -143
  196. package/lighthouse-core/lib/i18n/locales/ko.json +143 -143
  197. package/lighthouse-core/lib/i18n/locales/lt.json +143 -143
  198. package/lighthouse-core/lib/i18n/locales/lv.json +143 -143
  199. package/lighthouse-core/lib/i18n/locales/nl.json +141 -141
  200. package/lighthouse-core/lib/i18n/locales/no.json +141 -141
  201. package/lighthouse-core/lib/i18n/locales/pl.json +141 -141
  202. package/lighthouse-core/lib/i18n/locales/pt-PT.json +141 -141
  203. package/lighthouse-core/lib/i18n/locales/pt.json +141 -141
  204. package/lighthouse-core/lib/i18n/locales/ro.json +144 -144
  205. package/lighthouse-core/lib/i18n/locales/ru.json +143 -143
  206. package/lighthouse-core/lib/i18n/locales/sk.json +142 -142
  207. package/lighthouse-core/lib/i18n/locales/sl.json +141 -141
  208. package/lighthouse-core/lib/i18n/locales/sr-Latn.json +143 -143
  209. package/lighthouse-core/lib/i18n/locales/sr.json +143 -143
  210. package/lighthouse-core/lib/i18n/locales/sv.json +142 -142
  211. package/lighthouse-core/lib/i18n/locales/ta.json +141 -141
  212. package/lighthouse-core/lib/i18n/locales/te.json +143 -143
  213. package/lighthouse-core/lib/i18n/locales/th.json +143 -143
  214. package/lighthouse-core/lib/i18n/locales/tr.json +143 -143
  215. package/lighthouse-core/lib/i18n/locales/uk.json +141 -141
  216. package/lighthouse-core/lib/i18n/locales/vi.json +143 -143
  217. package/lighthouse-core/lib/i18n/locales/zh-HK.json +141 -141
  218. package/lighthouse-core/lib/i18n/locales/zh-TW.json +143 -143
  219. package/lighthouse-core/lib/i18n/locales/zh.json +143 -143
  220. package/lighthouse-core/lib/lh-error.js +2 -2
  221. package/lighthouse-core/lib/minify-trace.js +1 -1
  222. package/lighthouse-core/lib/network-request.js +1 -17
  223. package/lighthouse-core/lib/page-functions.js +5 -6
  224. package/lighthouse-core/lib/rect-helpers.js +3 -3
  225. package/lighthouse-core/lib/sd-validation/assets/jsonldcontext.json +7137 -0
  226. package/lighthouse-core/lib/sd-validation/assets/schema-tree.json +9900 -0
  227. package/{report/report-assets.js → lighthouse-core/lib/sd-validation/helpers/walk-object.js} +20 -12
  228. package/lighthouse-core/lib/sd-validation/json-expander.js +56 -0
  229. package/lighthouse-core/lib/sd-validation/json-linter.js +49 -0
  230. package/lighthouse-core/lib/sd-validation/jsonld-keyword-validator.js +50 -0
  231. package/lighthouse-core/lib/sd-validation/line-number-from-jsonld-path.js +60 -0
  232. package/lighthouse-core/lib/sd-validation/schema-validator.js +146 -0
  233. package/lighthouse-core/lib/sd-validation/scripts/download-jsonldcontext.js +30 -0
  234. package/lighthouse-core/lib/sd-validation/scripts/generate-schema-tree.js +97 -0
  235. package/lighthouse-core/lib/sd-validation/sd-validation.js +77 -0
  236. package/lighthouse-core/lib/tappable-rects.js +1 -1
  237. package/lighthouse-core/lib/tracehouse/trace-processor.js +42 -116
  238. package/lighthouse-core/lib/url-shim.js +2 -29
  239. package/lighthouse-core/report/html/html-report-assets.js +38 -0
  240. package/{report/README.md → lighthouse-core/report/html/readme.md} +11 -7
  241. package/{report → lighthouse-core/report/html}/renderer/category-renderer.js +0 -0
  242. package/{report → lighthouse-core/report/html}/renderer/crc-details-renderer.js +0 -0
  243. package/{report → lighthouse-core/report/html}/renderer/details-renderer.js +1 -1
  244. package/{report → lighthouse-core/report/html}/renderer/dom.js +0 -0
  245. package/{report → lighthouse-core/report/html}/renderer/element-screenshot-renderer.js +0 -0
  246. package/{report → lighthouse-core/report/html}/renderer/i18n.js +1 -1
  247. package/{report → lighthouse-core/report/html}/renderer/logger.js +0 -0
  248. package/{report → lighthouse-core/report/html}/renderer/performance-category-renderer.js +0 -0
  249. package/{report → lighthouse-core/report/html}/renderer/psi.js +0 -0
  250. package/{report → lighthouse-core/report/html}/renderer/pwa-category-renderer.js +0 -0
  251. package/{report → lighthouse-core/report/html}/renderer/report-renderer.js +0 -0
  252. package/{report → lighthouse-core/report/html}/renderer/report-ui-features.js +3 -3
  253. package/{report → lighthouse-core/report/html}/renderer/snippet-renderer.js +0 -0
  254. package/{report → lighthouse-core/report/html}/renderer/text-encoding.js +0 -0
  255. package/{report → lighthouse-core/report/html}/renderer/util.js +4 -7
  256. package/{report/assets/styles.css → lighthouse-core/report/html/report-styles.css} +0 -0
  257. package/{report/assets/standalone-template.html → lighthouse-core/report/html/report-template.html} +41 -1
  258. package/{report/assets → lighthouse-core/report/html}/templates.html +0 -0
  259. package/{report → lighthouse-core/report}/report-generator.js +1 -1
  260. package/lighthouse-core/runner.js +1 -1
  261. package/package.json +12 -13
  262. package/readme.md +2 -2
  263. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +2 -3
  264. package/third-party/chromium-synchronization/installability-errors-test.js +2 -2
  265. package/third-party/download-content-shell/download-content-shell.js +1 -2
  266. package/third-party/snyk/snapshot.json +1 -1
  267. package/tsconfig.json +1 -0
  268. package/types/artifacts.d.ts +21 -41
  269. package/types/audit.d.ts +0 -2
  270. package/types/config.d.ts +2 -16
  271. package/types/externs.d.ts +0 -1
  272. package/types/gatherer.d.ts +13 -13
  273. package/types/html-renderer.d.ts +14 -14
  274. package/types/i18n.d.ts +1 -1
  275. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images-snapshot.js +0 -94
  276. package/lighthouse-core/computed/image-records.js +0 -62
  277. package/lighthouse-core/computed/metrics/navigation-metric.js +0 -46
  278. package/lighthouse-core/computed/processed-navigation.js +0 -21
  279. package/lighthouse-core/computed/processed-trace.js +0 -21
  280. package/lighthouse-core/gather/gatherers/gather-context.js +0 -25
  281. package/lighthouse-core/gather/gatherers/host-form-factor.js +0 -31
  282. package/lighthouse-core/gather/gatherers/host-user-agent.js +0 -29
  283. package/lighthouse-core/lib/lh-trace-processor.js +0 -46
  284. package/report/clients/standalone.js +0 -52
  285. package/report/test/renderer/category-renderer-test.js +0 -488
  286. package/report/test/renderer/crc-details-renderer-test.js +0 -115
  287. package/report/test/renderer/details-renderer-test.js +0 -843
  288. package/report/test/renderer/dom-test.js +0 -157
  289. package/report/test/renderer/element-screenshot-renderer-test.js +0 -189
  290. package/report/test/renderer/i18n-test.js +0 -146
  291. package/report/test/renderer/performance-category-renderer-test.js +0 -332
  292. package/report/test/renderer/psi-test.js +0 -152
  293. package/report/test/renderer/pwa-category-renderer-test.js +0 -303
  294. package/report/test/renderer/report-renderer-test.js +0 -325
  295. package/report/test/renderer/report-ui-features-test.js +0 -572
  296. package/report/test/renderer/snippet-renderer-test.js +0 -291
  297. package/report/test/renderer/text-encoding-test.js +0 -41
  298. package/report/test/renderer/util-test.js +0 -388
  299. package/report/test/report-generator-test.js +0 -145
@@ -1,388 +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
- const assert = require('assert').strict;
9
- const Util = require('../../renderer/util.js');
10
- const I18n = require('../../renderer/i18n.js');
11
- const sampleResult = require('../../../lighthouse-core/test/results/sample_v2.json');
12
-
13
- /* eslint-env jest */
14
-
15
- describe('util helpers', () => {
16
- beforeEach(() => {
17
- Util.i18n = new I18n('en', {...Util.UIStrings});
18
- });
19
-
20
- afterEach(() => {
21
- Util.i18n = undefined;
22
- });
23
-
24
- it('calculates a score ratings', () => {
25
- assert.equal(Util.calculateRating(0.0), 'fail');
26
- assert.equal(Util.calculateRating(0.10), 'fail');
27
- assert.equal(Util.calculateRating(0.45), 'fail');
28
- assert.equal(Util.calculateRating(0.5), 'average');
29
- assert.equal(Util.calculateRating(0.75), 'average');
30
- assert.equal(Util.calculateRating(0.80), 'average');
31
- assert.equal(Util.calculateRating(0.90), 'pass');
32
- assert.equal(Util.calculateRating(1.00), 'pass');
33
- });
34
-
35
- it('builds device emulation string', () => {
36
- const get = opts => Util.getEmulationDescriptions(opts).deviceEmulation;
37
- assert.equal(get({formFactor: 'mobile'}), 'Emulated Moto G4');
38
- assert.equal(get({formFactor: 'desktop'}), 'Emulated Desktop');
39
- });
40
-
41
- it('builds throttling strings when provided', () => {
42
- const descriptions = Util.getEmulationDescriptions({throttlingMethod: 'provided'});
43
- assert.equal(descriptions.cpuThrottling, 'Provided by environment');
44
- assert.equal(descriptions.networkThrottling, 'Provided by environment');
45
- });
46
-
47
- it('builds throttling strings when devtools', () => {
48
- const descriptions = Util.getEmulationDescriptions({
49
- throttlingMethod: 'devtools',
50
- throttling: {
51
- cpuSlowdownMultiplier: 4.5,
52
- requestLatencyMs: 565,
53
- downloadThroughputKbps: 1400.00000000001,
54
- uploadThroughputKbps: 600,
55
- },
56
- });
57
-
58
- // eslint-disable-next-line max-len
59
- assert.equal(descriptions.networkThrottling, '565\xa0ms HTTP RTT, 1,400\xa0Kbps down, 600\xa0Kbps up (DevTools)');
60
- assert.equal(descriptions.cpuThrottling, '4.5x slowdown (DevTools)');
61
- });
62
-
63
- it('builds throttling strings when simulate', () => {
64
- const descriptions = Util.getEmulationDescriptions({
65
- throttlingMethod: 'simulate',
66
- throttling: {
67
- cpuSlowdownMultiplier: 2,
68
- rttMs: 150,
69
- throughputKbps: 1600,
70
- },
71
- });
72
-
73
- // eslint-disable-next-line max-len
74
- assert.equal(descriptions.networkThrottling, '150\xa0ms TCP RTT, 1,600\xa0Kbps throughput (Simulated)');
75
- assert.equal(descriptions.cpuThrottling, '2x slowdown (Simulated)');
76
- });
77
-
78
- describe('#prepareReportResult', () => {
79
- describe('backward compatibility', () => {
80
- it('corrects underscored `notApplicable` scoreDisplayMode', () => {
81
- const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult));
82
-
83
- let notApplicableCount = 0;
84
- Object.values(clonedSampleResult.audits).forEach(audit => {
85
- if (audit.scoreDisplayMode === 'notApplicable') {
86
- notApplicableCount++;
87
- audit.scoreDisplayMode = 'not_applicable';
88
- }
89
- });
90
-
91
- assert.ok(notApplicableCount > 20); // Make sure something's being tested.
92
-
93
- // Original audit results should be restored.
94
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
95
-
96
- assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
97
- });
98
-
99
- it('corrects undefined auditDetails.type to `debugdata`', () => {
100
- const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult));
101
-
102
- // Delete debugdata details types.
103
- let undefinedCount = 0;
104
- for (const audit of Object.values(clonedSampleResult.audits)) {
105
- if (audit.details && audit.details.type === 'debugdata') {
106
- undefinedCount++;
107
- delete audit.details.type;
108
- }
109
- }
110
- assert.ok(undefinedCount > 4); // Make sure something's being tested.
111
- assert.notDeepStrictEqual(clonedSampleResult.audits, sampleResult.audits);
112
-
113
- // Original audit results should be restored.
114
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
115
- assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
116
- });
117
-
118
- it('corrects `diagnostic` auditDetails.type to `debugdata`', () => {
119
- const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult));
120
-
121
- // Change debugdata details types.
122
- let diagnosticCount = 0;
123
- for (const audit of Object.values(clonedSampleResult.audits)) {
124
- if (audit.details && audit.details.type === 'debugdata') {
125
- diagnosticCount++;
126
- audit.details.type = 'diagnostic';
127
- }
128
- }
129
- assert.ok(diagnosticCount > 4); // Make sure something's being tested.
130
- assert.notDeepStrictEqual(clonedSampleResult.audits, sampleResult.audits);
131
-
132
- // Original audit results should be restored.
133
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
134
- assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
135
- });
136
-
137
- it('corrects screenshots in the `filmstrip` auditDetails.type', () => {
138
- const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult));
139
-
140
- // Strip filmstrip screenshots of data URL prefix.
141
- let filmstripCount = 0;
142
- for (const audit of Object.values(clonedSampleResult.audits)) {
143
- if (audit.details && audit.details.type === 'filmstrip') {
144
- filmstripCount++;
145
- for (const screenshot of audit.details.items) {
146
- screenshot.data = screenshot.data.slice('data:image/jpeg;base64,'.length);
147
- }
148
- }
149
- }
150
- assert.ok(filmstripCount > 0); // Make sure something's being tested.
151
- assert.notDeepStrictEqual(clonedSampleResult.audits, sampleResult.audits);
152
-
153
- // Original audit results should be restored.
154
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
155
- assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
156
- });
157
- });
158
-
159
- it('appends stack pack descriptions to auditRefs', () => {
160
- const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult));
161
- const iconDataURL = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg"%3E%3C/svg%3E';
162
- clonedSampleResult.stackPacks = [{
163
- id: 'snackpack',
164
- title: 'SnackPack',
165
- iconDataURL,
166
- descriptions: {
167
- 'unused-css-rules': 'Consider using snacks in packs.',
168
- },
169
- }];
170
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
171
-
172
- const perfAuditRefs = preparedResult.categories.performance.auditRefs;
173
- const unusedCssRef = perfAuditRefs.find(ref => ref.id === 'unused-css-rules');
174
- assert.deepStrictEqual(unusedCssRef.stackPacks, [{
175
- title: 'SnackPack',
176
- iconDataURL,
177
- description: 'Consider using snacks in packs.',
178
- }]);
179
-
180
- // No stack pack on audit wth no stack pack.
181
- const interactiveRef = perfAuditRefs.find(ref => ref.id === 'interactive');
182
- assert.strictEqual(interactiveRef.stackPacks, undefined);
183
- });
184
- });
185
-
186
- describe('getTld', () => {
187
- it('returns the correct tld', () => {
188
- assert.equal(Util.getTld('example.com'), '.com');
189
- assert.equal(Util.getTld('example.co.uk'), '.co.uk');
190
- assert.equal(Util.getTld('example.com.br'), '.com.br');
191
- assert.equal(Util.getTld('example.tokyo.jp'), '.jp');
192
- });
193
- });
194
-
195
- describe('getRootDomain', () => {
196
- it('returns the correct rootDomain from a string', () => {
197
- assert.equal(Util.getRootDomain('https://www.example.com/index.html'), 'example.com');
198
- assert.equal(Util.getRootDomain('https://example.com'), 'example.com');
199
- assert.equal(Util.getRootDomain('https://www.example.co.uk'), 'example.co.uk');
200
- assert.equal(Util.getRootDomain('https://example.com.br/app/'), 'example.com.br');
201
- assert.equal(Util.getRootDomain('https://example.tokyo.jp'), 'tokyo.jp');
202
- assert.equal(Util.getRootDomain('https://sub.example.com'), 'example.com');
203
- assert.equal(Util.getRootDomain('https://sub.example.tokyo.jp'), 'tokyo.jp');
204
- assert.equal(Util.getRootDomain('http://localhost'), 'localhost');
205
- assert.equal(Util.getRootDomain('http://localhost:8080'), 'localhost');
206
- });
207
-
208
- it('returns the correct rootDomain from an URL object', () => {
209
- assert.equal(Util.getRootDomain(new URL('https://www.example.com/index.html')), 'example.com');
210
- assert.equal(Util.getRootDomain(new URL('https://example.com')), 'example.com');
211
- assert.equal(Util.getRootDomain(new URL('https://www.example.co.uk')), 'example.co.uk');
212
- assert.equal(Util.getRootDomain(new URL('https://example.com.br/app/')), 'example.com.br');
213
- assert.equal(Util.getRootDomain(new URL('https://example.tokyo.jp')), 'tokyo.jp');
214
- assert.equal(Util.getRootDomain(new URL('https://sub.example.com')), 'example.com');
215
- assert.equal(Util.getRootDomain(new URL('https://sub.example.tokyo.jp')), 'tokyo.jp');
216
- assert.equal(Util.getRootDomain(new URL('http://localhost')), 'localhost');
217
- assert.equal(Util.getRootDomain(new URL('http://localhost:8080')), 'localhost');
218
- });
219
- });
220
-
221
- describe('#splitMarkdownCodeSpans', () => {
222
- it('handles strings with no backticks in them', () => {
223
- expect(Util.splitMarkdownCodeSpans('regular text')).toEqual([
224
- {isCode: false, text: 'regular text'},
225
- ]);
226
- });
227
-
228
- it('does not split on a single backtick', () => {
229
- expect(Util.splitMarkdownCodeSpans('regular `text')).toEqual([
230
- {isCode: false, text: 'regular `text'},
231
- ]);
232
- });
233
-
234
- it('splits on backticked code', () => {
235
- expect(Util.splitMarkdownCodeSpans('regular `code` text')).toEqual([
236
- {isCode: false, text: 'regular '},
237
- {isCode: true, text: 'code'},
238
- {isCode: false, text: ' text'},
239
- ]);
240
- });
241
-
242
- it('splits on backticked code at the beginning of the string', () => {
243
- expect(Util.splitMarkdownCodeSpans('`start code` regular text')).toEqual([
244
- {isCode: true, text: 'start code'},
245
- {isCode: false, text: ' regular text'},
246
- ]);
247
- });
248
-
249
- it('splits on backticked code at the end of the string', () => {
250
- expect(Util.splitMarkdownCodeSpans('regular text `end code`')).toEqual([
251
- {isCode: false, text: 'regular text '},
252
- {isCode: true, text: 'end code'},
253
- ]);
254
- });
255
-
256
- it('does not split on a single backtick after split out backticked code', () => {
257
- expect(Util.splitMarkdownCodeSpans('regular text `code` and more `text')).toEqual([
258
- {isCode: false, text: 'regular text '},
259
- {isCode: true, text: 'code'},
260
- {isCode: false, text: ' and more `text'},
261
- ]);
262
- });
263
-
264
- it('splits on two instances of backticked code', () => {
265
- expect(Util.splitMarkdownCodeSpans('regular text `code` more text `and more code`')).toEqual([
266
- {isCode: false, text: 'regular text '},
267
- {isCode: true, text: 'code'},
268
- {isCode: false, text: ' more text '},
269
- {isCode: true, text: 'and more code'},
270
- ]);
271
- });
272
-
273
- it('splits on two directly adjacent instances of backticked code', () => {
274
- // eslint-disable-next-line max-len
275
- expect(Util.splitMarkdownCodeSpans('regular text `first code``second code` end text')).toEqual([
276
- {isCode: false, text: 'regular text '},
277
- {isCode: true, text: 'first code'},
278
- {isCode: true, text: 'second code'},
279
- {isCode: false, text: ' end text'},
280
- ]);
281
- });
282
-
283
- it('handles text only within backticks', () => {
284
- expect(Util.splitMarkdownCodeSpans('`first code``second code`')).toEqual([
285
- {isCode: true, text: 'first code'},
286
- {isCode: true, text: 'second code'},
287
- ]);
288
- });
289
-
290
- it('splits on two instances of backticked code separated by only a space', () => {
291
- // eslint-disable-next-line max-len
292
- expect(Util.splitMarkdownCodeSpans('`first code` `second code`')).toEqual([
293
- {isCode: true, text: 'first code'},
294
- {isCode: false, text: ' '},
295
- {isCode: true, text: 'second code'},
296
- ]);
297
- });
298
- });
299
-
300
- describe('#splitMarkdownLink', () => {
301
- it('handles strings with no links in them', () => {
302
- expect(Util.splitMarkdownLink('some text')).toEqual([
303
- {isLink: false, text: 'some text'},
304
- ]);
305
- });
306
-
307
- it('does not split on an incomplete markdown link', () => {
308
- expect(Util.splitMarkdownLink('some [not link text](text')).toEqual([
309
- {isLink: false, text: 'some [not link text](text'},
310
- ]);
311
- });
312
-
313
- it('splits on a markdown link', () => {
314
- expect(Util.splitMarkdownLink('some [link text](https://example.com) text')).toEqual([
315
- {isLink: false, text: 'some '},
316
- {isLink: true, text: 'link text', linkHref: 'https://example.com'},
317
- {isLink: false, text: ' text'},
318
- ]);
319
- });
320
-
321
- it('splits on an http markdown link', () => {
322
- expect(Util.splitMarkdownLink('you should [totally click here](http://never-mitm.com) now')).toEqual([
323
- {isLink: false, text: 'you should '},
324
- {isLink: true, text: 'totally click here', linkHref: 'http://never-mitm.com'},
325
- {isLink: false, text: ' now'},
326
- ]);
327
- });
328
-
329
- it('does not split on a non-http/https link', () => {
330
- expect(Util.splitMarkdownLink('some [link text](ftp://example.com) text')).toEqual([
331
- {isLink: false, text: 'some [link text](ftp://example.com) text'},
332
- ]);
333
- });
334
-
335
- it('does not split on a malformed markdown link', () => {
336
- expect(Util.splitMarkdownLink('some [link ]text](https://example.com')).toEqual([
337
- {isLink: false, text: 'some [link ]text](https://example.com'},
338
- ]);
339
-
340
- expect(Util.splitMarkdownLink('some [link text] (https://example.com')).toEqual([
341
- {isLink: false, text: 'some [link text] (https://example.com'},
342
- ]);
343
- });
344
-
345
- it('does not split on empty link text', () => {
346
- expect(Util.splitMarkdownLink('some [](https://example.com) empty link')).toEqual([
347
- {isLink: false, text: 'some [](https://example.com) empty link'},
348
- ]);
349
- });
350
-
351
- it('splits on a markdown link at the beginning of a string', () => {
352
- expect(Util.splitMarkdownLink('[link text](https://example.com) end text')).toEqual([
353
- {isLink: true, text: 'link text', linkHref: 'https://example.com'},
354
- {isLink: false, text: ' end text'},
355
- ]);
356
- });
357
-
358
- it('splits on a markdown link at the end of a string', () => {
359
- expect(Util.splitMarkdownLink('start text [link text](https://example.com)')).toEqual([
360
- {isLink: false, text: 'start text '},
361
- {isLink: true, text: 'link text', linkHref: 'https://example.com'},
362
- ]);
363
- });
364
-
365
- it('handles a string consisting only of a markdown link', () => {
366
- expect(Util.splitMarkdownLink(`[I'm only a link](https://example.com)`)).toEqual([
367
- {isLink: true, text: `I'm only a link`, linkHref: 'https://example.com'},
368
- ]);
369
- });
370
-
371
- it('handles a string starting and ending with a markdown link', () => {
372
- expect(Util.splitMarkdownLink('[first link](https://first.com) other text [second link](https://second.com)')).toEqual([
373
- {isLink: true, text: 'first link', linkHref: 'https://first.com'},
374
- {isLink: false, text: ' other text '},
375
- {isLink: true, text: 'second link', linkHref: 'https://second.com'},
376
- ]);
377
- });
378
-
379
- it('handles a string with adjacent markdown links', () => {
380
- expect(Util.splitMarkdownLink('start text [first link](https://first.com)[second link](https://second.com) and scene')).toEqual([
381
- {isLink: false, text: 'start text '},
382
- {isLink: true, text: 'first link', linkHref: 'https://first.com'},
383
- {isLink: true, text: 'second link', linkHref: 'https://second.com'},
384
- {isLink: false, text: ' and scene'},
385
- ]);
386
- });
387
- });
388
- });
@@ -1,145 +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
- const assert = require('assert').strict;
9
- const fs = require('fs');
10
- const jsdom = require('jsdom');
11
- const ReportGenerator = require('../report-generator.js');
12
- const reportAssets = require('../report-assets.js');
13
- const sampleResults = require('../../lighthouse-core/test/results/sample_v2.json');
14
- const csvValidator = require('csv-validator');
15
-
16
- /* eslint-env jest */
17
-
18
- describe('ReportGenerator', () => {
19
- describe('#replaceStrings', () => {
20
- it('should replace all occurrences', () => {
21
- const source = '%foo! %foo %bar!';
22
- const result = ReportGenerator.replaceStrings(source, [
23
- {search: '%foo', replacement: 'hey'},
24
- {search: '%bar', replacement: 'you'},
25
- ]);
26
-
27
- assert.equal(result, 'hey! hey you!');
28
- });
29
-
30
- it('should not replace serial occurences', () => {
31
- const result = ReportGenerator.replaceStrings('%1', [
32
- {search: '%1', replacement: '%2'},
33
- {search: '%2', replacement: 'pwnd'},
34
- ]);
35
-
36
- assert.equal(result, '%2');
37
- });
38
- });
39
-
40
- describe('#generateHtmlReport', () => {
41
- it('should return html', () => {
42
- const result = ReportGenerator.generateReportHtml({});
43
- assert.ok(result.includes('doctype html'), 'includes doctype');
44
- assert.ok(result.trim().match(/<\/html>$/), 'ends with HTML tag');
45
- });
46
-
47
- it('should inject the report JSON', () => {
48
- const code = 'hax\u2028hax</script><script>console.log("pwned");%%LIGHTHOUSE_JAVASCRIPT%%';
49
- const result = ReportGenerator.generateReportHtml({code});
50
- assert.ok(result.includes('"code":"hax\\u2028'), 'injects the json');
51
- assert.ok(result.includes('hax\\u003c/script'), 'escapes HTML tags');
52
- assert.ok(result.includes('LIGHTHOUSE_JAVASCRIPT'), 'cannot be tricked');
53
- });
54
-
55
- it('should inject the report templates', () => {
56
- const page = new jsdom.JSDOM(ReportGenerator.generateReportHtml({}));
57
- const templates = new jsdom.JSDOM(reportAssets.REPORT_TEMPLATES);
58
- assert.equal(
59
- page.window.document.querySelectorAll('template[id^="tmpl-"]').length,
60
- templates.window.document.querySelectorAll('template[id^="tmpl-"]').length,
61
- 'all templates injected'
62
- );
63
- });
64
-
65
- it('should inject the report CSS', () => {
66
- const result = ReportGenerator.generateReportHtml({});
67
- assert.ok(!result.includes('/*%%LIGHTHOUSE_CSS%%*/'));
68
- assert.ok(result.includes('--color-green'));
69
- });
70
-
71
- it('should inject the report renderer javascript', () => {
72
- const result = ReportGenerator.generateReportHtml({});
73
- assert.ok(result.includes('ReportRenderer'), 'injects the script');
74
- assert.ok(result.includes('robustness: \\u003c/script'), 'escapes HTML tags in javascript');
75
- assert.ok(result.includes('pre$`post'), 'does not break from String.replace');
76
- assert.ok(result.includes('LIGHTHOUSE_JSON'), 'cannot be tricked');
77
- });
78
- });
79
-
80
- describe('#generateReport', () => {
81
- it('creates JSON for results', () => {
82
- const jsonOutput = ReportGenerator.generateReport(sampleResults, 'json');
83
- assert.doesNotThrow(_ => JSON.parse(jsonOutput));
84
- });
85
-
86
- it('creates HTML for results', () => {
87
- const htmlOutput = ReportGenerator.generateReport(sampleResults, 'html');
88
- assert.ok(/<!doctype/gim.test(htmlOutput));
89
- assert.ok(/<html lang="en"/gim.test(htmlOutput));
90
- });
91
-
92
- it('creates CSV for results', async () => {
93
- const path = './.results-as-csv.csv';
94
- const headers = {
95
- category: '',
96
- name: '',
97
- title: '',
98
- type: '',
99
- score: 42,
100
- };
101
-
102
- const csvOutput = ReportGenerator.generateReport(sampleResults, 'csv');
103
- fs.writeFileSync(path, csvOutput);
104
-
105
- const lines = csvOutput.split('\n');
106
- expect(lines.length).toBeGreaterThan(100);
107
- expect(lines.slice(0, 3).join('\n')).toMatchInlineSnapshot(`
108
- "requestedUrl,finalUrl,category,name,title,type,score
109
- \\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"Performance\\",\\"performance-score\\",\\"Overall Performance Category Score\\",\\"numeric\\",\\"0.57\\"
110
- \\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"Performance\\",\\"first-contentful-paint\\",\\"First Contentful Paint\\",\\"numeric\\",\\"0.24\\"
111
- "
112
- `);
113
-
114
- try {
115
- await csvValidator(path, headers);
116
- } catch (err) {
117
- assert.fail('CSV parser error:\n' + err.join('\n'));
118
- } finally {
119
- fs.unlinkSync(path);
120
- }
121
- });
122
-
123
- it('creates CSV for results including overall category scores', () => {
124
- const csvOutput = ReportGenerator.generateReport(sampleResults, 'csv');
125
- expect(csvOutput).toContain('performance-score');
126
- expect(csvOutput).toContain('accessibility-score');
127
- expect(csvOutput).toContain('best-practices-score');
128
- expect(csvOutput).toContain('seo-score');
129
- expect(csvOutput).toContain('pwa-score');
130
- });
131
-
132
- it('writes extended info', () => {
133
- const htmlOutput = ReportGenerator.generateReport(sampleResults, 'html');
134
- const outputCheck = new RegExp('dobetterweb/dbw_tester.css', 'i');
135
- assert.ok(outputCheck.test(htmlOutput));
136
- });
137
- });
138
-
139
- it('handles array of outputs', () => {
140
- const [json, html] = ReportGenerator.generateReport(sampleResults, ['json', 'html']);
141
- assert.doesNotThrow(_ => JSON.parse(json));
142
- assert.ok(/<!doctype/gim.test(html));
143
- assert.ok(/<html lang="en"/gim.test(html));
144
- });
145
- });