lighthouse 8.5.1-dev.20211009 → 8.5.1
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/dist/report/flow.js +149 -0
- package/dist/report/standalone.js +228 -0
- package/flow-report/assets/styles.css +9 -272
- package/flow-report/jest.config.js +1 -1
- package/flow-report/src/app.tsx +9 -31
- package/flow-report/src/common.tsx +7 -86
- package/flow-report/src/icons.tsx +3 -20
- package/flow-report/src/sidebar/sidebar.tsx +16 -11
- package/flow-report/src/summary/category.tsx +24 -42
- package/flow-report/src/summary/summary.tsx +29 -32
- package/flow-report/src/topbar.tsx +4 -54
- package/flow-report/src/util.ts +1 -26
- package/flow-report/src/wrappers/report-renderer.tsx +1 -1
- package/flow-report/src/wrappers/report.tsx +20 -7
- package/flow-report/test/app-test.tsx +13 -17
- package/flow-report/test/setup/env-setup.ts +0 -1
- package/flow-report/test/sidebar/flow-test.tsx +12 -6
- package/flow-report/test/sidebar/sidebar-test.tsx +13 -7
- package/flow-report/test/summary/category-test.tsx +34 -79
- package/flow-report/test/summary/summary-test.tsx +17 -11
- package/flow-report/test/util-test.tsx +12 -1
- package/flow-report/tsconfig.json +0 -1
- package/flow-report/types/flow-report.d.ts +1 -2
- package/jest.config.js +15 -1
- package/lighthouse-cli/cli-flags.js +1 -3
- package/lighthouse-cli/run.js +2 -2
- package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +0 -0
- package/lighthouse-cli/test/smokehouse/report-assert.js +4 -20
- package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +1 -2
- package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -1
- package/lighthouse-core/computed/js-bundles.js +2 -1
- package/lighthouse-core/computed/unused-javascript-summary.js +3 -3
- package/lighthouse-core/config/config.js +2 -2
- package/lighthouse-core/config/default-config.js +0 -5
- package/lighthouse-core/fraggle-rock/api.js +0 -10
- package/lighthouse-core/fraggle-rock/config/filters.js +3 -22
- package/lighthouse-core/fraggle-rock/gather/driver.js +0 -4
- package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +2 -2
- package/lighthouse-core/fraggle-rock/user-flow.js +6 -35
- package/lighthouse-core/gather/driver/navigation.js +0 -5
- package/lighthouse-core/gather/driver/prepare.js +0 -14
- package/lighthouse-core/gather/driver/storage.js +0 -5
- package/lighthouse-core/gather/gather-runner.js +2 -2
- package/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +1 -5
- package/lighthouse-core/gather/gatherers/full-page-screenshot.js +24 -30
- package/{shared/localization/i18n-module.js → lighthouse-core/lib/cdt/Common.js} +8 -3
- package/lighthouse-core/lib/cdt/SDK.js +123 -3
- package/lighthouse-core/lib/cdt/generated/SourceMap.js +312 -148
- package/lighthouse-core/lib/csp-evaluator.js +1 -2
- package/lighthouse-core/lib/i18n/README.md +6 -6
- package/lighthouse-core/lib/i18n/i18n.js +342 -9
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ar-XB.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ar.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/bg.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ca.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/cs.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/da.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/de.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/el.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-GB.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-US.json +0 -111
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-XA.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-XL.json +0 -111
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/es-419.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/es.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/fi.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/fil.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/fr.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/he.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/hi.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/hr.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/hu.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/id.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/it.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ja.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ko.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/lt.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/lv.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/nl.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/no.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/pl.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/pt-PT.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/pt.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ro.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ru.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/sk.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/sl.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/sr-Latn.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/sr.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/sv.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/ta.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/te.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/th.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/tr.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/uk.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/vi.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/zh-HK.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/zh-TW.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales/zh.json +0 -0
- package/{shared/localization → lighthouse-core/lib/i18n}/locales.js +1 -2
- package/{shared/localization → lighthouse-core/lib/i18n}/swap-locale.js +7 -9
- package/lighthouse-core/lib/page-functions.js +4 -4
- package/lighthouse-core/lib/stack-packs.js +13 -1
- package/{shared → lighthouse-core/lib}/type-verifiers.js +0 -0
- package/lighthouse-core/runner.js +6 -6
- package/lighthouse-core/scripts/manual-chrome-launcher.js +1 -4
- package/lighthouse-core/util-commonjs.js +4 -20
- package/package.json +15 -18
- package/readme.md +1 -1
- package/report/assets/standalone-template.html +1 -0
- package/report/assets/styles.css +1 -8
- package/report/assets/templates.html +2 -40
- package/report/clients/psi.js +0 -1
- package/report/generator/file-namer.js +8 -17
- package/report/generator/report-generator.js +1 -0
- package/report/renderer/category-renderer.js +4 -3
- package/report/renderer/components.js +69 -106
- package/report/renderer/dom.js +0 -19
- package/report/renderer/performance-category-renderer.js +20 -22
- package/report/renderer/report-renderer.js +0 -7
- package/report/renderer/report-ui-features.js +19 -7
- package/report/renderer/util.js +4 -20
- package/report/test/clients/psi-test.js +3 -2
- package/report/test/generator/file-namer-test.js +2 -2
- package/report/test/renderer/category-renderer-test.js +1 -1
- package/report/test/renderer/performance-category-renderer-test.js +0 -12
- package/report/test/renderer/report-renderer-test.js +55 -0
- package/report/test/renderer/util-test.js +8 -68
- package/report/test-assets/faux-psi-template.html +1 -0
- package/report/tsconfig.json +1 -2
- package/report/types/html-renderer.d.ts +1 -2
- package/root.js +0 -18
- package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +3 -5
- package/third-party/chromium-synchronization/installability-errors-test.js +1 -2
- package/tsconfig-all.json +0 -1
- package/tsconfig-base.json +1 -1
- package/tsconfig.json +3 -2
- package/types/config.d.ts +0 -1
- package/types/lhr/flow.d.ts +0 -7
- package/types/lhr/i18n.d.ts +3 -0
- package/changelog.md +0 -5395
- package/flow-report/.eslintrc.cjs +0 -49
- package/flow-report/package.json +0 -4
- package/flow-report/src/header.tsx +0 -88
- package/flow-report/src/help-dialog.tsx +0 -120
- package/flow-report/src/i18n/i18n.tsx +0 -44
- package/flow-report/src/i18n/localized-strings.js +0 -11
- package/flow-report/src/i18n/ui-strings.js +0 -86
- package/flow-report/test/common-test.tsx +0 -89
- package/flow-report/test/header-test.tsx +0 -55
- package/flow-report/test/sample-flow.ts +0 -17
- package/flow-report/test/topbar-test.tsx +0 -68
- package/lighthouse-core/lib/cdt/Platform.js +0 -55
- package/lighthouse-core/scripts/package.json +0 -4
- package/report/renderer/swap-locale-feature.js +0 -82
- package/report/test/renderer/report-renderer-axe-test.js +0 -86
- package/shared/localization/format.js +0 -422
- package/shared/localization/swap-flow-locale.js +0 -20
- package/shared/test/localization/format-test.js +0 -377
- package/shared/test/localization/locales-test.js +0 -47
- package/shared/test/localization/swap-locale-test.js +0 -140
- package/shared/tsconfig.json +0 -22
- package/shared/types/shared.d.ts +0 -24
- package/types/es-main.d.ts +0 -18
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
|
4
|
-
* 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
|
|
5
|
-
* 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.
|
|
6
|
-
*/
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
// Functions manually copied from:
|
|
10
|
-
// https://github.com/ChromeDevTools/devtools-frontend/blob/master/front_end/core/platform/array-utilities.ts#L125
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {any[]} array
|
|
14
|
-
* @param {any} needle
|
|
15
|
-
* @param {any} comparator
|
|
16
|
-
*/
|
|
17
|
-
function lowerBound(array, needle, comparator, left, right) {
|
|
18
|
-
let l = left || 0;
|
|
19
|
-
let r = right !== undefined ? right : array.length;
|
|
20
|
-
while (l < r) {
|
|
21
|
-
const m = (l + r) >> 1;
|
|
22
|
-
if (comparator(needle, array[m]) > 0) {
|
|
23
|
-
l = m + 1;
|
|
24
|
-
} else {
|
|
25
|
-
r = m;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return r;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @param {any[]} array
|
|
33
|
-
* @param {any} needle
|
|
34
|
-
* @param {any} comparator
|
|
35
|
-
*/
|
|
36
|
-
function upperBound(array, needle, comparator, left, right) {
|
|
37
|
-
let l = left || 0;
|
|
38
|
-
let r = right !== undefined ? right : array.length;
|
|
39
|
-
while (l < r) {
|
|
40
|
-
const m = (l + r) >> 1;
|
|
41
|
-
if (comparator(needle, array[m]) >= 0) {
|
|
42
|
-
l = m + 1;
|
|
43
|
-
} else {
|
|
44
|
-
r = m;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return r;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = {
|
|
51
|
-
ArrayUtilities: {
|
|
52
|
-
lowerBound,
|
|
53
|
-
upperBound,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @fileoverview Creates a <select> element, filled with all supported locales
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** @typedef {import('./dom.js').DOM} DOM */
|
|
13
|
-
/** @typedef {import('./report-ui-features').ReportUIFeatures} ReportUIFeatures */
|
|
14
|
-
|
|
15
|
-
export class SwapLocaleFeature {
|
|
16
|
-
/**
|
|
17
|
-
* @param {ReportUIFeatures} reportUIFeatures
|
|
18
|
-
* @param {DOM} dom
|
|
19
|
-
* @param {{onLocaleSelected: (localeModuleName: LH.Locale) => Promise<void>}} callbacks
|
|
20
|
-
* Specifiy the URL where the i18n module script can be found, and the URLS for the locale JSON files.
|
|
21
|
-
*/
|
|
22
|
-
constructor(reportUIFeatures, dom, callbacks) {
|
|
23
|
-
this._reportUIFeatures = reportUIFeatures;
|
|
24
|
-
this._dom = dom;
|
|
25
|
-
this._localeSelectedCallback = callbacks.onLocaleSelected;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {Array<LH.Locale>} locales
|
|
30
|
-
*/
|
|
31
|
-
enable(locales) {
|
|
32
|
-
if (!this._reportUIFeatures.json.i18n.icuMessagePaths) {
|
|
33
|
-
throw new Error('missing icuMessagePaths');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this._dom.find('.lh-tools-locale', this._dom.document()).classList.remove('lh-hidden');
|
|
37
|
-
|
|
38
|
-
const currentLocale = this._reportUIFeatures.json.configSettings.locale;
|
|
39
|
-
|
|
40
|
-
const containerEl = this._dom.find('.lh-tools-locale__selector-wrapper', this._dom.document());
|
|
41
|
-
containerEl.removeAttribute('aria-hidden');
|
|
42
|
-
const selectEl = this._dom.createChildOf(containerEl, 'select', 'lh-locale-selector');
|
|
43
|
-
selectEl.name = 'lh-locale-list';
|
|
44
|
-
selectEl.setAttribute('role', 'menuitem');
|
|
45
|
-
|
|
46
|
-
const toggleEl = this._dom.find('.lh-tool-locale__button', this._dom.document());
|
|
47
|
-
toggleEl.addEventListener('click', () => {
|
|
48
|
-
toggleEl.classList.toggle('lh-active');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
for (const locale of locales) {
|
|
52
|
-
const optionEl = this._dom.createChildOf(selectEl, 'option', '');
|
|
53
|
-
optionEl.value = locale;
|
|
54
|
-
if (locale === currentLocale) optionEl.selected = true;
|
|
55
|
-
|
|
56
|
-
// @ts-expect-error: waiting for typescript 4.5. Might need to add "ES2020.Intl"
|
|
57
|
-
// to tsconfig libs.
|
|
58
|
-
// https://github.com/microsoft/TypeScript/pull/44022#issuecomment-915087098
|
|
59
|
-
if (window.Intl && Intl.DisplayNames) {
|
|
60
|
-
// @ts-expect-error
|
|
61
|
-
const currentLocaleDisplay = new Intl.DisplayNames([currentLocale], {type: 'language'});
|
|
62
|
-
// @ts-expect-error
|
|
63
|
-
const optionLocaleDisplay = new Intl.DisplayNames([locale], {type: 'language'});
|
|
64
|
-
|
|
65
|
-
const optionLocaleName = optionLocaleDisplay.of(locale);
|
|
66
|
-
const currentLocaleName = currentLocaleDisplay.of(locale);
|
|
67
|
-
if (optionLocaleName !== currentLocaleName) {
|
|
68
|
-
optionEl.textContent = `${optionLocaleName} – ${currentLocaleName}`;
|
|
69
|
-
} else {
|
|
70
|
-
optionEl.textContent = currentLocaleName;
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
optionEl.textContent = locale;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
selectEl.addEventListener('change', () => {
|
|
78
|
-
const locale = /** @type {LH.Locale} */ (selectEl.value);
|
|
79
|
-
this._localeSelectedCallback(locale);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/* eslint-env jest */
|
|
9
|
-
|
|
10
|
-
import jsdom from 'jsdom';
|
|
11
|
-
|
|
12
|
-
import {Util} from '../../renderer/util.js';
|
|
13
|
-
import {DOM} from '../../renderer/dom.js';
|
|
14
|
-
import {DetailsRenderer} from '../../renderer/details-renderer.js';
|
|
15
|
-
import {CategoryRenderer} from '../../renderer/category-renderer.js';
|
|
16
|
-
import {ReportRenderer} from '../../renderer/report-renderer.js';
|
|
17
|
-
import sampleResultsOrig from '../../../lighthouse-core/test/results/sample_v2.json';
|
|
18
|
-
|
|
19
|
-
describe('ReportRendererAxe', () => {
|
|
20
|
-
describe('with aXe', () => {
|
|
21
|
-
let axe;
|
|
22
|
-
let renderer;
|
|
23
|
-
let sampleResults;
|
|
24
|
-
|
|
25
|
-
beforeAll(async () => {
|
|
26
|
-
const {window} = new jsdom.JSDOM();
|
|
27
|
-
const dom = new DOM(window.document);
|
|
28
|
-
const detailsRenderer = new DetailsRenderer(dom);
|
|
29
|
-
const categoryRenderer = new CategoryRenderer(dom, detailsRenderer);
|
|
30
|
-
renderer = new ReportRenderer(dom, categoryRenderer);
|
|
31
|
-
sampleResults = Util.prepareReportResult(sampleResultsOrig);
|
|
32
|
-
|
|
33
|
-
// Needed by axe-core
|
|
34
|
-
// https://github.com/dequelabs/axe-core/blob/581c441c/doc/examples/jsdom/test/a11y.js#L24
|
|
35
|
-
global.window = global.self = window;
|
|
36
|
-
global.Node = global.self.Node;
|
|
37
|
-
global.Element = global.self.Element;
|
|
38
|
-
|
|
39
|
-
// axe-core must be imported after the global polyfills
|
|
40
|
-
axe = (await import('axe-core')).default;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterAll(() => {
|
|
44
|
-
global.window = undefined;
|
|
45
|
-
global.Node = undefined;
|
|
46
|
-
global.Element = undefined;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('renders without axe violations', () => {
|
|
50
|
-
const container = renderer._dom._document.createElement('main');
|
|
51
|
-
const output = renderer.renderReport(sampleResults, container);
|
|
52
|
-
|
|
53
|
-
renderer._dom._document.body.appendChild(container);
|
|
54
|
-
|
|
55
|
-
const config = {
|
|
56
|
-
rules: {
|
|
57
|
-
// Reports may have duplicate ids
|
|
58
|
-
// https://github.com/GoogleChrome/lighthouse/issues/9432
|
|
59
|
-
'duplicate-id': {enabled: false},
|
|
60
|
-
'duplicate-id-aria': {enabled: false},
|
|
61
|
-
'landmark-no-duplicate-contentinfo': {enabled: false},
|
|
62
|
-
// The following rules are disable for axe-core + jsdom compatibility
|
|
63
|
-
// https://github.com/dequelabs/axe-core/tree/b573b1c1/doc/examples/jest_react#to-run-the-example
|
|
64
|
-
'color-contrast': {enabled: false},
|
|
65
|
-
'link-in-text-block': {enabled: false},
|
|
66
|
-
// Report has empty links prior to i18n-ing.
|
|
67
|
-
'link-name': {enabled: false},
|
|
68
|
-
// May not be a real issue. https://github.com/dequelabs/axe-core/issues/2958
|
|
69
|
-
'nested-interactive': {enabled: false},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
return new Promise(resolve => {
|
|
74
|
-
axe.run(output, config, (error, {violations}) => {
|
|
75
|
-
expect(error).toBeNull();
|
|
76
|
-
expect(violations).toEqual([]);
|
|
77
|
-
resolve();
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
// This test takes 40s on fast hardware, and 50-60s on GHA.
|
|
81
|
-
// https://github.com/dequelabs/axe-core/tree/b573b1c1/doc/examples/jest_react#timeout-issues
|
|
82
|
-
},
|
|
83
|
-
/* timeout= */ 100 * 1000
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,422 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
|
|
10
|
-
const MessageFormat = require('intl-messageformat').default;
|
|
11
|
-
const {isObjectOfUnknownValues, isObjectOrArrayOfUnknownValues} = require('../type-verifiers.js');
|
|
12
|
-
|
|
13
|
-
/** Contains available locales with messages. May be an empty object if bundled. */
|
|
14
|
-
const LOCALE_MESSAGES = require('./locales.js');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The locale tags for the localized messages available to Lighthouse on disk.
|
|
18
|
-
* When bundled, these will be inlined by brfs.
|
|
19
|
-
* These locales are considered the "canonical" locales. We support other locales which
|
|
20
|
-
* are simply aliases to one of these. ex: es-AR (alias) -> es-419 (canonical)
|
|
21
|
-
*/
|
|
22
|
-
let CANONICAL_LOCALES = ['__availableLocales__'];
|
|
23
|
-
// TODO: need brfs in gh-pages-app. For now, above is replaced, see build-i18n.module.js
|
|
24
|
-
if (fs.readdirSync) {
|
|
25
|
-
CANONICAL_LOCALES = fs.readdirSync(__dirname + '/locales/')
|
|
26
|
-
.filter(basename => basename.endsWith('.json') && !basename.endsWith('.ctc.json'))
|
|
27
|
-
.map(locale => locale.replace('.json', ''))
|
|
28
|
-
.sort();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** @typedef {import('intl-messageformat-parser').Element} MessageElement */
|
|
32
|
-
/** @typedef {import('intl-messageformat-parser').ArgumentElement} ArgumentElement */
|
|
33
|
-
|
|
34
|
-
const MESSAGE_I18N_ID_REGEX = / | [^\s]+$/;
|
|
35
|
-
|
|
36
|
-
const formats = {
|
|
37
|
-
number: {
|
|
38
|
-
bytes: {
|
|
39
|
-
maximumFractionDigits: 0,
|
|
40
|
-
},
|
|
41
|
-
milliseconds: {
|
|
42
|
-
maximumFractionDigits: 0,
|
|
43
|
-
},
|
|
44
|
-
seconds: {
|
|
45
|
-
// Force the seconds to the tenths place for limited output and ease of scanning
|
|
46
|
-
minimumFractionDigits: 1,
|
|
47
|
-
maximumFractionDigits: 1,
|
|
48
|
-
},
|
|
49
|
-
extendedPercent: {
|
|
50
|
-
// Force allow up to two digits after decimal place in percentages. (Intl.NumberFormat options)
|
|
51
|
-
maximumFractionDigits: 2,
|
|
52
|
-
style: 'percent',
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Function to retrieve all 'argumentElement's from an ICU message. An argumentElement
|
|
59
|
-
* is an ICU element with an argument in it, like '{varName}' or '{varName, number, bytes}'. This
|
|
60
|
-
* differs from 'messageElement's which are just arbitrary text in a message.
|
|
61
|
-
*
|
|
62
|
-
* Notes:
|
|
63
|
-
* This function will recursively inspect plural elements for nested argumentElements.
|
|
64
|
-
*
|
|
65
|
-
* We need to find all the elements from the plural format sections, but
|
|
66
|
-
* they need to be deduplicated. I.e. "=1{hello {icu}} =other{hello {icu}}"
|
|
67
|
-
* the variable "icu" would appear twice if it wasn't de duplicated. And they cannot
|
|
68
|
-
* be stored in a set because they are not equal since their locations are different,
|
|
69
|
-
* thus they are stored via a Map keyed on the "id" which is the ICU varName.
|
|
70
|
-
*
|
|
71
|
-
* @param {Array<MessageElement>} icuElements
|
|
72
|
-
* @param {Map<string, ArgumentElement>} [seenElementsById]
|
|
73
|
-
* @return {Map<string, ArgumentElement>}
|
|
74
|
-
*/
|
|
75
|
-
function collectAllCustomElementsFromICU(icuElements, seenElementsById = new Map()) {
|
|
76
|
-
for (const el of icuElements) {
|
|
77
|
-
// We are only interested in elements that need ICU formatting (argumentElements)
|
|
78
|
-
if (el.type !== 'argumentElement') continue;
|
|
79
|
-
|
|
80
|
-
seenElementsById.set(el.id, el);
|
|
81
|
-
|
|
82
|
-
// Plurals need to be inspected recursively
|
|
83
|
-
if (!el.format || el.format.type !== 'pluralFormat') continue;
|
|
84
|
-
// Look at all options of the plural (=1{} =other{}...)
|
|
85
|
-
for (const option of el.format.options) {
|
|
86
|
-
// Run collections on each option's elements
|
|
87
|
-
collectAllCustomElementsFromICU(option.value.elements, seenElementsById);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return seenElementsById;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Returns a copy of the `values` object, with the values formatted based on how
|
|
96
|
-
* they will be used in their icuMessage, e.g. KB or milliseconds. The original
|
|
97
|
-
* object is unchanged.
|
|
98
|
-
* @param {MessageFormat} messageFormatter
|
|
99
|
-
* @param {Readonly<Record<string, string | number>>} values
|
|
100
|
-
* @param {string} lhlMessage Used for clear error logging.
|
|
101
|
-
* @return {Record<string, string | number>}
|
|
102
|
-
*/
|
|
103
|
-
function _preformatValues(messageFormatter, values, lhlMessage) {
|
|
104
|
-
const elementMap = collectAllCustomElementsFromICU(messageFormatter.getAst().elements);
|
|
105
|
-
const argumentElements = [...elementMap.values()];
|
|
106
|
-
|
|
107
|
-
/** @type {Record<string, string | number>} */
|
|
108
|
-
const formattedValues = {};
|
|
109
|
-
|
|
110
|
-
for (const {id, format} of argumentElements) {
|
|
111
|
-
// Throw an error if a message's value isn't provided
|
|
112
|
-
if (id && (id in values) === false) {
|
|
113
|
-
throw new Error(`ICU Message "${lhlMessage}" contains a value reference ("${id}") ` +
|
|
114
|
-
`that wasn't provided`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const value = values[id];
|
|
118
|
-
|
|
119
|
-
// Direct `{id}` replacement and non-numeric values need no formatting.
|
|
120
|
-
if (!format || format.type !== 'numberFormat') {
|
|
121
|
-
formattedValues[id] = value;
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (typeof value !== 'number') {
|
|
126
|
-
throw new Error(`ICU Message "${lhlMessage}" contains a numeric reference ("${id}") ` +
|
|
127
|
-
'but provided value was not a number');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Format values for known styles.
|
|
131
|
-
if (format.style === 'milliseconds') {
|
|
132
|
-
// Round all milliseconds to the nearest 10.
|
|
133
|
-
formattedValues[id] = Math.round(value / 10) * 10;
|
|
134
|
-
} else if (format.style === 'seconds' && id === 'timeInMs') {
|
|
135
|
-
// Convert all seconds to the correct unit (currently only for `timeInMs`).
|
|
136
|
-
formattedValues[id] = Math.round(value / 100) / 10;
|
|
137
|
-
} else if (format.style === 'bytes') {
|
|
138
|
-
// Replace all the bytes with KB.
|
|
139
|
-
formattedValues[id] = value / 1024;
|
|
140
|
-
} else {
|
|
141
|
-
// For all other number styles, the value isn't changed.
|
|
142
|
-
formattedValues[id] = value;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Throw an error if a value is provided but has no placeholder in the message.
|
|
147
|
-
for (const valueId of Object.keys(values)) {
|
|
148
|
-
if (valueId in formattedValues) continue;
|
|
149
|
-
|
|
150
|
-
// errorCode is a special case always allowed to help LHError ease-of-use.
|
|
151
|
-
if (valueId === 'errorCode') {
|
|
152
|
-
formattedValues.errorCode = values.errorCode;
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
throw new Error(`Provided value "${valueId}" does not match any placeholder in ` +
|
|
157
|
-
`ICU message "${lhlMessage}"`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return formattedValues;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Format string `message` by localizing `values` and inserting them. `message`
|
|
165
|
-
* is assumed to already be in the given locale.
|
|
166
|
-
* If you need to localize a messagem `getFormatted` is probably what you want.
|
|
167
|
-
* @param {string} message
|
|
168
|
-
* @param {Record<string, string | number>} values
|
|
169
|
-
* @param {LH.Locale} locale
|
|
170
|
-
* @return {string}
|
|
171
|
-
*/
|
|
172
|
-
function _formatMessage(message, values = {}, locale) {
|
|
173
|
-
// When using accented english, force the use of a different locale for number formatting.
|
|
174
|
-
const localeForMessageFormat = (locale === 'en-XA' || locale === 'en-XL') ? 'de-DE' : locale;
|
|
175
|
-
|
|
176
|
-
const formatter = new MessageFormat(message, localeForMessageFormat, formats);
|
|
177
|
-
|
|
178
|
-
// Preformat values for the message format like KB and milliseconds.
|
|
179
|
-
const valuesForMessageFormat = _preformatValues(formatter, values, message);
|
|
180
|
-
|
|
181
|
-
return formatter.format(valuesForMessageFormat);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Retrieves the localized version of `icuMessage` and formats with any given
|
|
186
|
-
* value replacements.
|
|
187
|
-
* @param {LH.IcuMessage} icuMessage
|
|
188
|
-
* @param {LH.Locale} locale
|
|
189
|
-
* @return {string}
|
|
190
|
-
*/
|
|
191
|
-
function _localizeIcuMessage(icuMessage, locale) {
|
|
192
|
-
const localeMessages = LOCALE_MESSAGES[locale];
|
|
193
|
-
if (!localeMessages) throw new Error(`Unsupported locale '${locale}'`);
|
|
194
|
-
const localeMessage = localeMessages[icuMessage.i18nId];
|
|
195
|
-
|
|
196
|
-
// Fall back to the default (usually the original english message) if we couldn't find a
|
|
197
|
-
// message in the specified locale. This could be because of string drift between
|
|
198
|
-
// Lighthouse versions or because new strings haven't been updated yet. Better to have
|
|
199
|
-
// an english message than no message at all; in some cases it won't even matter.
|
|
200
|
-
if (!localeMessage) {
|
|
201
|
-
return icuMessage.formattedDefault;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return _formatMessage(localeMessage.message, icuMessage.values, locale);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @param {LH.Locale} locale
|
|
209
|
-
* @return {Record<string, string>}
|
|
210
|
-
*/
|
|
211
|
-
function getRendererFormattedStrings(locale) {
|
|
212
|
-
const localeMessages = LOCALE_MESSAGES[locale];
|
|
213
|
-
if (!localeMessages) throw new Error(`Unsupported locale '${locale}'`);
|
|
214
|
-
|
|
215
|
-
const icuMessageIds = Object.keys(localeMessages).filter(f => f.startsWith('report/'));
|
|
216
|
-
/** @type {Record<string, string>} */
|
|
217
|
-
const strings = {};
|
|
218
|
-
for (const icuMessageId of icuMessageIds) {
|
|
219
|
-
const {filename, key} = getIcuMessageIdParts(icuMessageId);
|
|
220
|
-
if (!filename.endsWith('util.js')) throw new Error(`Unexpected message: ${icuMessageId}`);
|
|
221
|
-
|
|
222
|
-
strings[key] = localeMessages[icuMessageId].message;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return strings;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Returns whether `icuMessageOrNot`` is an `LH.IcuMessage` instance.
|
|
230
|
-
* @param {unknown} icuMessageOrNot
|
|
231
|
-
* @return {icuMessageOrNot is LH.IcuMessage}
|
|
232
|
-
*/
|
|
233
|
-
function isIcuMessage(icuMessageOrNot) {
|
|
234
|
-
if (!isObjectOfUnknownValues(icuMessageOrNot)) {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const {i18nId, values, formattedDefault} = icuMessageOrNot;
|
|
239
|
-
if (typeof i18nId !== 'string') {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// formattedDefault is required.
|
|
244
|
-
if (typeof formattedDefault !== 'string') {
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Values is optional.
|
|
249
|
-
if (values !== undefined) {
|
|
250
|
-
if (!isObjectOfUnknownValues(values)) {
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
for (const value of Object.values(values)) {
|
|
254
|
-
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Finally return true if i18nId seems correct.
|
|
261
|
-
return MESSAGE_I18N_ID_REGEX.test(i18nId);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Get the localized and formatted form of `icuMessageOrRawString` if it's an
|
|
266
|
-
* LH.IcuMessage, or get it back directly if it's already a string.
|
|
267
|
-
* Warning: this function throws if `icuMessageOrRawString` is not the expected
|
|
268
|
-
* type (use function from `createIcuMessageFn` to create a valid LH.IcuMessage)
|
|
269
|
-
* or `locale` isn't supported (use `lookupLocale` to find a valid locale).
|
|
270
|
-
* @param {LH.IcuMessage | string} icuMessageOrRawString
|
|
271
|
-
* @param {LH.Locale} locale
|
|
272
|
-
* @return {string}
|
|
273
|
-
*/
|
|
274
|
-
function getFormatted(icuMessageOrRawString, locale) {
|
|
275
|
-
if (isIcuMessage(icuMessageOrRawString)) {
|
|
276
|
-
return _localizeIcuMessage(icuMessageOrRawString, locale);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (typeof icuMessageOrRawString === 'string') {
|
|
280
|
-
return icuMessageOrRawString;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Should be impossible from types, but do a strict check in case malformed JSON makes it this far.
|
|
284
|
-
throw new Error('Attempted to format invalid icuMessage type');
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** @param {string[]} pathInLHR */
|
|
288
|
-
function _formatPathAsString(pathInLHR) {
|
|
289
|
-
let pathAsString = '';
|
|
290
|
-
for (const property of pathInLHR) {
|
|
291
|
-
if (/^[a-z]+$/i.test(property)) {
|
|
292
|
-
if (pathAsString.length) pathAsString += '.';
|
|
293
|
-
pathAsString += property;
|
|
294
|
-
} else {
|
|
295
|
-
if (/]|"|'|\s/.test(property)) throw new Error(`Cannot handle "${property}" in i18n`);
|
|
296
|
-
pathAsString += `[${property}]`;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return pathAsString;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Recursively walk the input object, looking for property values that are
|
|
305
|
-
* `LH.IcuMessage`s and replace them with their localized values. Primarily
|
|
306
|
-
* used with the full LHR or a Config as input.
|
|
307
|
-
* Returns a map of locations that were replaced to the `IcuMessage` that was at
|
|
308
|
-
* that location.
|
|
309
|
-
* @param {unknown} inputObject
|
|
310
|
-
* @param {LH.Locale} locale
|
|
311
|
-
* @return {LH.Result.IcuMessagePaths}
|
|
312
|
-
*/
|
|
313
|
-
function replaceIcuMessages(inputObject, locale) {
|
|
314
|
-
/**
|
|
315
|
-
* @param {unknown} subObject
|
|
316
|
-
* @param {LH.Result.IcuMessagePaths} icuMessagePaths
|
|
317
|
-
* @param {string[]} pathInLHR
|
|
318
|
-
*/
|
|
319
|
-
function replaceInObject(subObject, icuMessagePaths, pathInLHR = []) {
|
|
320
|
-
if (!isObjectOrArrayOfUnknownValues(subObject)) return;
|
|
321
|
-
|
|
322
|
-
for (const [property, possibleIcuMessage] of Object.entries(subObject)) {
|
|
323
|
-
const currentPathInLHR = pathInLHR.concat([property]);
|
|
324
|
-
|
|
325
|
-
// Replace any IcuMessages with a localized string.
|
|
326
|
-
if (isIcuMessage(possibleIcuMessage)) {
|
|
327
|
-
const formattedString = getFormatted(possibleIcuMessage, locale);
|
|
328
|
-
const messageInstancesInLHR = icuMessagePaths[possibleIcuMessage.i18nId] || [];
|
|
329
|
-
const currentPathAsString = _formatPathAsString(currentPathInLHR);
|
|
330
|
-
|
|
331
|
-
messageInstancesInLHR.push(
|
|
332
|
-
possibleIcuMessage.values ?
|
|
333
|
-
{values: possibleIcuMessage.values, path: currentPathAsString} :
|
|
334
|
-
currentPathAsString
|
|
335
|
-
);
|
|
336
|
-
|
|
337
|
-
// @ts-ignore - tsc doesn't like that `property` can be either string key or array index.
|
|
338
|
-
subObject[property] = formattedString;
|
|
339
|
-
icuMessagePaths[possibleIcuMessage.i18nId] = messageInstancesInLHR;
|
|
340
|
-
} else {
|
|
341
|
-
replaceInObject(possibleIcuMessage, icuMessagePaths, currentPathInLHR);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** @type {LH.Result.IcuMessagePaths} */
|
|
347
|
-
const icuMessagePaths = {};
|
|
348
|
-
replaceInObject(inputObject, icuMessagePaths);
|
|
349
|
-
return icuMessagePaths;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Returns whether the `requestedLocale` can be used.
|
|
354
|
-
* @param {LH.Locale} requestedLocale
|
|
355
|
-
* @return {boolean}
|
|
356
|
-
*/
|
|
357
|
-
function hasLocale(requestedLocale) {
|
|
358
|
-
const hasIntlSupport = Intl.NumberFormat.supportedLocalesOf([requestedLocale]).length > 0;
|
|
359
|
-
const hasMessages = Boolean(LOCALE_MESSAGES[requestedLocale]);
|
|
360
|
-
|
|
361
|
-
return hasIntlSupport && hasMessages;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Returns a list of canonical locales (each of which may have aliases, but those would
|
|
366
|
-
* only show in getAvailableLocales)
|
|
367
|
-
* TODO: create a CanonicalLocale type
|
|
368
|
-
* @return {Array<string>}
|
|
369
|
-
*/
|
|
370
|
-
function getCanonicalLocales() {
|
|
371
|
-
return CANONICAL_LOCALES;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Returns a list of available locales.
|
|
376
|
-
* - if full build, this includes all canonical locales, aliases, and any locale added
|
|
377
|
-
* via `registerLocaleData`.
|
|
378
|
-
* - if bundled and locale messages have been stripped (locales.js shimmed), this includes no
|
|
379
|
-
* locales (perhaps available in a separate bundle), and perhaps any locales
|
|
380
|
-
* from `registerLocaleData`.
|
|
381
|
-
* @return {Array<LH.Locale>}
|
|
382
|
-
*/
|
|
383
|
-
function getAvailableLocales() {
|
|
384
|
-
return /** @type {Array<LH.Locale>} */ (Object.keys(LOCALE_MESSAGES).sort());
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Populate the i18n string lookup dict with locale data
|
|
389
|
-
* Used when the host environment selects the locale and serves lighthouse the intended locale file
|
|
390
|
-
* @see https://docs.google.com/document/d/1jnt3BqKB-4q3AE94UWFA0Gqspx8Sd_jivlB7gQMlmfk/edit
|
|
391
|
-
* @param {LH.Locale} locale
|
|
392
|
-
* @param {import('./locales').LhlMessages} lhlMessages
|
|
393
|
-
*/
|
|
394
|
-
function registerLocaleData(locale, lhlMessages) {
|
|
395
|
-
LOCALE_MESSAGES[locale] = lhlMessages;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* @param {string} i18nMessageId
|
|
400
|
-
*/
|
|
401
|
-
function getIcuMessageIdParts(i18nMessageId) {
|
|
402
|
-
if (!MESSAGE_I18N_ID_REGEX.test(i18nMessageId)) {
|
|
403
|
-
throw Error(`"${i18nMessageId}" does not appear to be a valid ICU message id`);
|
|
404
|
-
}
|
|
405
|
-
const [filename, key] = i18nMessageId.split(' | ');
|
|
406
|
-
return {filename, key};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
module.exports = {
|
|
410
|
-
_formatPathAsString,
|
|
411
|
-
collectAllCustomElementsFromICU,
|
|
412
|
-
isIcuMessage,
|
|
413
|
-
getFormatted,
|
|
414
|
-
getRendererFormattedStrings,
|
|
415
|
-
replaceIcuMessages,
|
|
416
|
-
hasLocale,
|
|
417
|
-
registerLocaleData,
|
|
418
|
-
_formatMessage,
|
|
419
|
-
getIcuMessageIdParts,
|
|
420
|
-
getAvailableLocales,
|
|
421
|
-
getCanonicalLocales,
|
|
422
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
const swapLocale = require('./swap-locale.js');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {LH.FlowResult} flowResult
|
|
12
|
-
* @param {LH.Locale} locale
|
|
13
|
-
*/
|
|
14
|
-
module.exports = function swapFlowLocale(flowResult, locale) {
|
|
15
|
-
const localizedFlowResult = JSON.parse(JSON.stringify(flowResult));
|
|
16
|
-
localizedFlowResult.steps = flowResult.steps.map(step => {
|
|
17
|
-
return {...step, lhr: swapLocale(step.lhr, locale).lhr};
|
|
18
|
-
});
|
|
19
|
-
return localizedFlowResult;
|
|
20
|
-
};
|