lighthouse 9.5.0-dev.20230123 → 9.5.0-dev.20230124

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 (109) hide show
  1. package/.codecov.yml +0 -5
  2. package/core/audits/audit.js +1 -1
  3. package/core/audits/byte-efficiency/legacy-javascript.d.ts +1 -0
  4. package/core/audits/byte-efficiency/legacy-javascript.js +7 -3
  5. package/core/audits/dobetterweb/uses-http2.d.ts +5 -2
  6. package/core/audits/dobetterweb/uses-http2.js +12 -7
  7. package/core/audits/third-party-facades.d.ts +3 -2
  8. package/core/audits/third-party-facades.js +12 -9
  9. package/core/audits/third-party-summary.d.ts +7 -6
  10. package/core/audits/third-party-summary.js +16 -14
  11. package/core/audits/valid-source-maps.d.ts +5 -3
  12. package/core/audits/valid-source-maps.js +11 -9
  13. package/core/computed/entity-classification.d.ts +29 -0
  14. package/core/computed/entity-classification.js +102 -0
  15. package/core/computed/resource-summary.d.ts +4 -2
  16. package/core/computed/resource-summary.js +8 -5
  17. package/core/lib/url-utils.js +1 -1
  18. package/core/runner.d.ts +10 -0
  19. package/core/runner.js +48 -0
  20. package/core/util.cjs +1 -1
  21. package/dist/report/bundle.esm.js +724 -687
  22. package/dist/report/flow.js +25 -15
  23. package/dist/report/standalone.js +25 -15
  24. package/flow-report/src/common.tsx +1 -1
  25. package/flow-report/src/i18n/i18n.tsx +17 -16
  26. package/flow-report/src/sidebar/sidebar.tsx +2 -2
  27. package/flow-report/src/summary/category.tsx +6 -6
  28. package/flow-report/src/summary/summary.tsx +2 -2
  29. package/package.json +4 -4
  30. package/report/renderer/category-renderer.js +19 -17
  31. package/report/renderer/crc-details-renderer.js +6 -6
  32. package/report/renderer/details-renderer.js +7 -6
  33. package/report/renderer/dom.js +1 -1
  34. package/report/renderer/element-screenshot-renderer.js +3 -3
  35. package/report/renderer/performance-category-renderer.js +17 -15
  36. package/report/renderer/pwa-category-renderer.js +5 -4
  37. package/report/renderer/report-globals.d.ts +21 -0
  38. package/report/renderer/report-globals.js +49 -0
  39. package/report/renderer/report-renderer.js +22 -20
  40. package/report/renderer/report-ui-features.js +9 -8
  41. package/report/renderer/report-utils.d.ts +116 -0
  42. package/report/renderer/{util.js → report-utils.js} +81 -429
  43. package/report/renderer/snippet-renderer.js +3 -2
  44. package/report/test/renderer/category-renderer-test.js +9 -4
  45. package/report/test/renderer/crc-details-renderer-test.js +7 -3
  46. package/report/test/renderer/details-renderer-test.js +7 -3
  47. package/report/test/renderer/dom-test.js +7 -3
  48. package/report/test/renderer/element-screenshot-renderer-test.js +8 -4
  49. package/report/test/renderer/performance-category-renderer-test.js +14 -9
  50. package/report/test/renderer/pwa-category-renderer-test.js +10 -5
  51. package/report/test/renderer/report-renderer-test.js +2 -2
  52. package/report/test/renderer/report-ui-features-test.js +3 -3
  53. package/report/test/renderer/{util-test.js → report-utils-test.js} +36 -234
  54. package/report/test/renderer/snippet-renderer-test.js +7 -3
  55. package/shared/localization/format.js +5 -2
  56. package/shared/localization/locales/ar-XB.json +50 -50
  57. package/shared/localization/locales/ar.json +50 -50
  58. package/shared/localization/locales/bg.json +50 -50
  59. package/shared/localization/locales/ca.json +50 -50
  60. package/shared/localization/locales/cs.json +50 -50
  61. package/shared/localization/locales/da.json +50 -50
  62. package/shared/localization/locales/de.json +50 -50
  63. package/shared/localization/locales/el.json +50 -50
  64. package/shared/localization/locales/en-GB.json +50 -50
  65. package/shared/localization/locales/en-US.json +54 -54
  66. package/shared/localization/locales/en-XA.json +50 -50
  67. package/shared/localization/locales/en-XL.json +54 -54
  68. package/shared/localization/locales/es-419.json +50 -50
  69. package/shared/localization/locales/es.json +50 -50
  70. package/shared/localization/locales/fi.json +50 -50
  71. package/shared/localization/locales/fil.json +50 -50
  72. package/shared/localization/locales/fr.json +50 -50
  73. package/shared/localization/locales/he.json +50 -50
  74. package/shared/localization/locales/hi.json +50 -50
  75. package/shared/localization/locales/hr.json +50 -50
  76. package/shared/localization/locales/hu.json +50 -50
  77. package/shared/localization/locales/id.json +50 -50
  78. package/shared/localization/locales/it.json +50 -50
  79. package/shared/localization/locales/ja.json +50 -50
  80. package/shared/localization/locales/ko.json +50 -50
  81. package/shared/localization/locales/lt.json +50 -50
  82. package/shared/localization/locales/lv.json +50 -50
  83. package/shared/localization/locales/nl.json +50 -50
  84. package/shared/localization/locales/no.json +50 -50
  85. package/shared/localization/locales/pl.json +50 -50
  86. package/shared/localization/locales/pt-PT.json +50 -50
  87. package/shared/localization/locales/pt.json +50 -50
  88. package/shared/localization/locales/ro.json +50 -50
  89. package/shared/localization/locales/ru.json +50 -50
  90. package/shared/localization/locales/sk.json +50 -50
  91. package/shared/localization/locales/sl.json +50 -50
  92. package/shared/localization/locales/sr-Latn.json +50 -50
  93. package/shared/localization/locales/sr.json +50 -50
  94. package/shared/localization/locales/sv.json +50 -50
  95. package/shared/localization/locales/ta.json +50 -50
  96. package/shared/localization/locales/te.json +50 -50
  97. package/shared/localization/locales/th.json +50 -50
  98. package/shared/localization/locales/tr.json +50 -50
  99. package/shared/localization/locales/uk.json +50 -50
  100. package/shared/localization/locales/vi.json +50 -50
  101. package/shared/localization/locales/zh-HK.json +50 -50
  102. package/shared/localization/locales/zh-TW.json +50 -50
  103. package/shared/localization/locales/zh.json +50 -50
  104. package/shared/test/util-test.js +214 -0
  105. package/shared/util.d.ts +122 -0
  106. package/shared/util.js +332 -0
  107. package/types/artifacts.d.ts +14 -0
  108. package/types/lhr/lhr.d.ts +33 -0
  109. package/report/renderer/util.d.ts +0 -342
@@ -6,34 +6,39 @@
6
6
 
7
7
  import assert from 'assert/strict';
8
8
 
9
- import {Util} from '../../renderer/util.js';
9
+ import {ReportUtils} from '../../renderer/report-utils.js';
10
10
  import {I18nFormatter} from '../../renderer/i18n-formatter.js';
11
11
  import {readJson} from '../../../core/test/test-utils.js';
12
+ import {Globals} from '../../renderer/report-globals.js';
12
13
 
13
14
  const sampleResult = readJson('../../../core/test/results/sample_v2.json', import.meta);
14
15
 
15
16
  describe('util helpers', () => {
16
17
  beforeEach(() => {
17
- Util.i18n = new I18nFormatter('en');
18
+ Globals.apply({
19
+ providedStrings: {},
20
+ i18n: new I18nFormatter('en'),
21
+ reportJson: null,
22
+ });
18
23
  });
19
24
 
20
25
  afterEach(() => {
21
- Util.i18n = undefined;
26
+ Globals.i18n = undefined;
22
27
  });
23
28
 
24
29
  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');
30
+ assert.equal(ReportUtils.calculateRating(0.0), 'fail');
31
+ assert.equal(ReportUtils.calculateRating(0.10), 'fail');
32
+ assert.equal(ReportUtils.calculateRating(0.45), 'fail');
33
+ assert.equal(ReportUtils.calculateRating(0.5), 'average');
34
+ assert.equal(ReportUtils.calculateRating(0.75), 'average');
35
+ assert.equal(ReportUtils.calculateRating(0.80), 'average');
36
+ assert.equal(ReportUtils.calculateRating(0.90), 'pass');
37
+ assert.equal(ReportUtils.calculateRating(1.00), 'pass');
33
38
  });
34
39
 
35
40
  it('builds device emulation string', () => {
36
- const get = settings => Util.getEmulationDescriptions(settings).deviceEmulation;
41
+ const get = settings => ReportUtils.getEmulationDescriptions(settings).deviceEmulation;
37
42
  /* eslint-disable max-len */
38
43
  assert.equal(get({formFactor: 'mobile', screenEmulation: {disabled: false, mobile: true}}), 'Emulated Moto G4');
39
44
  assert.equal(get({formFactor: 'mobile', screenEmulation: {disabled: true, mobile: true}}), 'No emulation');
@@ -45,7 +50,7 @@ describe('util helpers', () => {
45
50
  });
46
51
 
47
52
  it('builds throttling strings when provided', () => {
48
- const descriptions = Util.getEmulationDescriptions({
53
+ const descriptions = ReportUtils.getEmulationDescriptions({
49
54
  throttlingMethod: 'provided',
50
55
  screenEmulation: {disabled: true},
51
56
  });
@@ -55,7 +60,7 @@ describe('util helpers', () => {
55
60
  });
56
61
 
57
62
  it('builds throttling strings when devtools', () => {
58
- const descriptions = Util.getEmulationDescriptions({
63
+ const descriptions = ReportUtils.getEmulationDescriptions({
59
64
  throttlingMethod: 'devtools',
60
65
  throttling: {
61
66
  cpuSlowdownMultiplier: 4.5,
@@ -72,7 +77,7 @@ describe('util helpers', () => {
72
77
  });
73
78
 
74
79
  it('builds throttling strings when simulate', () => {
75
- const descriptions = Util.getEmulationDescriptions({
80
+ const descriptions = ReportUtils.getEmulationDescriptions({
76
81
  throttlingMethod: 'simulate',
77
82
  throttling: {
78
83
  cpuSlowdownMultiplier: 2,
@@ -104,7 +109,7 @@ describe('util helpers', () => {
104
109
  assert.ok(notApplicableCount > 20); // Make sure something's being tested.
105
110
 
106
111
  // Original audit results should be restored.
107
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
112
+ const preparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
108
113
 
109
114
  assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
110
115
  });
@@ -124,7 +129,7 @@ describe('util helpers', () => {
124
129
  assert.notDeepStrictEqual(clonedSampleResult.audits, sampleResult.audits);
125
130
 
126
131
  // Original audit results should be restored.
127
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
132
+ const preparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
128
133
  assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
129
134
  });
130
135
 
@@ -143,7 +148,7 @@ describe('util helpers', () => {
143
148
  assert.notDeepStrictEqual(clonedSampleResult.audits, sampleResult.audits);
144
149
 
145
150
  // Original audit results should be restored.
146
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
151
+ const preparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
147
152
  assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
148
153
  });
149
154
 
@@ -164,7 +169,7 @@ describe('util helpers', () => {
164
169
  assert.notDeepStrictEqual(clonedSampleResult.audits, sampleResult.audits);
165
170
 
166
171
  // Original audit results should be restored.
167
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
172
+ const preparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
168
173
  assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
169
174
  });
170
175
 
@@ -183,7 +188,7 @@ describe('util helpers', () => {
183
188
  assert.notDeepStrictEqual(clonedSampleResult.audits, sampleResult.audits);
184
189
 
185
190
  // Original audit results should be restored.
186
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
191
+ const preparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
187
192
  assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
188
193
  assert.deepStrictEqual(preparedResult.fullPageScreenshot, sampleResult.fullPageScreenshot);
189
194
  });
@@ -204,8 +209,8 @@ describe('util helpers', () => {
204
209
  assert.notDeepStrictEqual(clonedSampleResult.categoryGroups, sampleResult.categoryGroups);
205
210
 
206
211
  // Original audit results should be restored.
207
- const clonedPreparedResult = Util.prepareReportResult(clonedSampleResult);
208
- const preparedResult = Util.prepareReportResult(sampleResult);
212
+ const clonedPreparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
213
+ const preparedResult = ReportUtils.prepareReportResult(sampleResult);
209
214
  assert.deepStrictEqual(clonedPreparedResult.categories, preparedResult.categories);
210
215
  assert.deepStrictEqual(clonedPreparedResult.categoryGroups, preparedResult.categoryGroups);
211
216
  });
@@ -231,7 +236,7 @@ describe('util helpers', () => {
231
236
  }
232
237
  }
233
238
 
234
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
239
+ const preparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
235
240
  assert.deepStrictEqual(sampleResult.audits, preparedResult.audits);
236
241
  });
237
242
  });
@@ -247,7 +252,7 @@ describe('util helpers', () => {
247
252
  'unused-css-rules': 'Consider using snacks in packs.',
248
253
  },
249
254
  }];
250
- const preparedResult = Util.prepareReportResult(clonedSampleResult);
255
+ const preparedResult = ReportUtils.prepareReportResult(clonedSampleResult);
251
256
 
252
257
  const perfAuditRefs = preparedResult.categories.performance.auditRefs;
253
258
  const unusedCssRef = perfAuditRefs.find(ref => ref.id === 'unused-css-rules');
@@ -263,215 +268,12 @@ describe('util helpers', () => {
263
268
  });
264
269
  });
265
270
 
266
- describe('getTld', () => {
267
- it('returns the correct tld', () => {
268
- assert.equal(Util.getTld('example.com'), '.com');
269
- assert.equal(Util.getTld('example.co.uk'), '.co.uk');
270
- assert.equal(Util.getTld('example.com.br'), '.com.br');
271
- assert.equal(Util.getTld('example.tokyo.jp'), '.jp');
272
- });
273
- });
274
-
275
- describe('getRootDomain', () => {
276
- it('returns the correct rootDomain from a string', () => {
277
- assert.equal(Util.getRootDomain('https://www.example.com/index.html'), 'example.com');
278
- assert.equal(Util.getRootDomain('https://example.com'), 'example.com');
279
- assert.equal(Util.getRootDomain('https://www.example.co.uk'), 'example.co.uk');
280
- assert.equal(Util.getRootDomain('https://example.com.br/app/'), 'example.com.br');
281
- assert.equal(Util.getRootDomain('https://example.tokyo.jp'), 'tokyo.jp');
282
- assert.equal(Util.getRootDomain('https://sub.example.com'), 'example.com');
283
- assert.equal(Util.getRootDomain('https://sub.example.tokyo.jp'), 'tokyo.jp');
284
- assert.equal(Util.getRootDomain('http://localhost'), 'localhost');
285
- assert.equal(Util.getRootDomain('http://localhost:8080'), 'localhost');
286
- });
287
-
288
- it('returns the correct rootDomain from an URL object', () => {
289
- assert.equal(Util.getRootDomain(new URL('https://www.example.com/index.html')), 'example.com');
290
- assert.equal(Util.getRootDomain(new URL('https://example.com')), 'example.com');
291
- assert.equal(Util.getRootDomain(new URL('https://www.example.co.uk')), 'example.co.uk');
292
- assert.equal(Util.getRootDomain(new URL('https://example.com.br/app/')), 'example.com.br');
293
- assert.equal(Util.getRootDomain(new URL('https://example.tokyo.jp')), 'tokyo.jp');
294
- assert.equal(Util.getRootDomain(new URL('https://sub.example.com')), 'example.com');
295
- assert.equal(Util.getRootDomain(new URL('https://sub.example.tokyo.jp')), 'tokyo.jp');
296
- assert.equal(Util.getRootDomain(new URL('http://localhost')), 'localhost');
297
- assert.equal(Util.getRootDomain(new URL('http://localhost:8080')), 'localhost');
298
- });
299
- });
300
-
301
- describe('#splitMarkdownCodeSpans', () => {
302
- it('handles strings with no backticks in them', () => {
303
- expect(Util.splitMarkdownCodeSpans('regular text')).toEqual([
304
- {isCode: false, text: 'regular text'},
305
- ]);
306
- });
307
-
308
- it('does not split on a single backtick', () => {
309
- expect(Util.splitMarkdownCodeSpans('regular `text')).toEqual([
310
- {isCode: false, text: 'regular `text'},
311
- ]);
312
- });
313
-
314
- it('splits on backticked code', () => {
315
- expect(Util.splitMarkdownCodeSpans('regular `code` text')).toEqual([
316
- {isCode: false, text: 'regular '},
317
- {isCode: true, text: 'code'},
318
- {isCode: false, text: ' text'},
319
- ]);
320
- });
321
-
322
- it('splits on backticked code at the beginning of the string', () => {
323
- expect(Util.splitMarkdownCodeSpans('`start code` regular text')).toEqual([
324
- {isCode: true, text: 'start code'},
325
- {isCode: false, text: ' regular text'},
326
- ]);
327
- });
328
-
329
- it('splits on backticked code at the end of the string', () => {
330
- expect(Util.splitMarkdownCodeSpans('regular text `end code`')).toEqual([
331
- {isCode: false, text: 'regular text '},
332
- {isCode: true, text: 'end code'},
333
- ]);
334
- });
335
-
336
- it('does not split on a single backtick after split out backticked code', () => {
337
- expect(Util.splitMarkdownCodeSpans('regular text `code` and more `text')).toEqual([
338
- {isCode: false, text: 'regular text '},
339
- {isCode: true, text: 'code'},
340
- {isCode: false, text: ' and more `text'},
341
- ]);
342
- });
343
-
344
- it('splits on two instances of backticked code', () => {
345
- expect(Util.splitMarkdownCodeSpans('regular text `code` more text `and more code`')).toEqual([
346
- {isCode: false, text: 'regular text '},
347
- {isCode: true, text: 'code'},
348
- {isCode: false, text: ' more text '},
349
- {isCode: true, text: 'and more code'},
350
- ]);
351
- });
352
-
353
- it('splits on two directly adjacent instances of backticked code', () => {
354
- // eslint-disable-next-line max-len
355
- expect(Util.splitMarkdownCodeSpans('regular text `first code``second code` end text')).toEqual([
356
- {isCode: false, text: 'regular text '},
357
- {isCode: true, text: 'first code'},
358
- {isCode: true, text: 'second code'},
359
- {isCode: false, text: ' end text'},
360
- ]);
361
- });
362
-
363
- it('handles text only within backticks', () => {
364
- expect(Util.splitMarkdownCodeSpans('`first code``second code`')).toEqual([
365
- {isCode: true, text: 'first code'},
366
- {isCode: true, text: 'second code'},
367
- ]);
368
- });
369
-
370
- it('splits on two instances of backticked code separated by only a space', () => {
371
- // eslint-disable-next-line max-len
372
- expect(Util.splitMarkdownCodeSpans('`first code` `second code`')).toEqual([
373
- {isCode: true, text: 'first code'},
374
- {isCode: false, text: ' '},
375
- {isCode: true, text: 'second code'},
376
- ]);
377
- });
378
- });
379
-
380
- describe('#splitMarkdownLink', () => {
381
- it('handles strings with no links in them', () => {
382
- expect(Util.splitMarkdownLink('some text')).toEqual([
383
- {isLink: false, text: 'some text'},
384
- ]);
385
- });
386
-
387
- it('does not split on an incomplete markdown link', () => {
388
- expect(Util.splitMarkdownLink('some [not link text](text')).toEqual([
389
- {isLink: false, text: 'some [not link text](text'},
390
- ]);
391
- });
392
-
393
- it('splits on a markdown link', () => {
394
- expect(Util.splitMarkdownLink('some [link text](https://example.com) text')).toEqual([
395
- {isLink: false, text: 'some '},
396
- {isLink: true, text: 'link text', linkHref: 'https://example.com'},
397
- {isLink: false, text: ' text'},
398
- ]);
399
- });
400
-
401
- it('splits on an http markdown link', () => {
402
- expect(Util.splitMarkdownLink('you should [totally click here](http://never-mitm.com) now')).toEqual([
403
- {isLink: false, text: 'you should '},
404
- {isLink: true, text: 'totally click here', linkHref: 'http://never-mitm.com'},
405
- {isLink: false, text: ' now'},
406
- ]);
407
- });
408
-
409
- it('does not split on a non-http/https link', () => {
410
- expect(Util.splitMarkdownLink('some [link text](ftp://example.com) text')).toEqual([
411
- {isLink: false, text: 'some [link text](ftp://example.com) text'},
412
- ]);
413
- });
414
-
415
- it('does not split on a malformed markdown link', () => {
416
- expect(Util.splitMarkdownLink('some [link ]text](https://example.com')).toEqual([
417
- {isLink: false, text: 'some [link ]text](https://example.com'},
418
- ]);
419
-
420
- expect(Util.splitMarkdownLink('some [link text] (https://example.com')).toEqual([
421
- {isLink: false, text: 'some [link text] (https://example.com'},
422
- ]);
423
- });
424
-
425
- it('does not split on empty link text', () => {
426
- expect(Util.splitMarkdownLink('some [](https://example.com) empty link')).toEqual([
427
- {isLink: false, text: 'some [](https://example.com) empty link'},
428
- ]);
429
- });
430
-
431
- it('splits on a markdown link at the beginning of a string', () => {
432
- expect(Util.splitMarkdownLink('[link text](https://example.com) end text')).toEqual([
433
- {isLink: true, text: 'link text', linkHref: 'https://example.com'},
434
- {isLink: false, text: ' end text'},
435
- ]);
436
- });
437
-
438
- it('splits on a markdown link at the end of a string', () => {
439
- expect(Util.splitMarkdownLink('start text [link text](https://example.com)')).toEqual([
440
- {isLink: false, text: 'start text '},
441
- {isLink: true, text: 'link text', linkHref: 'https://example.com'},
442
- ]);
443
- });
444
-
445
- it('handles a string consisting only of a markdown link', () => {
446
- expect(Util.splitMarkdownLink(`[I'm only a link](https://example.com)`)).toEqual([
447
- {isLink: true, text: `I'm only a link`, linkHref: 'https://example.com'},
448
- ]);
449
- });
450
-
451
- it('handles a string starting and ending with a markdown link', () => {
452
- expect(Util.splitMarkdownLink('[first link](https://first.com) other text [second link](https://second.com)')).toEqual([
453
- {isLink: true, text: 'first link', linkHref: 'https://first.com'},
454
- {isLink: false, text: ' other text '},
455
- {isLink: true, text: 'second link', linkHref: 'https://second.com'},
456
- ]);
457
- });
458
-
459
- it('handles a string with adjacent markdown links', () => {
460
- expect(Util.splitMarkdownLink('start text [first link](https://first.com)[second link](https://second.com) and scene')).toEqual([
461
- {isLink: false, text: 'start text '},
462
- {isLink: true, text: 'first link', linkHref: 'https://first.com'},
463
- {isLink: true, text: 'second link', linkHref: 'https://second.com'},
464
- {isLink: false, text: ' and scene'},
465
- ]);
466
- });
467
- });
468
-
469
271
  describe('#shouldDisplayAsFraction', () => {
470
272
  it('returns true for timespan and snapshot', () => {
471
- expect(Util.shouldDisplayAsFraction('navigation')).toEqual(false);
472
- expect(Util.shouldDisplayAsFraction('timespan')).toEqual(true);
473
- expect(Util.shouldDisplayAsFraction('snapshot')).toEqual(true);
474
- expect(Util.shouldDisplayAsFraction(undefined)).toEqual(false);
273
+ expect(ReportUtils.shouldDisplayAsFraction('navigation')).toEqual(false);
274
+ expect(ReportUtils.shouldDisplayAsFraction('timespan')).toEqual(true);
275
+ expect(ReportUtils.shouldDisplayAsFraction('snapshot')).toEqual(true);
276
+ expect(ReportUtils.shouldDisplayAsFraction(undefined)).toEqual(false);
475
277
  });
476
278
  });
477
279
 
@@ -486,7 +288,7 @@ describe('util helpers', () => {
486
288
  {weight: 1, result: {score: 0, scoreDisplayMode: 'binary'}, group: 'metrics'},
487
289
  ],
488
290
  };
489
- const fraction = Util.calculateCategoryFraction(category);
291
+ const fraction = ReportUtils.calculateCategoryFraction(category);
490
292
  expect(fraction).toEqual({
491
293
  numPassableAudits: 4,
492
294
  numPassed: 3,
@@ -505,7 +307,7 @@ describe('util helpers', () => {
505
307
  {weight: 1, result: {score: 0, scoreDisplayMode: 'notApplicable'}, group: 'metrics'},
506
308
  ],
507
309
  };
508
- const fraction = Util.calculateCategoryFraction(category);
310
+ const fraction = ReportUtils.calculateCategoryFraction(category);
509
311
  expect(fraction).toEqual({
510
312
  numPassableAudits: 1,
511
313
  numPassed: 1,
@@ -524,7 +326,7 @@ describe('util helpers', () => {
524
326
  {weight: 1, result: {score: 0, scoreDisplayMode: 'informative'}, group: 'metrics'},
525
327
  ],
526
328
  };
527
- const fraction = Util.calculateCategoryFraction(category);
329
+ const fraction = ReportUtils.calculateCategoryFraction(category);
528
330
  expect(fraction).toEqual({
529
331
  numPassableAudits: 2,
530
332
  numPassed: 2,
@@ -8,10 +8,10 @@ import assert from 'assert/strict';
8
8
 
9
9
  import jsdom from 'jsdom';
10
10
 
11
- import {Util} from '../../renderer/util.js';
12
11
  import {I18nFormatter} from '../../renderer/i18n-formatter.js';
13
12
  import {DOM} from '../../renderer/dom.js';
14
13
  import {SnippetRenderer} from '../../renderer/snippet-renderer.js';
14
+ import {Globals} from '../../renderer/report-globals.js';
15
15
 
16
16
  /* Generates a snippet lines array like this (for a single range from 1 to 4):
17
17
  [
@@ -55,13 +55,17 @@ describe('DetailsRenderer', () => {
55
55
  let dom;
56
56
 
57
57
  before(() => {
58
- Util.i18n = new I18nFormatter('en');
58
+ Globals.apply({
59
+ providedStrings: {},
60
+ i18n: new I18nFormatter('en'),
61
+ reportJson: null,
62
+ });
59
63
  const {document} = new jsdom.JSDOM().window;
60
64
  dom = new DOM(document);
61
65
  });
62
66
 
63
67
  after(() => {
64
- Util.i18n = undefined;
68
+ Globals.i18n = undefined;
65
69
  });
66
70
 
67
71
  function renderSnippet(details) {
@@ -221,12 +221,15 @@ function getRendererFormattedStrings(locale) {
221
221
 
222
222
  // If `localeMessages` is empty in the bundled and DEFAULT_LOCALE case, this
223
223
  // will be empty and the report will fall back to the util UIStrings for these.
224
- const icuMessageIds = Object.keys(localeMessages).filter(f => f.startsWith('report/'));
224
+ const icuMessageIds = Object.keys(localeMessages)
225
+ .filter(f => f.startsWith('report/renderer/report-utils.js'));
225
226
  /** @type {Record<string, string>} */
226
227
  const strings = {};
227
228
  for (const icuMessageId of icuMessageIds) {
228
229
  const {filename, key} = getIcuMessageIdParts(icuMessageId);
229
- if (!filename.endsWith('util.js')) throw new Error(`Unexpected message: ${icuMessageId}`);
230
+ if (!filename.endsWith('report-utils.js')) {
231
+ throw new Error(`Unexpected message: ${icuMessageId}`);
232
+ }
230
233
 
231
234
  strings[key] = localeMessages[icuMessageId].message;
232
235
  }
@@ -2327,154 +2327,154 @@
2327
2327
  "node_modules/lighthouse-stack-packs/packs/wordpress.js | uses-text-compression": {
2328
2328
  "message": "‏‮You‬‏ ‏‮can‬‏ ‏‮enable‬‏ ‏‮text‬‏ ‏‮compression‬‏ ‏‮in‬‏ ‏‮your‬‏ ‏‮web‬‏ ‏‮server‬‏ ‏‮configuration‬‏."
2329
2329
  },
2330
- "report/renderer/util.js | calculatorLink": {
2330
+ "report/renderer/report-utils.js | calculatorLink": {
2331
2331
  "message": "‏‮See‬‏ ‏‮calculator‬‏."
2332
2332
  },
2333
- "report/renderer/util.js | collapseView": {
2333
+ "report/renderer/report-utils.js | collapseView": {
2334
2334
  "message": "‏‮Collapse‬‏ ‏‮view‬‏"
2335
2335
  },
2336
- "report/renderer/util.js | crcInitialNavigation": {
2336
+ "report/renderer/report-utils.js | crcInitialNavigation": {
2337
2337
  "message": "‏‮Initial‬‏ ‏‮Navigation‬‏"
2338
2338
  },
2339
- "report/renderer/util.js | crcLongestDurationLabel": {
2339
+ "report/renderer/report-utils.js | crcLongestDurationLabel": {
2340
2340
  "message": "‏‮Maximum‬‏ ‏‮critical‬‏ ‏‮path‬‏ ‏‮latency‬‏:"
2341
2341
  },
2342
- "report/renderer/util.js | dropdownCopyJSON": {
2342
+ "report/renderer/report-utils.js | dropdownCopyJSON": {
2343
2343
  "message": "‏‮Copy‬‏ ‏‮JSON‬‏"
2344
2344
  },
2345
- "report/renderer/util.js | dropdownDarkTheme": {
2345
+ "report/renderer/report-utils.js | dropdownDarkTheme": {
2346
2346
  "message": "‏‮Toggle‬‏ ‏‮Dark‬‏ ‏‮Theme‬‏"
2347
2347
  },
2348
- "report/renderer/util.js | dropdownPrintExpanded": {
2348
+ "report/renderer/report-utils.js | dropdownPrintExpanded": {
2349
2349
  "message": "‏‮Print‬‏ ‏‮Expanded‬‏"
2350
2350
  },
2351
- "report/renderer/util.js | dropdownPrintSummary": {
2351
+ "report/renderer/report-utils.js | dropdownPrintSummary": {
2352
2352
  "message": "‏‮Print‬‏ ‏‮Summary‬‏"
2353
2353
  },
2354
- "report/renderer/util.js | dropdownSaveGist": {
2354
+ "report/renderer/report-utils.js | dropdownSaveGist": {
2355
2355
  "message": "‏‮Save‬‏ ‏‮as‬‏ ‏‮Gist‬‏"
2356
2356
  },
2357
- "report/renderer/util.js | dropdownSaveHTML": {
2357
+ "report/renderer/report-utils.js | dropdownSaveHTML": {
2358
2358
  "message": "‏‮Save‬‏ ‏‮as‬‏ ‏‮HTML‬‏"
2359
2359
  },
2360
- "report/renderer/util.js | dropdownSaveJSON": {
2360
+ "report/renderer/report-utils.js | dropdownSaveJSON": {
2361
2361
  "message": "‏‮Save‬‏ ‏‮as‬‏ ‏‮JSON‬‏"
2362
2362
  },
2363
- "report/renderer/util.js | dropdownViewer": {
2363
+ "report/renderer/report-utils.js | dropdownViewer": {
2364
2364
  "message": "‏‮Open‬‏ ‏‮in‬‏ ‏‮Viewer‬‏"
2365
2365
  },
2366
- "report/renderer/util.js | errorLabel": {
2366
+ "report/renderer/report-utils.js | errorLabel": {
2367
2367
  "message": "‏‮Error‬‏!"
2368
2368
  },
2369
- "report/renderer/util.js | errorMissingAuditInfo": {
2369
+ "report/renderer/report-utils.js | errorMissingAuditInfo": {
2370
2370
  "message": "‏‮Report‬‏ ‏‮error‬‏: ‏‮no‬‏ ‏‮audit‬‏ ‏‮information‬‏"
2371
2371
  },
2372
- "report/renderer/util.js | expandView": {
2372
+ "report/renderer/report-utils.js | expandView": {
2373
2373
  "message": "‏‮Expand‬‏ ‏‮view‬‏"
2374
2374
  },
2375
- "report/renderer/util.js | footerIssue": {
2375
+ "report/renderer/report-utils.js | footerIssue": {
2376
2376
  "message": "‏‮File‬‏ ‏‮an‬‏ ‏‮issue‬‏"
2377
2377
  },
2378
- "report/renderer/util.js | hide": {
2378
+ "report/renderer/report-utils.js | hide": {
2379
2379
  "message": "‏‮Hide‬‏"
2380
2380
  },
2381
- "report/renderer/util.js | labDataTitle": {
2381
+ "report/renderer/report-utils.js | labDataTitle": {
2382
2382
  "message": "‏‮Lab‬‏ ‏‮Data‬‏"
2383
2383
  },
2384
- "report/renderer/util.js | lsPerformanceCategoryDescription": {
2384
+ "report/renderer/report-utils.js | lsPerformanceCategoryDescription": {
2385
2385
  "message": "[‏‮Lighthouse‬‏](https://developers.google.com/web/tools/lighthouse/) ‏‮analysis‬‏ ‏‮of‬‏ ‏‮the‬‏ ‏‮current‬‏ ‏‮page‬‏ ‏‮on‬‏ ‏‮an‬‏ ‏‮emulated‬‏ ‏‮mobile‬‏ ‏‮network‬‏. ‏‮Values‬‏ ‏‮are‬‏ ‏‮estimated‬‏ ‏‮and‬‏ ‏‮may‬‏ ‏‮vary‬‏."
2386
2386
  },
2387
- "report/renderer/util.js | manualAuditsGroupTitle": {
2387
+ "report/renderer/report-utils.js | manualAuditsGroupTitle": {
2388
2388
  "message": "‏‮Additional‬‏ ‏‮items‬‏ ‏‮to‬‏ ‏‮manually‬‏ ‏‮check‬‏"
2389
2389
  },
2390
- "report/renderer/util.js | notApplicableAuditsGroupTitle": {
2390
+ "report/renderer/report-utils.js | notApplicableAuditsGroupTitle": {
2391
2391
  "message": "‏‮Not‬‏ ‏‮applicable‬‏"
2392
2392
  },
2393
- "report/renderer/util.js | opportunityResourceColumnLabel": {
2393
+ "report/renderer/report-utils.js | opportunityResourceColumnLabel": {
2394
2394
  "message": "‏‮Opportunity‬‏"
2395
2395
  },
2396
- "report/renderer/util.js | opportunitySavingsColumnLabel": {
2396
+ "report/renderer/report-utils.js | opportunitySavingsColumnLabel": {
2397
2397
  "message": "‏‮Estimated‬‏ ‏‮Savings‬‏"
2398
2398
  },
2399
- "report/renderer/util.js | passedAuditsGroupTitle": {
2399
+ "report/renderer/report-utils.js | passedAuditsGroupTitle": {
2400
2400
  "message": "‏‮Passed‬‏ ‏‮audits‬‏"
2401
2401
  },
2402
- "report/renderer/util.js | runtimeAnalysisWindow": {
2402
+ "report/renderer/report-utils.js | runtimeAnalysisWindow": {
2403
2403
  "message": "‏‮Initial‬‏ ‏‮page‬‏ ‏‮load‬‏"
2404
2404
  },
2405
- "report/renderer/util.js | runtimeCustom": {
2405
+ "report/renderer/report-utils.js | runtimeCustom": {
2406
2406
  "message": "‏‮Custom‬‏ ‏‮throttling‬‏"
2407
2407
  },
2408
- "report/renderer/util.js | runtimeDesktopEmulation": {
2408
+ "report/renderer/report-utils.js | runtimeDesktopEmulation": {
2409
2409
  "message": "‏‮Emulated‬‏ ‏‮Desktop‬‏"
2410
2410
  },
2411
- "report/renderer/util.js | runtimeMobileEmulation": {
2411
+ "report/renderer/report-utils.js | runtimeMobileEmulation": {
2412
2412
  "message": "‏‮Emulated‬‏ ‏‮Moto‬‏ ‏‮G‬‏4"
2413
2413
  },
2414
- "report/renderer/util.js | runtimeNoEmulation": {
2414
+ "report/renderer/report-utils.js | runtimeNoEmulation": {
2415
2415
  "message": "‏‮No‬‏ ‏‮emulation‬‏"
2416
2416
  },
2417
- "report/renderer/util.js | runtimeSettingsAxeVersion": {
2417
+ "report/renderer/report-utils.js | runtimeSettingsAxeVersion": {
2418
2418
  "message": "‏‮Axe‬‏ ‏‮version‬‏"
2419
2419
  },
2420
- "report/renderer/util.js | runtimeSettingsBenchmark": {
2420
+ "report/renderer/report-utils.js | runtimeSettingsBenchmark": {
2421
2421
  "message": "‏‮CPU‬‏/‏‮Memory‬‏ ‏‮Power‬‏"
2422
2422
  },
2423
- "report/renderer/util.js | runtimeSettingsCPUThrottling": {
2423
+ "report/renderer/report-utils.js | runtimeSettingsCPUThrottling": {
2424
2424
  "message": "‏‮CPU‬‏ ‏‮throttling‬‏"
2425
2425
  },
2426
- "report/renderer/util.js | runtimeSettingsDevice": {
2426
+ "report/renderer/report-utils.js | runtimeSettingsDevice": {
2427
2427
  "message": "‏‮Device‬‏"
2428
2428
  },
2429
- "report/renderer/util.js | runtimeSettingsNetworkThrottling": {
2429
+ "report/renderer/report-utils.js | runtimeSettingsNetworkThrottling": {
2430
2430
  "message": "‏‮Network‬‏ ‏‮throttling‬‏"
2431
2431
  },
2432
- "report/renderer/util.js | runtimeSettingsUANetwork": {
2432
+ "report/renderer/report-utils.js | runtimeSettingsUANetwork": {
2433
2433
  "message": "‏‮User‬‏ ‏‮agent‬‏ (‏‮network‬‏)"
2434
2434
  },
2435
- "report/renderer/util.js | runtimeSingleLoad": {
2435
+ "report/renderer/report-utils.js | runtimeSingleLoad": {
2436
2436
  "message": "‏‮Single‬‏ ‏‮page‬‏ ‏‮load‬‏"
2437
2437
  },
2438
- "report/renderer/util.js | runtimeSingleLoadTooltip": {
2438
+ "report/renderer/report-utils.js | runtimeSingleLoadTooltip": {
2439
2439
  "message": "‏‮This‬‏ ‏‮data‬‏ ‏‮is‬‏ ‏‮taken‬‏ ‏‮from‬‏ ‏‮a‬‏ ‏‮single‬‏ ‏‮page‬‏ ‏‮load‬‏, ‏‮as‬‏ ‏‮opposed‬‏ ‏‮to‬‏ ‏‮field‬‏ ‏‮data‬‏ ‏‮summarizing‬‏ ‏‮many‬‏ ‏‮sessions‬‏."
2440
2440
  },
2441
- "report/renderer/util.js | runtimeSlow4g": {
2441
+ "report/renderer/report-utils.js | runtimeSlow4g": {
2442
2442
  "message": "‏‮Slow‬‏ 4‏‮G‬‏ ‏‮throttling‬‏"
2443
2443
  },
2444
- "report/renderer/util.js | runtimeUnknown": {
2444
+ "report/renderer/report-utils.js | runtimeUnknown": {
2445
2445
  "message": "‏‮Unknown‬‏"
2446
2446
  },
2447
- "report/renderer/util.js | show": {
2447
+ "report/renderer/report-utils.js | show": {
2448
2448
  "message": "‏‮Show‬‏"
2449
2449
  },
2450
- "report/renderer/util.js | showRelevantAudits": {
2450
+ "report/renderer/report-utils.js | showRelevantAudits": {
2451
2451
  "message": "‏‮Show‬‏ ‏‮audits‬‏ ‏‮relevant‬‏ ‏‮to‬‏:"
2452
2452
  },
2453
- "report/renderer/util.js | snippetCollapseButtonLabel": {
2453
+ "report/renderer/report-utils.js | snippetCollapseButtonLabel": {
2454
2454
  "message": "‏‮Collapse‬‏ ‏‮snippet‬‏"
2455
2455
  },
2456
- "report/renderer/util.js | snippetExpandButtonLabel": {
2456
+ "report/renderer/report-utils.js | snippetExpandButtonLabel": {
2457
2457
  "message": "‏‮Expand‬‏ ‏‮snippet‬‏"
2458
2458
  },
2459
- "report/renderer/util.js | thirdPartyResourcesLabel": {
2459
+ "report/renderer/report-utils.js | thirdPartyResourcesLabel": {
2460
2460
  "message": "‏‮Show‬‏ 3‏‮rd‬‏-‏‮party‬‏ ‏‮resources‬‏"
2461
2461
  },
2462
- "report/renderer/util.js | throttlingProvided": {
2462
+ "report/renderer/report-utils.js | throttlingProvided": {
2463
2463
  "message": "‏‮Provided‬‏ ‏‮by‬‏ ‏‮environment‬‏"
2464
2464
  },
2465
- "report/renderer/util.js | toplevelWarningsMessage": {
2465
+ "report/renderer/report-utils.js | toplevelWarningsMessage": {
2466
2466
  "message": "‏‮There‬‏ ‏‮were‬‏ ‏‮issues‬‏ ‏‮affecting‬‏ ‏‮this‬‏ ‏‮run‬‏ ‏‮of‬‏ ‏‮Lighthouse‬‏:"
2467
2467
  },
2468
- "report/renderer/util.js | varianceDisclaimer": {
2468
+ "report/renderer/report-utils.js | varianceDisclaimer": {
2469
2469
  "message": "‏‮Values‬‏ ‏‮are‬‏ ‏‮estimated‬‏ ‏‮and‬‏ ‏‮may‬‏ ‏‮vary‬‏. ‏‮The‬‏ [‏‮performance‬‏ ‏‮score‬‏ ‏‮is‬‏ ‏‮calculated‬‏](https://web.dev/performance-scoring/) ‏‮directly‬‏ ‏‮from‬‏ ‏‮these‬‏ ‏‮metrics‬‏."
2470
2470
  },
2471
- "report/renderer/util.js | viewTreemapLabel": {
2471
+ "report/renderer/report-utils.js | viewTreemapLabel": {
2472
2472
  "message": "‏‮View‬‏ ‏‮Treemap‬‏"
2473
2473
  },
2474
- "report/renderer/util.js | warningAuditsGroupTitle": {
2474
+ "report/renderer/report-utils.js | warningAuditsGroupTitle": {
2475
2475
  "message": "‏‮Passed‬‏ ‏‮audits‬‏ ‏‮but‬‏ ‏‮with‬‏ ‏‮warnings‬‏"
2476
2476
  },
2477
- "report/renderer/util.js | warningHeader": {
2477
+ "report/renderer/report-utils.js | warningHeader": {
2478
2478
  "message": "‏‮Warnings‬‏: "
2479
2479
  },
2480
2480
  "treemap/app/src/util.js | allLabel": {