lighthouse 9.5.0-dev.20220416 → 9.5.0-dev.20220419

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 (83) hide show
  1. package/dist/report/bundle.esm.js +117 -70
  2. package/dist/report/flow.js +23 -23
  3. package/dist/report/standalone.js +14 -14
  4. package/flow-report/src/summary/category.tsx +1 -1
  5. package/lighthouse-cli/.eslintrc.cjs +3 -4
  6. package/lighthouse-cli/bin.js +0 -1
  7. package/lighthouse-cli/cli-flags.js +0 -1
  8. package/lighthouse-cli/commands/commands.js +0 -1
  9. package/lighthouse-cli/commands/list-audits.js +0 -1
  10. package/lighthouse-cli/commands/list-locales.js +0 -1
  11. package/lighthouse-cli/commands/list-trace-categories.js +0 -1
  12. package/lighthouse-cli/index.js +0 -1
  13. package/lighthouse-cli/printer.js +0 -1
  14. package/lighthouse-cli/run.js +0 -1
  15. package/lighthouse-cli/sentry-prompt.js +0 -1
  16. package/lighthouse-cli/test/smokehouse/core-tests.js +0 -1
  17. package/lighthouse-cli/test/smokehouse/frontends/back-compat-util.js +0 -1
  18. package/lighthouse-cli/test/smokehouse/frontends/lib.js +0 -1
  19. package/lighthouse-cli/test/smokehouse/frontends/node.js +0 -1
  20. package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +0 -1
  21. package/lighthouse-cli/test/smokehouse/lib/child-process-error.js +0 -1
  22. package/lighthouse-cli/test/smokehouse/lib/concurrent-mapper.js +0 -1
  23. package/lighthouse-cli/test/smokehouse/lib/local-console.js +0 -1
  24. package/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js +0 -1
  25. package/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js +0 -1
  26. package/lighthouse-cli/test/smokehouse/lighthouse-runners/devtools.js +0 -1
  27. package/lighthouse-cli/test/smokehouse/report-assert.js +0 -1
  28. package/lighthouse-cli/test/smokehouse/smokehouse.js +0 -1
  29. package/lighthouse-core/audits/byte-efficiency/legacy-javascript.js +1 -1
  30. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +16 -2
  31. package/lighthouse-core/gather/gatherers/full-page-screenshot.js +3 -2
  32. package/lighthouse-core/index.js +2 -9
  33. package/lighthouse-core/lib/stack-packs.js +4 -0
  34. package/lighthouse-core/scripts/manual-chrome-launcher.js +0 -1
  35. package/lighthouse-core/util-commonjs.js +14 -8
  36. package/package.json +3 -3
  37. package/report/.eslintrc.cjs +3 -1
  38. package/report/assets/styles.css +5 -2
  39. package/report/assets/templates.html +10 -9
  40. package/report/clients/bundle.js +0 -1
  41. package/report/clients/standalone.js +0 -1
  42. package/report/renderer/api.js +0 -1
  43. package/report/renderer/category-renderer.js +0 -1
  44. package/report/renderer/components.js +13 -14
  45. package/report/renderer/crc-details-renderer.js +0 -1
  46. package/report/renderer/details-renderer.js +0 -1
  47. package/report/renderer/dom.js +0 -1
  48. package/report/renderer/drop-down-menu.js +0 -1
  49. package/report/renderer/element-screenshot-renderer.js +0 -4
  50. package/report/renderer/features-util.js +0 -1
  51. package/report/renderer/i18n.js +91 -49
  52. package/report/renderer/logger.js +0 -1
  53. package/report/renderer/open-tab.js +0 -1
  54. package/report/renderer/performance-category-renderer.js +0 -1
  55. package/report/renderer/pwa-category-renderer.js +0 -1
  56. package/report/renderer/report-renderer.js +0 -1
  57. package/report/renderer/report-ui-features.js +0 -1
  58. package/report/renderer/snippet-renderer.js +0 -1
  59. package/report/renderer/swap-locale-feature.js +0 -1
  60. package/report/renderer/text-encoding.js +0 -1
  61. package/report/renderer/topbar-features.js +0 -1
  62. package/report/renderer/util.js +13 -8
  63. package/report/test/clients/bundle-test.js +0 -1
  64. package/report/test/renderer/category-renderer-test.js +0 -1
  65. package/report/test/renderer/components-test.js +0 -1
  66. package/report/test/renderer/crc-details-renderer-test.js +0 -1
  67. package/report/test/renderer/details-renderer-test.js +0 -1
  68. package/report/test/renderer/dom-test.js +0 -1
  69. package/report/test/renderer/element-screenshot-renderer-test.js +3 -4
  70. package/report/test/renderer/i18n-test.js +26 -8
  71. package/report/test/renderer/performance-category-renderer-test.js +0 -1
  72. package/report/test/renderer/pwa-category-renderer-test.js +0 -1
  73. package/report/test/renderer/report-renderer-axe-test.js +0 -1
  74. package/report/test/renderer/report-renderer-test.js +0 -1
  75. package/report/test/renderer/report-ui-features-test.js +0 -1
  76. package/report/test/renderer/snippet-renderer-test.js +0 -1
  77. package/report/test/renderer/text-encoding-test.js +0 -1
  78. package/report/test/renderer/util-test.js +2 -3
  79. package/report/test-assets/faux-psi.js +0 -1
  80. package/shared/localization/locales/en-US.json +26 -5
  81. package/shared/localization/locales/en-XL.json +26 -5
  82. package/third-party/snyk/snapshot.json +2 -2
  83. package/types/config.d.ts +2 -0
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  // Not named `NBSP` because that creates a duplicate identifier (util.js).
9
8
  const NBSP2 = '\xa0';
@@ -22,9 +21,7 @@ export class I18n {
22
21
  // When testing, use a locale with more exciting numeric formatting.
23
22
  if (locale === 'en-XA') locale = 'de';
24
23
 
25
- this._numberDateLocale = locale;
26
- this._numberFormatter = new Intl.NumberFormat(locale);
27
- this._percentFormatter = new Intl.NumberFormat(locale, {style: 'percent'});
24
+ this._locale = locale;
28
25
  this._strings = strings;
29
26
  }
30
27
 
@@ -32,6 +29,32 @@ export class I18n {
32
29
  return this._strings;
33
30
  }
34
31
 
32
+ /**
33
+ * @param {number} number
34
+ * @param {number} granularity
35
+ * @param {Intl.NumberFormatOptions} opts
36
+ * @return {string}
37
+ */
38
+ _formatNumberWithGranularity(number, granularity, opts = {}) {
39
+ opts = {...opts};
40
+ const log10 = -Math.log10(granularity);
41
+ if (!Number.isFinite(log10) || (granularity > 1 && !Number.isInteger(log10))) {
42
+ console.warn(`granularity of ${granularity} is invalid, defaulting to value of 1`);
43
+ granularity = 1;
44
+ }
45
+
46
+ if (granularity < 1) {
47
+ opts.minimumFractionDigits = opts.maximumFractionDigits = Math.ceil(log10);
48
+ }
49
+
50
+ number = Math.round(number / granularity) * granularity;
51
+
52
+ // Avoid displaying a negative value that rounds to zero as "0".
53
+ if (Object.is(number, -0)) number = 0;
54
+
55
+ return new Intl.NumberFormat(this._locale, opts).format(number).replace(' ', NBSP2);
56
+ }
57
+
35
58
  /**
36
59
  * Format number.
37
60
  * @param {number} number
@@ -39,8 +62,18 @@ export class I18n {
39
62
  * @return {string}
40
63
  */
41
64
  formatNumber(number, granularity = 0.1) {
42
- const coarseValue = Math.round(number / granularity) * granularity;
43
- return this._numberFormatter.format(coarseValue);
65
+ return this._formatNumberWithGranularity(number, granularity);
66
+ }
67
+
68
+ /**
69
+ * Format integer.
70
+ * Just like {@link formatNumber} but uses a granularity of 1, rounding to the nearest
71
+ * whole number.
72
+ * @param {number} number
73
+ * @return {string}
74
+ */
75
+ formatInteger(number) {
76
+ return this._formatNumberWithGranularity(number, 1);
44
77
  }
45
78
 
46
79
  /**
@@ -49,7 +82,7 @@ export class I18n {
49
82
  * @return {string}
50
83
  */
51
84
  formatPercent(number) {
52
- return this._percentFormatter.format(number);
85
+ return new Intl.NumberFormat(this._locale, {style: 'percent'}).format(number);
53
86
  }
54
87
 
55
88
  /**
@@ -58,9 +91,7 @@ export class I18n {
58
91
  * @return {string}
59
92
  */
60
93
  formatBytesToKiB(size, granularity = 0.1) {
61
- const formatter = this._byteFormatterForGranularity(granularity);
62
- const kbs = formatter.format(Math.round(size / 1024 / granularity) * granularity);
63
- return `${kbs}${NBSP2}KiB`;
94
+ return this._formatNumberWithGranularity(size / KiB, granularity) + `${NBSP2}KiB`;
64
95
  }
65
96
 
66
97
  /**
@@ -69,9 +100,7 @@ export class I18n {
69
100
  * @return {string}
70
101
  */
71
102
  formatBytesToMiB(size, granularity = 0.1) {
72
- const formatter = this._byteFormatterForGranularity(granularity);
73
- const kbs = formatter.format(Math.round(size / (1024 ** 2) / granularity) * granularity);
74
- return `${kbs}${NBSP2}MiB`;
103
+ return this._formatNumberWithGranularity(size / MiB, granularity) + `${NBSP2}MiB`;
75
104
  }
76
105
 
77
106
  /**
@@ -80,9 +109,11 @@ export class I18n {
80
109
  * @return {string}
81
110
  */
82
111
  formatBytes(size, granularity = 1) {
83
- const formatter = this._byteFormatterForGranularity(granularity);
84
- const kbs = formatter.format(Math.round(size / granularity) * granularity);
85
- return `${kbs}${NBSP2}bytes`;
112
+ return this._formatNumberWithGranularity(size, granularity, {
113
+ style: 'unit',
114
+ unit: 'byte',
115
+ unitDisplay: 'long',
116
+ });
86
117
  }
87
118
 
88
119
  /**
@@ -93,25 +124,23 @@ export class I18n {
93
124
  formatBytesWithBestUnit(size, granularity = 0.1) {
94
125
  if (size >= MiB) return this.formatBytesToMiB(size, granularity);
95
126
  if (size >= KiB) return this.formatBytesToKiB(size, granularity);
96
- return this.formatNumber(size, granularity) + '\xa0B';
127
+ return this._formatNumberWithGranularity(size, granularity, {
128
+ style: 'unit',
129
+ unit: 'byte',
130
+ unitDisplay: 'narrow',
131
+ });
97
132
  }
98
133
 
99
134
  /**
100
- * Format bytes with a constant number of fractional digits, i.e. for a granularity of 0.1, 10 becomes '10.0'
101
- * @param {number} granularity Controls how coarse the displayed value is
102
- * @return {Intl.NumberFormat}
135
+ * @param {number} size
136
+ * @param {number=} granularity Controls how coarse the displayed value is, defaults to 1
137
+ * @return {string}
103
138
  */
104
- _byteFormatterForGranularity(granularity) {
105
- // assume any granularity above 1 will not contain fractional parts, i.e. will never be 1.5
106
- let numberOfFractionDigits = 0;
107
- if (granularity < 1) {
108
- numberOfFractionDigits = -Math.floor(Math.log10(granularity));
109
- }
110
-
111
- return new Intl.NumberFormat(this._numberDateLocale, {
112
- ...this._numberFormatter.resolvedOptions(),
113
- maximumFractionDigits: numberOfFractionDigits,
114
- minimumFractionDigits: numberOfFractionDigits,
139
+ formatKbps(size, granularity = 1) {
140
+ return this._formatNumberWithGranularity(size, granularity, {
141
+ style: 'unit',
142
+ unit: 'kilobit-per-second',
143
+ unitDisplay: 'short',
115
144
  });
116
145
  }
117
146
 
@@ -121,10 +150,11 @@ export class I18n {
121
150
  * @return {string}
122
151
  */
123
152
  formatMilliseconds(ms, granularity = 10) {
124
- const coarseTime = Math.round(ms / granularity) * granularity;
125
- return coarseTime === 0
126
- ? `${this._numberFormatter.format(0)}${NBSP2}ms`
127
- : `${this._numberFormatter.format(coarseTime)}${NBSP2}ms`;
153
+ return this._formatNumberWithGranularity(ms, granularity, {
154
+ style: 'unit',
155
+ unit: 'millisecond',
156
+ unitDisplay: 'short',
157
+ });
128
158
  }
129
159
 
130
160
  /**
@@ -133,8 +163,11 @@ export class I18n {
133
163
  * @return {string}
134
164
  */
135
165
  formatSeconds(ms, granularity = 0.1) {
136
- const coarseTime = Math.round(ms / 1000 / granularity) * granularity;
137
- return `${this._numberFormatter.format(coarseTime)}${NBSP2}s`;
166
+ return this._formatNumberWithGranularity(ms / 1000, granularity, {
167
+ style: 'unit',
168
+ unit: 'second',
169
+ unitDisplay: 'short',
170
+ });
138
171
  }
139
172
 
140
173
  /**
@@ -154,10 +187,10 @@ export class I18n {
154
187
  // and https://github.com/GoogleChrome/lighthouse/pull/9822
155
188
  let formatter;
156
189
  try {
157
- formatter = new Intl.DateTimeFormat(this._numberDateLocale, options);
190
+ formatter = new Intl.DateTimeFormat(this._locale, options);
158
191
  } catch (err) {
159
192
  options.timeZone = 'UTC';
160
- formatter = new Intl.DateTimeFormat(this._numberDateLocale, options);
193
+ formatter = new Intl.DateTimeFormat(this._locale, options);
161
194
  }
162
195
 
163
196
  return formatter.format(new Date(date));
@@ -169,6 +202,10 @@ export class I18n {
169
202
  * @return {string}
170
203
  */
171
204
  formatDuration(timeInMilliseconds) {
205
+ // There is a proposal for a Intl.DurationFormat.
206
+ // https://github.com/tc39/proposal-intl-duration-format
207
+ // Until then, we do things a bit more manually.
208
+
172
209
  let timeInSeconds = timeInMilliseconds / 1000;
173
210
  if (Math.round(timeInSeconds) === 0) {
174
211
  return 'None';
@@ -177,19 +214,24 @@ export class I18n {
177
214
  /** @type {Array<string>} */
178
215
  const parts = [];
179
216
  /** @type {Record<string, number>} */
180
- const unitLabels = {
181
- d: 60 * 60 * 24,
182
- h: 60 * 60,
183
- m: 60,
184
- s: 1,
217
+ const unitToSecondsPer = {
218
+ day: 60 * 60 * 24,
219
+ hour: 60 * 60,
220
+ minute: 60,
221
+ second: 1,
185
222
  };
186
223
 
187
- Object.keys(unitLabels).forEach(label => {
188
- const unit = unitLabels[label];
189
- const numberOfUnits = Math.floor(timeInSeconds / unit);
224
+ Object.keys(unitToSecondsPer).forEach(unit => {
225
+ const secondsPerUnit = unitToSecondsPer[unit];
226
+ const numberOfUnits = Math.floor(timeInSeconds / secondsPerUnit);
190
227
  if (numberOfUnits > 0) {
191
- timeInSeconds -= numberOfUnits * unit;
192
- parts.push(`${numberOfUnits}\xa0${label}`);
228
+ timeInSeconds -= numberOfUnits * secondsPerUnit;
229
+ const part = this._formatNumberWithGranularity(numberOfUnits, 1, {
230
+ style: 'unit',
231
+ unit,
232
+ unitDisplay: 'narrow',
233
+ });
234
+ parts.push(part);
193
235
  }
194
236
  });
195
237
 
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- 'use strict';
18
17
 
19
18
  /**
20
19
  * Logs messages via a UI butter.
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- 'use strict';
18
17
 
19
18
  import {TextEncoding} from './text-encoding.js';
20
19
 
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- 'use strict';
18
17
 
19
18
  /** @typedef {import('./dom.js').DOM} DOM */
20
19
 
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- 'use strict';
18
17
 
19
18
  import {Util} from './util.js';
20
19
  import {CategoryRenderer} from './category-renderer.js';
@@ -17,7 +17,6 @@
17
17
  * Dummy text for ensuring report robustness: </script> pre$`post %%LIGHTHOUSE_JSON%%
18
18
  * (this is handled by terser)
19
19
  */
20
- 'use strict';
21
20
 
22
21
  /** @typedef {import('./dom.js').DOM} DOM */
23
22
 
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- 'use strict';
18
17
 
19
18
  /**
20
19
  * @fileoverview Adds tools button, print, and other dynamic functionality to
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /** @typedef {import('./details-renderer').DetailsRenderer} DetailsRenderer */
9
8
  /** @typedef {import('./dom').DOM} DOM */
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /**
9
8
  * @fileoverview Creates a <select> element, filled with all supported locales
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* global CompressionStream */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env browser */
9
8
 
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- 'use strict';
18
17
 
19
18
  /** @template T @typedef {import('./i18n').I18n<T>} I18n */
20
19
 
@@ -430,10 +429,13 @@ class Util {
430
429
  break;
431
430
  case 'devtools': {
432
431
  const {cpuSlowdownMultiplier, requestLatencyMs} = throttling;
433
- cpuThrottling = `${Util.i18n.formatNumber(cpuSlowdownMultiplier)}x slowdown (DevTools)`;
434
- networkThrottling = `${Util.i18n.formatNumber(requestLatencyMs)}${NBSP}ms HTTP RTT, ` +
435
- `${Util.i18n.formatNumber(throttling.downloadThroughputKbps)}${NBSP}Kbps down, ` +
436
- `${Util.i18n.formatNumber(throttling.uploadThroughputKbps)}${NBSP}Kbps up (DevTools)`;
432
+ // TODO: better api in i18n formatter such that this isn't needed.
433
+ const cpuGranularity = Number.isInteger(cpuSlowdownMultiplier) ? 1 : 0.1;
434
+ // eslint-disable-next-line max-len
435
+ cpuThrottling = `${Util.i18n.formatNumber(cpuSlowdownMultiplier, cpuGranularity)}x slowdown (DevTools)`;
436
+ networkThrottling = `${Util.i18n.formatMilliseconds(requestLatencyMs, 1)} HTTP RTT, ` +
437
+ `${Util.i18n.formatKbps(throttling.downloadThroughputKbps)} down, ` +
438
+ `${Util.i18n.formatKbps(throttling.uploadThroughputKbps)} up (DevTools)`;
437
439
 
438
440
  const isSlow4G = () => {
439
441
  return requestLatencyMs === 150 * 3.75 &&
@@ -445,9 +447,12 @@ class Util {
445
447
  }
446
448
  case 'simulate': {
447
449
  const {cpuSlowdownMultiplier, rttMs, throughputKbps} = throttling;
448
- cpuThrottling = `${Util.i18n.formatNumber(cpuSlowdownMultiplier)}x slowdown (Simulated)`;
449
- networkThrottling = `${Util.i18n.formatNumber(rttMs)}${NBSP}ms TCP RTT, ` +
450
- `${Util.i18n.formatNumber(throughputKbps)}${NBSP}Kbps throughput (Simulated)`;
450
+ // TODO: better api in i18n formatter such that this isn't needed.
451
+ const cpuGranularity = Number.isInteger(cpuSlowdownMultiplier) ? 1 : 0.1;
452
+ // eslint-disable-next-line max-len
453
+ cpuThrottling = `${Util.i18n.formatNumber(cpuSlowdownMultiplier, cpuGranularity)}x slowdown (Simulated)`;
454
+ networkThrottling = `${Util.i18n.formatMilliseconds(rttMs)} TCP RTT, ` +
455
+ `${Util.i18n.formatKbps(throughputKbps)} throughput (Simulated)`;
451
456
 
452
457
  const isSlow4G = () => {
453
458
  return rttMs === 150 && throughputKbps === 1.6 * 1024;
@@ -4,7 +4,6 @@
4
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
5
  */
6
6
 
7
- 'use strict';
8
7
 
9
8
  import fs from 'fs';
10
9
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  import {strict as assert} from 'assert';
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  import {strict as assert} from 'assert';
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -66,7 +65,8 @@ describe('ElementScreenshotRenderer', () => {
66
65
  /* eslint-disable max-len */
67
66
  expect(htmlFormatted).toMatchInlineSnapshot(`
68
67
  "
69
- <div class=\\"lh-element-screenshot__content\\" style=\\"top: -500px;\\">
68
+ <div class=\\"lh-element-screenshot__content\\">
69
+ <div class=\\"lh-element-screenshot__image\\" style=\\"width: 500px; height: 500px; background-position-y: 0px; background-position-x: 0px; background-size: 1000px 1000px;\\">
70
70
  <div class=\\"lh-element-screenshot__mask\\" style=\\"width: 500px; height: 500px; clip-path: url(#clip-0);\\">
71
71
  <svg height=\\"0\\" width=\\"0\\"> <defs>
72
72
  <clipPath clipPathUnits=\\"objectBoundingBox\\" id=\\"clip-0\\">
@@ -74,8 +74,7 @@ describe('ElementScreenshotRenderer', () => {
74
74
  <polygon points=\\"0,0.7 1,0.7 1,1 0,1\\"></polygon>
75
75
  <polygon points=\\"0,0.1 0.1,0.1 0.1,0.7 0,0.7\\"></polygon>
76
76
  <polygon points=\\"0.5,0.1 1,0.1 1,0.7 0.5,0.7\\"></polygon></clipPath> </defs> </svg> </div>
77
- <div class=\\"lh-element-screenshot__image\\" style=\\"width: 500px; height: 500px; background-position-y: 0px; background-position-x: 0px; background-size: 1000px 1000px;\\"></div>
78
- <div class=\\"lh-element-screenshot__element-marker\\" style=\\"width: 200px; height: 300px; left: 50px; top: 50px;\\"></div> </div> "
77
+ <div class=\\"lh-element-screenshot__element-marker\\" style=\\"width: 200px; height: 300px; left: 50px; top: 50px;\\"></div> </div> </div> "
79
78
  `);
80
79
  /* eslint-enable max-len */
81
80
  });
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  import {strict as assert} from 'assert';
9
8
 
@@ -22,9 +21,12 @@ const NBSP = '\xa0';
22
21
  describe('util helpers', () => {
23
22
  it('formats a number', () => {
24
23
  const i18n = new I18n('en', {...Util.UIStrings});
25
- assert.strictEqual(i18n.formatNumber(10), '10');
26
- assert.strictEqual(i18n.formatNumber(100.01), '100');
24
+ assert.strictEqual(i18n.formatNumber(10), '10.0');
25
+ assert.strictEqual(i18n.formatNumber(100.01), '100.0');
27
26
  assert.strictEqual(i18n.formatNumber(13000.456), '13,000.5');
27
+ assert.strictEqual(i18n.formatInteger(10), '10');
28
+ assert.strictEqual(i18n.formatInteger(100.01), '100');
29
+ assert.strictEqual(i18n.formatInteger(13000.6), '13,001');
28
30
  });
29
31
 
30
32
  it('formats a date', () => {
@@ -101,9 +103,25 @@ describe('util helpers', () => {
101
103
 
102
104
  it('formats a duration', () => {
103
105
  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`);
106
+ assert.equal(i18n.formatDuration(60 * 1000), '1m');
107
+ assert.equal(i18n.formatDuration(60 * 60 * 1000 + 5000), '1h 5s');
108
+ assert.equal(i18n.formatDuration(28 * 60 * 60 * 1000 + 5000), '1d 4h 5s');
109
+ });
110
+
111
+ it('formats a duration based on locale', () => {
112
+ let i18n = new I18n('de', {...Util.UIStrings});
113
+ assert.equal(i18n.formatDuration(60 * 1000), `1${NBSP}Min.`);
114
+ assert.equal(i18n.formatDuration(60 * 60 * 1000 + 5000), `1${NBSP}Std. 5${NBSP}Sek.`);
115
+ assert.equal(
116
+ i18n.formatDuration(28 * 60 * 60 * 1000 + 5000), `1${NBSP}T 4${NBSP}Std. 5${NBSP}Sek.`);
117
+
118
+ // Yes, this is actually backwards (s h d).
119
+ i18n = new I18n('ar', {...Util.UIStrings});
120
+ /* eslint-disable no-irregular-whitespace */
121
+ assert.equal(i18n.formatDuration(60 * 1000), `١${NBSP}د`);
122
+ assert.equal(i18n.formatDuration(60 * 60 * 1000 + 5000), `١${NBSP}س ٥${NBSP}ث`);
123
+ assert.equal(i18n.formatDuration(28 * 60 * 60 * 1000 + 5000), `١ ي ٤ س ٥ ث`);
124
+ /* eslint-enable no-irregular-whitespace */
107
125
  });
108
126
 
109
127
  it('formats numbers based on locale', () => {
@@ -114,7 +132,7 @@ describe('util helpers', () => {
114
132
  assert.strictEqual(i18n.formatNumber(number), '12.346,9');
115
133
  assert.strictEqual(i18n.formatBytesToKiB(number), `12,1${NBSP}KiB`);
116
134
  assert.strictEqual(i18n.formatMilliseconds(number), `12.350${NBSP}ms`);
117
- assert.strictEqual(i18n.formatSeconds(number), `12,3${NBSP}s`);
135
+ assert.strictEqual(i18n.formatSeconds(number), `12,3${NBSP}Sek.`);
118
136
  });
119
137
 
120
138
  it('uses decimal comma with en-XA test locale', () => {
@@ -125,7 +143,7 @@ describe('util helpers', () => {
125
143
  assert.strictEqual(i18n.formatNumber(number), '12.346,9');
126
144
  assert.strictEqual(i18n.formatBytesToKiB(number), `12,1${NBSP}KiB`);
127
145
  assert.strictEqual(i18n.formatMilliseconds(number), `12.350${NBSP}ms`);
128
- assert.strictEqual(i18n.formatSeconds(number), `12,3${NBSP}s`);
146
+ assert.strictEqual(i18n.formatSeconds(number), `12,3${NBSP}Sek.`);
129
147
  });
130
148
 
131
149
  it('should not crash on unknown locales', () => {
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /* eslint-env jest */
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  import fs from 'fs';
9
8
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  import {strict as assert} from 'assert';
9
8
 
@@ -57,7 +56,7 @@ describe('util helpers', () => {
57
56
  });
58
57
 
59
58
  // eslint-disable-next-line max-len
60
- assert.equal(descriptions.networkThrottling, '565\xa0ms HTTP RTT, 1,400\xa0Kbps down, 600\xa0Kbps up (DevTools)');
59
+ assert.equal(descriptions.networkThrottling, '565\xa0ms HTTP RTT, 1,400\xa0kb/s down, 600\xa0kb/s up (DevTools)');
61
60
  assert.equal(descriptions.cpuThrottling, '4.5x slowdown (DevTools)');
62
61
  });
63
62
 
@@ -72,7 +71,7 @@ describe('util helpers', () => {
72
71
  });
73
72
 
74
73
  // eslint-disable-next-line max-len
75
- assert.equal(descriptions.networkThrottling, '150\xa0ms TCP RTT, 1,600\xa0Kbps throughput (Simulated)');
74
+ assert.equal(descriptions.networkThrottling, '150\xa0ms TCP RTT, 1,600\xa0kb/s throughput (Simulated)');
76
75
  assert.equal(descriptions.cpuThrottling, '2x slowdown (Simulated)');
77
76
  });
78
77
 
@@ -3,7 +3,6 @@
3
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
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
5
  */
6
- 'use strict';
7
6
 
8
7
  /** @fileoverview This file exercises two LH reports within the same DOM. */
9
8