lighthouse 9.5.0-dev.20230122 → 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.
- package/.codecov.yml +0 -5
- package/core/audits/audit.js +1 -1
- package/core/audits/bf-cache.js +1 -1
- package/core/audits/byte-efficiency/legacy-javascript.d.ts +1 -0
- package/core/audits/byte-efficiency/legacy-javascript.js +7 -3
- package/core/audits/dobetterweb/uses-http2.d.ts +5 -2
- package/core/audits/dobetterweb/uses-http2.js +12 -7
- package/core/audits/screenshot-thumbnails.d.ts +2 -1
- package/core/audits/screenshot-thumbnails.js +14 -9
- package/core/audits/third-party-facades.d.ts +3 -2
- package/core/audits/third-party-facades.js +12 -9
- package/core/audits/third-party-summary.d.ts +7 -6
- package/core/audits/third-party-summary.js +16 -14
- package/core/audits/valid-source-maps.d.ts +5 -3
- package/core/audits/valid-source-maps.js +11 -9
- package/core/computed/entity-classification.d.ts +29 -0
- package/core/computed/entity-classification.js +102 -0
- package/core/computed/processed-navigation.d.ts +12 -6
- package/core/computed/processed-navigation.js +19 -6
- package/core/computed/resource-summary.d.ts +4 -2
- package/core/computed/resource-summary.js +8 -5
- package/core/lib/url-utils.js +1 -1
- package/core/runner.d.ts +10 -0
- package/core/runner.js +48 -0
- package/core/util.cjs +43 -10
- package/core/util.d.cts +114 -2
- package/dist/report/bundle.esm.js +858 -883
- package/dist/report/flow.js +33 -23
- package/dist/report/standalone.js +27 -17
- package/flow-report/assets/standalone-flow-template.html +1 -1
- package/flow-report/src/common.tsx +1 -1
- package/flow-report/src/i18n/i18n.d.ts +103 -100
- package/flow-report/src/i18n/i18n.tsx +23 -18
- package/flow-report/src/sidebar/sidebar.tsx +3 -3
- package/flow-report/src/summary/category.tsx +7 -7
- package/flow-report/src/summary/summary.tsx +2 -2
- package/flow-report/src/topbar.tsx +4 -28
- package/package.json +5 -5
- package/readme.md +1 -1
- package/report/assets/standalone-template.html +1 -1
- package/report/assets/styles.css +3 -3
- package/report/assets/templates.html +4 -28
- package/report/renderer/category-renderer.js +19 -17
- package/report/renderer/components.js +119 -202
- package/report/renderer/crc-details-renderer.js +7 -6
- package/report/renderer/details-renderer.js +7 -6
- package/report/renderer/dom.js +1 -1
- package/report/renderer/element-screenshot-renderer.js +3 -3
- package/report/renderer/{i18n.d.ts → i18n-formatter.d.ts} +3 -9
- package/report/renderer/{i18n.js → i18n-formatter.js} +2 -11
- package/report/renderer/performance-category-renderer.js +17 -15
- package/report/renderer/pwa-category-renderer.js +5 -4
- package/report/renderer/report-globals.d.ts +21 -0
- package/report/renderer/report-globals.js +49 -0
- package/report/renderer/report-renderer.js +22 -24
- package/report/renderer/report-ui-features.js +9 -8
- package/report/renderer/report-utils.d.ts +116 -0
- package/report/renderer/{util.js → report-utils.js} +100 -415
- package/report/renderer/snippet-renderer.js +3 -2
- package/report/test/renderer/category-renderer-test.js +10 -5
- package/report/test/renderer/crc-details-renderer-test.js +8 -4
- package/report/test/renderer/details-renderer-test.js +8 -4
- package/report/test/renderer/dom-test.js +8 -4
- package/report/test/renderer/element-screenshot-renderer-test.js +9 -5
- package/report/test/renderer/{i18n-test.js → i18n-formatter-test.js} +15 -21
- package/report/test/renderer/performance-category-renderer-test.js +15 -10
- package/report/test/renderer/pwa-category-renderer-test.js +11 -6
- package/report/test/renderer/report-renderer-test.js +2 -2
- package/report/test/renderer/report-ui-features-test.js +3 -3
- package/report/test/renderer/{util-test.js → report-utils-test.js} +37 -235
- package/report/test/renderer/snippet-renderer-test.js +8 -4
- package/report/test-assets/lhr-3.0.0.json +2332 -0
- package/report/test-assets/lhr-4.3.0.json +4754 -0
- package/report/test-assets/lhr-5.0.0.json +5994 -0
- package/report/test-assets/lhr-6.0.0.json +7222 -0
- package/report/test-assets/lhr-8.5.0.json +8679 -0
- package/shared/localization/format.js +5 -2
- package/shared/localization/locales/ar-XB.json +50 -50
- package/shared/localization/locales/ar.json +50 -50
- package/shared/localization/locales/bg.json +50 -50
- package/shared/localization/locales/ca.json +50 -50
- package/shared/localization/locales/cs.json +50 -50
- package/shared/localization/locales/da.json +50 -50
- package/shared/localization/locales/de.json +50 -50
- package/shared/localization/locales/el.json +50 -50
- package/shared/localization/locales/en-GB.json +50 -50
- package/shared/localization/locales/en-US.json +55 -55
- package/shared/localization/locales/en-XA.json +50 -50
- package/shared/localization/locales/en-XL.json +55 -55
- package/shared/localization/locales/es-419.json +50 -50
- package/shared/localization/locales/es.json +50 -50
- package/shared/localization/locales/fi.json +50 -50
- package/shared/localization/locales/fil.json +50 -50
- package/shared/localization/locales/fr.json +50 -50
- package/shared/localization/locales/he.json +50 -50
- package/shared/localization/locales/hi.json +50 -50
- package/shared/localization/locales/hr.json +50 -50
- package/shared/localization/locales/hu.json +50 -50
- package/shared/localization/locales/id.json +50 -50
- package/shared/localization/locales/it.json +50 -50
- package/shared/localization/locales/ja.json +50 -50
- package/shared/localization/locales/ko.json +50 -50
- package/shared/localization/locales/lt.json +50 -50
- package/shared/localization/locales/lv.json +50 -50
- package/shared/localization/locales/nl.json +50 -50
- package/shared/localization/locales/no.json +50 -50
- package/shared/localization/locales/pl.json +50 -50
- package/shared/localization/locales/pt-PT.json +50 -50
- package/shared/localization/locales/pt.json +50 -50
- package/shared/localization/locales/ro.json +50 -50
- package/shared/localization/locales/ru.json +50 -50
- package/shared/localization/locales/sk.json +50 -50
- package/shared/localization/locales/sl.json +50 -50
- package/shared/localization/locales/sr-Latn.json +50 -50
- package/shared/localization/locales/sr.json +50 -50
- package/shared/localization/locales/sv.json +50 -50
- package/shared/localization/locales/ta.json +50 -50
- package/shared/localization/locales/te.json +50 -50
- package/shared/localization/locales/th.json +50 -50
- package/shared/localization/locales/tr.json +50 -50
- package/shared/localization/locales/uk.json +50 -50
- package/shared/localization/locales/vi.json +50 -50
- package/shared/localization/locales/zh-HK.json +50 -50
- package/shared/localization/locales/zh-TW.json +50 -50
- package/shared/localization/locales/zh.json +50 -50
- package/shared/test/util-test.js +214 -0
- package/shared/util.d.ts +122 -0
- package/shared/util.js +332 -0
- package/types/artifacts.d.ts +14 -0
- package/types/lhr/lhr.d.ts +33 -0
- package/report/renderer/util.d.ts +0 -230
|
@@ -6,34 +6,39 @@
|
|
|
6
6
|
|
|
7
7
|
import assert from 'assert/strict';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import {ReportUtils} from '../../renderer/report-utils.js';
|
|
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
|
-
|
|
18
|
+
Globals.apply({
|
|
19
|
+
providedStrings: {},
|
|
20
|
+
i18n: new I18nFormatter('en'),
|
|
21
|
+
reportJson: null,
|
|
22
|
+
});
|
|
18
23
|
});
|
|
19
24
|
|
|
20
25
|
afterEach(() => {
|
|
21
|
-
|
|
26
|
+
Globals.i18n = undefined;
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
it('calculates a score ratings', () => {
|
|
25
|
-
assert.equal(
|
|
26
|
-
assert.equal(
|
|
27
|
-
assert.equal(
|
|
28
|
-
assert.equal(
|
|
29
|
-
assert.equal(
|
|
30
|
-
assert.equal(
|
|
31
|
-
assert.equal(
|
|
32
|
-
assert.equal(
|
|
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 =>
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
208
|
-
const preparedResult =
|
|
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 =
|
|
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 =
|
|
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(
|
|
472
|
-
expect(
|
|
473
|
-
expect(
|
|
474
|
-
expect(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 {
|
|
12
|
-
import {I18n} from '../../renderer/i18n.js';
|
|
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
|
-
|
|
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
|
-
|
|
68
|
+
Globals.i18n = undefined;
|
|
65
69
|
});
|
|
66
70
|
|
|
67
71
|
function renderSnippet(details) {
|