Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report(flow): fix ui strings not being bundled #14427

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/build-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {locales} from '../shared/localization/locales.js';
import {UIStrings as FlowUIStrings} from '../flow-report/src/i18n/ui-strings.js';

/**
* Extract only the strings needed for the flow report into
* a script that sets a global variable `strings`, whose keys
* are locale codes (en-US, es, etc.) and values are localized UIStrings.
* Extract only the strings needed for the flow report. Code generated is
* an object whose keys are locale codes (en-US, es, etc.) and values are localized UIStrings.
* For flow-report/src/i18n/localized-strings.js
*/
function buildFlowStrings() {
const strings = /** @type {Record<LH.Locale, string>} */ ({});
Expand Down
2 changes: 1 addition & 1 deletion flow-report/src/i18n/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {formatMessage} from '../../../shared/localization/format';
import {I18n} from '../../../report/renderer/i18n';
import {UIStrings} from './ui-strings';
import {useFlowResult} from '../util';
import strings from './localized-strings';
import strings from './localized-strings.js';
import {Util} from '../../../report/renderer/util';

const I18nContext = createContext(new I18n('en-US', {...Util.UIStrings, ...UIStrings}));
Expand Down
16 changes: 16 additions & 0 deletions flow-report/test/flow-report-pptr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import puppeteer, {Browser, Page} from 'puppeteer';

import {ReportGenerator} from '../../report/generator/report-generator.js';
import {swapFlowLocale} from '../../shared/localization/swap-flow-locale.js';
import {flowResult} from './sample-flow';

describe('Lighthouse Flow Report', () => {
Expand Down Expand Up @@ -40,4 +41,19 @@ describe('Lighthouse Flow Report', () => {
expect(pageErrors).toHaveLength(0);
});
});

describe('Renders the flow report (i18n)', () => {
before(async () => {
const html = ReportGenerator.generateFlowReportHtml(swapFlowLocale(flowResult, 'es'));
await page.setContent(html);
});

it('should load with no errors', async () => {
expect(pageErrors).toHaveLength(0);
const el = await page.$('.SummarySectionHeader__content');
if (!el) throw new Error();
const text = await el.evaluate(el => el.textContent);
expect(text).toEqual('Todos los informes');
});
});
}).timeout(35_000);
5 changes: 4 additions & 1 deletion report/generator/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ class ReportGenerator {
*/
static generateFlowReportHtml(flow) {
const sanitizedJson = ReportGenerator.sanitizeJson(flow);
// terser does its own sanitization, but keep this basic replace for when
// we want to generate a report without minification.
const sanitizedJavascript = reportAssets.FLOW_REPORT_JAVASCRIPT.replace(/<\//g, '\\u003c/');
return ReportGenerator.replaceStrings(reportAssets.FLOW_REPORT_TEMPLATE, [
/* eslint-disable max-len */
{search: '%%LIGHTHOUSE_FLOW_JSON%%', replacement: sanitizedJson},
{search: '%%LIGHTHOUSE_FLOW_JAVASCRIPT%%', replacement: reportAssets.FLOW_REPORT_JAVASCRIPT},
{search: '%%LIGHTHOUSE_FLOW_JAVASCRIPT%%', replacement: sanitizedJavascript},
{search: '/*%%LIGHTHOUSE_FLOW_CSS%%*/', replacement: reportAssets.FLOW_REPORT_CSS},
/* eslint-enable max-len */
]);
Expand Down