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,157 +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 jsdom = require('jsdom');
10
- const reportAssets = require('../../report-assets.js');
11
- const DOM = require('../../renderer/dom.js');
12
- const Util = require('../../renderer/util.js');
13
- const I18n = require('../../renderer/i18n.js');
14
-
15
- /* eslint-env jest */
16
-
17
- describe('DOM', () => {
18
- let dom;
19
-
20
- beforeAll(() => {
21
- global.Util = Util;
22
- global.Util.i18n = new I18n('en', {...Util.UIStrings});
23
- const {document} = new jsdom.JSDOM(reportAssets.REPORT_TEMPLATES).window;
24
- dom = new DOM(document);
25
- dom.setLighthouseChannel('someChannel');
26
- });
27
-
28
- afterAll(() => {
29
- global.Util.i18n = undefined;
30
- global.Util = undefined;
31
- });
32
-
33
- describe('createElement', () => {
34
- it('creates a simple element using default values', () => {
35
- const el = dom.createElement('div');
36
- assert.equal(el.localName, 'div');
37
- assert.equal(el.className, '');
38
- assert.equal(el.hasAttributes(), false);
39
- });
40
-
41
- it('creates an element from parameters', () => {
42
- const el = dom.createElement(
43
- 'div', 'class1 class2', {title: 'title attr', tabindex: 0});
44
- assert.equal(el.localName, 'div');
45
- assert.equal(el.className, 'class1 class2');
46
- assert.equal(el.getAttribute('title'), 'title attr');
47
- assert.equal(el.getAttribute('tabindex'), '0');
48
- });
49
- });
50
-
51
- describe('cloneTemplate', () => {
52
- it('should clone a template', () => {
53
- const clone = dom.cloneTemplate('#tmpl-lh-audit', dom.document());
54
- assert.ok(clone.querySelector('.lh-audit'));
55
- });
56
-
57
- it('should clone a template from a context scope', () => {
58
- const heading = dom.cloneTemplate('#tmpl-lh-footer', dom.document());
59
- const items = dom.cloneTemplate('#tmpl-lh-env__items', heading);
60
- assert.ok(items.querySelector('.lh-env__item'));
61
- });
62
-
63
- it('fails when template cannot be found', () => {
64
- assert.throws(() => dom.cloneTemplate('#unknown-selector', dom.document()));
65
- });
66
-
67
- it('fails when a template context isn\'t provided', () => {
68
- assert.throws(() => dom.cloneTemplate('#tmpl-lh-audit'));
69
- });
70
-
71
- it('does not inject duplicate styles', () => {
72
- const clone = dom.cloneTemplate('#tmpl-lh-snippet', dom.document());
73
- const clone2 = dom.cloneTemplate('#tmpl-lh-snippet', dom.document());
74
- assert.ok(clone.querySelector('style'));
75
- assert.ok(!clone2.querySelector('style'));
76
- });
77
- });
78
-
79
- describe('convertMarkdownLinkSnippets', () => {
80
- it('correctly converts links', () => {
81
- let result = dom.convertMarkdownLinkSnippets(
82
- 'Some [link](https://example.com/foo). [Learn more](http://example.com).');
83
- assert.equal(result.innerHTML,
84
- 'Some <a rel="noopener" target="_blank" href="https://example.com/foo">link</a>. ' +
85
- '<a rel="noopener" target="_blank" href="http://example.com/">Learn more</a>.');
86
-
87
- result = dom.convertMarkdownLinkSnippets('[link](https://example.com/foo)');
88
- assert.equal(result.innerHTML,
89
- '<a rel="noopener" target="_blank" href="https://example.com/foo">link</a>',
90
- 'just a link');
91
-
92
- result = dom.convertMarkdownLinkSnippets(
93
- '[ Link ](https://example.com/foo) and some text afterwards.');
94
- assert.equal(result.innerHTML,
95
- '<a rel="noopener" target="_blank" href="https://example.com/foo"> Link </a> ' +
96
- 'and some text afterwards.', 'link with spaces in brackets');
97
- });
98
-
99
- it('handles invalid urls', () => {
100
- const text = 'Text has [bad](https:///) link.';
101
- assert.throws(() => {
102
- dom.convertMarkdownLinkSnippets(text);
103
- });
104
- });
105
-
106
- it('ignores links that do not start with http', () => {
107
- const snippets = [
108
- 'Sentence with [link](/local/path).',
109
- 'Sentence with [link](javascript:console.log("pwned")).',
110
- 'Sentence with [link](chrome://settings#give-my-your-password).',
111
- ];
112
-
113
- for (const text of snippets) {
114
- const result = dom.convertMarkdownLinkSnippets(text);
115
- assert.equal(result.innerHTML, text);
116
- }
117
- });
118
-
119
- it('handles the case of [text]... [text](url)', () => {
120
- const text = 'Ensuring `<td>` cells using the `[headers]` are good. ' +
121
- '[Learn more](https://dequeuniversity.com/rules/axe/3.1/td-headers-attr).';
122
- const result = dom.convertMarkdownLinkSnippets(text);
123
- assert.equal(result.innerHTML, 'Ensuring `&lt;td&gt;` cells using the `[headers]` are ' +
124
- 'good. <a rel="noopener" target="_blank" href="https://dequeuniversity.com/rules/axe/3.1/td-headers-attr">Learn more</a>.');
125
- });
126
-
127
- it('appends utm params to the URLs with https://developers.google.com origin', () => {
128
- const text = '[Learn more](https://developers.google.com/web/tools/lighthouse/audits/description).';
129
-
130
- const result = dom.convertMarkdownLinkSnippets(text);
131
- assert.equal(result.innerHTML, '<a rel="noopener" target="_blank" href="https://developers.google.com/web/tools/lighthouse/audits/description?utm_source=lighthouse&amp;utm_medium=someChannel">Learn more</a>.');
132
- });
133
-
134
- it('appends utm params to the URLs with https://web.dev origin', () => {
135
- const text = '[Learn more](https://web.dev/tap-targets/).';
136
-
137
- const result = dom.convertMarkdownLinkSnippets(text);
138
- assert.equal(result.innerHTML, '<a rel="noopener" target="_blank" href="https://web.dev/tap-targets/?utm_source=lighthouse&amp;utm_medium=someChannel">Learn more</a>.');
139
- });
140
-
141
- it('doesn\'t append utm params to other (non-docs) origins', () => {
142
- const text = '[Learn more](https://example.com/info).';
143
-
144
- const result = dom.convertMarkdownLinkSnippets(text);
145
- assert.equal(result.innerHTML, '<a rel="noopener" target="_blank" href="https://example.com/info">Learn more</a>.');
146
- });
147
- });
148
-
149
- describe('convertMarkdownCodeSnippets', () => {
150
- it('correctly converts links', () => {
151
- const result = dom.convertMarkdownCodeSnippets(
152
- 'Here is some `code`, and then some `more code`, and yet event `more`.');
153
- assert.equal(result.innerHTML, 'Here is some <code>code</code>, and then some ' +
154
- '<code>more code</code>, and yet event <code>more</code>.');
155
- });
156
- });
157
- });
@@ -1,189 +0,0 @@
1
- /**
2
- * @license Copyright 2020 Google Inc. 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
- /* eslint-env jest */
9
-
10
- const jsdom = require('jsdom');
11
- const ElementScreenshotRenderer = require('../../renderer/element-screenshot-renderer.js');
12
- const RectHelpers = require('../../../lighthouse-core/lib/rect-helpers.js');
13
- const Util = require('../../renderer/util.js');
14
- const I18n = require('../../renderer/i18n.js');
15
- const DOM = require('../../renderer/dom.js');
16
- const reportAssets = require('../../report-assets.js');
17
-
18
- /**
19
- * @param {{left: number, top: number, width: number, height:number}} opts
20
- * @return {LH.Artifacts.Rect}
21
- */
22
- function makeRect(opts) {
23
- return {
24
- ...opts,
25
- right: opts.left + opts.width,
26
- bottom: opts.top + opts.height,
27
- };
28
- }
29
-
30
- describe('ElementScreenshotRenderer', () => {
31
- let dom;
32
-
33
- beforeAll(() => {
34
- global.RectHelpers = RectHelpers;
35
- global.Util = Util;
36
- global.Util.i18n = new I18n('en', {...Util.UIStrings});
37
- const {document} = new jsdom.JSDOM(reportAssets.REPORT_TEMPLATES).window;
38
- dom = new DOM(document);
39
- });
40
-
41
- afterAll(() => {
42
- global.RectHelpers = undefined;
43
- global.Util.i18n = undefined;
44
- global.Util = undefined;
45
- });
46
-
47
- it('renders screenshot', () => {
48
- const fullPageScreenshot = {
49
- width: 1000,
50
- height: 1000,
51
- };
52
- const elementRectSC = makeRect({
53
- left: 50,
54
- top: 50,
55
- width: 200,
56
- height: 300,
57
- });
58
- const renderContainerSizeDC = {
59
- width: 500,
60
- height: 500,
61
- };
62
- const el = ElementScreenshotRenderer.render(
63
- dom,
64
- dom.document(),
65
- fullPageScreenshot,
66
- elementRectSC,
67
- renderContainerSizeDC
68
- );
69
-
70
- /* eslint-disable max-len */
71
- expect(el.innerHTML).toMatchInlineSnapshot(`
72
- "
73
- <div class=\\"lh-element-screenshot__content\\" style=\\"top: -500px;\\">
74
- <div class=\\"lh-element-screenshot__mask\\" style=\\"width: 500px; height: 500px; clip-path: url(#clip-0);\\">
75
- <svg xmlns=\\"http://www.w3.org/2000/svg\\" height=\\"0\\" width=\\"0\\">
76
- <defs>
77
- <clipPath clipPathUnits=\\"objectBoundingBox\\" id=\\"clip-0\\"><polygon points=\\"0,0 1,0 1,0.1 0,0.1\\"></polygon><polygon points=\\"0,0.7 1,0.7 1,1 0,1\\"></polygon><polygon points=\\"0,0.1 0.1,0.1 0.1,0.7 0,0.7\\"></polygon><polygon points=\\"0.5,0.1 1,0.1 1,0.7 0.5,0.7\\"></polygon></clipPath>
78
- <!-- clipPath filled by ElementScreenshotRenderer.renderClipPath -->
79
- </defs>
80
- </svg>
81
- </div>
82
- <div class=\\"lh-element-screenshot__image\\" style=\\"width: 500px; height: 500px; background-position-y: 0px; background-position-x: 0px; background-size: 1000px 1000px;\\"></div>
83
- <div class=\\"lh-element-screenshot__element-marker\\" style=\\"width: 200px; height: 300px; left: 50px; top: 50px;\\"></div>
84
- </div>
85
- "
86
- `);
87
- /* eslint-enable max-len */
88
- });
89
-
90
- it('returns null if element is out of bounds', () => {
91
- const fullPageScreenshot = {
92
- width: 1000,
93
- height: 1000,
94
- };
95
- const elementRectSC = makeRect({
96
- left: 50,
97
- top: 5000,
98
- width: 200,
99
- height: 300,
100
- });
101
- const renderContainerSizeDC = {
102
- width: 500,
103
- height: 500,
104
- };
105
- expect(ElementScreenshotRenderer.render(
106
- dom,
107
- dom.document(),
108
- fullPageScreenshot,
109
- elementRectSC,
110
- renderContainerSizeDC
111
- )).toBe(null);
112
- });
113
-
114
- describe('getScreenshotPositions', () => {
115
- it('centers the screenshot on the highlighted area', () => {
116
- expect(
117
- ElementScreenshotRenderer.getScreenshotPositions(
118
- {left: 400, top: 500, width: 100, height: 40},
119
- {width: 412, height: 300},
120
- {width: 1300, height: 5000}
121
- )
122
- ).toMatchObject({
123
- screenshot: {
124
- left: 244,
125
- top: 370,
126
- },
127
- clip: {
128
- left: 156,
129
- top: 130,
130
- },
131
- });
132
- });
133
-
134
- it('contains the screenshot within the display area if the clip is in the top left', () => {
135
- expect(
136
- ElementScreenshotRenderer.getScreenshotPositions(
137
- {left: 0, top: 0, width: 100, height: 40},
138
- {width: 412, height: 300},
139
- {width: 412, height: 5000}
140
- )
141
- ).toMatchObject({
142
- screenshot: {
143
- left: 0,
144
- top: 0,
145
- },
146
- clip: {
147
- left: 0,
148
- top: 0,
149
- },
150
- });
151
- });
152
-
153
- it('contains the screenshot within the display area if the clip is in the bottom right', () => {
154
- expect(
155
- ElementScreenshotRenderer.getScreenshotPositions(
156
- {left: 300, top: 4950, width: 100, height: 40},
157
- {width: 412, height: 300},
158
- {width: 412, height: 5000}
159
- )
160
- ).toMatchObject({
161
- screenshot: {
162
- left: 0,
163
- top: 4700,
164
- },
165
- clip: {
166
- left: 300,
167
- top: 250,
168
- },
169
- });
170
-
171
- expect(
172
- ElementScreenshotRenderer.getScreenshotPositions(
173
- {left: 300, top: 4950, width: 100, height: 40},
174
- {width: 200, height: 300},
175
- {width: 412, height: 5000}
176
- )
177
- ).toMatchObject({
178
- screenshot: {
179
- left: 212,
180
- top: 4700,
181
- },
182
- clip: {
183
- left: 88,
184
- top: 250,
185
- },
186
- });
187
- });
188
- });
189
- });
@@ -1,146 +0,0 @@
1
- /**
2
- * @license Copyright 2020 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 {isNode12SmallIcu} = require('../../../lighthouse-core/test/test-utils.js');
12
-
13
- // Require i18n to make sure Intl is polyfilled in Node without full-icu for testing.
14
- // When Util is run in a browser, Intl will be supplied natively (IE11+).
15
- // eslint-disable-next-line no-unused-vars
16
- const i18n = require('../../../lighthouse-core/lib/i18n/i18n.js');
17
-
18
- const NBSP = '\xa0';
19
-
20
- /* eslint-env jest */
21
-
22
- describe('util helpers', () => {
23
- it('formats a number', () => {
24
- const i18n = new I18n('en', {...Util.UIStrings});
25
- assert.strictEqual(i18n.formatNumber(10), '10');
26
- assert.strictEqual(i18n.formatNumber(100.01), '100');
27
- assert.strictEqual(i18n.formatNumber(13000.456), '13,000.5');
28
- });
29
-
30
- it('formats a date', () => {
31
- const i18n = new I18n('en', {...Util.UIStrings});
32
- const timestamp = i18n.formatDateTime('2017-04-28T23:07:51.189Z');
33
- assert.ok(
34
- timestamp.includes('Apr 27, 2017') ||
35
- timestamp.includes('Apr 28, 2017') ||
36
- timestamp.includes('Apr 29, 2017')
37
- );
38
- });
39
-
40
- it('formats bytes', () => {
41
- const i18n = new I18n('en', {...Util.UIStrings});
42
- assert.equal(i18n.formatBytesToKiB(100), `0.1${NBSP}KiB`);
43
- assert.equal(i18n.formatBytesToKiB(2000), `2.0${NBSP}KiB`);
44
- assert.equal(i18n.formatBytesToKiB(1014 * 1024), `1,014.0${NBSP}KiB`);
45
- });
46
-
47
- it('formats bytes with different granularities', () => {
48
- const i18n = new I18n('en', {...Util.UIStrings});
49
-
50
- let granularity = 10;
51
- assert.strictEqual(i18n.formatBytes(15.0, granularity), `20${NBSP}bytes`);
52
- assert.strictEqual(i18n.formatBytes(15.12345, granularity), `20${NBSP}bytes`);
53
- assert.strictEqual(i18n.formatBytes(14.99999, granularity), `10${NBSP}bytes`);
54
-
55
- granularity = 1;
56
- assert.strictEqual(i18n.formatBytes(15.0, granularity), `15${NBSP}bytes`);
57
- assert.strictEqual(i18n.formatBytes(15.12345, granularity), `15${NBSP}bytes`);
58
- assert.strictEqual(i18n.formatBytes(15.54321, granularity), `16${NBSP}bytes`);
59
-
60
- granularity = 0.5;
61
- assert.strictEqual(i18n.formatBytes(15.0, granularity), `15.0${NBSP}bytes`);
62
- assert.strictEqual(i18n.formatBytes(15.12345, granularity), `15.0${NBSP}bytes`);
63
- assert.strictEqual(i18n.formatBytes(15.54321, granularity), `15.5${NBSP}bytes`);
64
-
65
- granularity = 0.1;
66
- assert.strictEqual(i18n.formatBytes(15.0, granularity), `15.0${NBSP}bytes`);
67
- assert.strictEqual(i18n.formatBytes(15.12345, granularity), `15.1${NBSP}bytes`);
68
- assert.strictEqual(i18n.formatBytes(15.19999, granularity), `15.2${NBSP}bytes`);
69
-
70
- granularity = 0.01;
71
- assert.strictEqual(i18n.formatBytes(15.0, granularity), `15.00${NBSP}bytes`);
72
- assert.strictEqual(i18n.formatBytes(15.12345, granularity), `15.12${NBSP}bytes`);
73
- assert.strictEqual(i18n.formatBytes(15.19999, granularity), `15.20${NBSP}bytes`);
74
- });
75
-
76
- it('formats kibibytes with different granularities', () => {
77
- const i18n = new I18n('en', {...Util.UIStrings});
78
-
79
- let granularity = 10;
80
- assert.strictEqual(i18n.formatBytesToKiB(5 * 1024, granularity), `10${NBSP}KiB`);
81
- assert.strictEqual(i18n.formatBytesToKiB(4 * 1024, granularity), `0${NBSP}KiB`);
82
-
83
- granularity = 1;
84
- assert.strictEqual(i18n.formatBytesToKiB(5 * 1024, granularity), `5${NBSP}KiB`);
85
- assert.strictEqual(i18n.formatBytesToKiB(4 * 1024 + 512, granularity), `5${NBSP}KiB`);
86
- assert.strictEqual(i18n.formatBytesToKiB(4 * 1024 + 511, granularity), `4${NBSP}KiB`);
87
-
88
- granularity = 0.01;
89
- assert.strictEqual(i18n.formatBytesToKiB(5 * 1024, granularity), `5.00${NBSP}KiB`);
90
- assert.strictEqual(i18n.formatBytesToKiB(5 * 1024 - 5, granularity), `5.00${NBSP}KiB`);
91
- assert.strictEqual(i18n.formatBytesToKiB(5 * 1024 - 6, granularity), `4.99${NBSP}KiB`);
92
- });
93
-
94
- it('formats ms', () => {
95
- const i18n = new I18n('en', {...Util.UIStrings});
96
- assert.equal(i18n.formatMilliseconds(123), `120${NBSP}ms`);
97
- assert.equal(i18n.formatMilliseconds(2456.5, 0.1), `2,456.5${NBSP}ms`);
98
- assert.equal(i18n.formatMilliseconds(0.000001), `0${NBSP}ms`);
99
- assert.equal(i18n.formatMilliseconds(-0.000001), `0${NBSP}ms`);
100
- });
101
-
102
- it('formats a duration', () => {
103
- const i18n = new I18n('en', {...Util.UIStrings});
104
- assert.equal(i18n.formatDuration(60 * 1000), `1${NBSP}m`);
105
- assert.equal(i18n.formatDuration(60 * 60 * 1000 + 5000), `1${NBSP}h 5${NBSP}s`);
106
- assert.equal(i18n.formatDuration(28 * 60 * 60 * 1000 + 5000), `1${NBSP}d 4${NBSP}h 5${NBSP}s`);
107
- });
108
-
109
- it('formats numbers based on locale', () => {
110
- // COMPAT: Node 12 only has 'en' by default.
111
- if (isNode12SmallIcu()) return;
112
-
113
- // Requires full-icu or Intl polyfill.
114
- const number = 12346.858558;
115
-
116
- const i18n = new I18n('de', {...Util.UIStrings});
117
- assert.strictEqual(i18n.formatNumber(number), '12.346,9');
118
- assert.strictEqual(i18n.formatBytesToKiB(number), `12,1${NBSP}KiB`);
119
- assert.strictEqual(i18n.formatMilliseconds(number), `12.350${NBSP}ms`);
120
- assert.strictEqual(i18n.formatSeconds(number), `12,3${NBSP}s`);
121
- });
122
-
123
- it('uses decimal comma with en-XA test locale', () => {
124
- // COMPAT: Node 12 only has 'en' by default.
125
- if (isNode12SmallIcu()) return;
126
-
127
- // Requires full-icu or Intl polyfill.
128
- const number = 12346.858558;
129
-
130
- const i18n = new I18n('en-XA', {...Util.UIStrings});
131
- assert.strictEqual(i18n.formatNumber(number), '12.346,9');
132
- assert.strictEqual(i18n.formatBytesToKiB(number), `12,1${NBSP}KiB`);
133
- assert.strictEqual(i18n.formatMilliseconds(number), `12.350${NBSP}ms`);
134
- assert.strictEqual(i18n.formatSeconds(number), `12,3${NBSP}s`);
135
- });
136
-
137
- it('should not crash on unknown locales', () => {
138
- const i18n = new I18n('unknown-mystery-locale', {...Util.UIStrings});
139
- const timestamp = i18n.formatDateTime('2017-04-28T23:07:51.189Z');
140
- assert.ok(
141
- timestamp.includes('Apr 27, 2017') ||
142
- timestamp.includes('Apr 28, 2017') ||
143
- timestamp.includes('Apr 29, 2017')
144
- );
145
- });
146
- });