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

feat: backcompat config in report #2167

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 17 additions & 5 deletions lighthouse-core/report/v2/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ class ReportGeneratorV2 {

/**
* Returns the report JSON object with computed scores.
* @param {{categories: !Object<{audits: !Array}>}} config
* @param {!Object<{score: ?number|boolean|undefined}>} resultsByAuditId
* @param {{categories: !Object<{audits: !Array}>, config: ?Object, audits: ?Object}} config
* @param {!Object<{score: ?number|boolean|undefined}>=} resultsByAuditId
* @return {{categories: !Array<{audits: !Array<{score: number, result: !Object}>}>}}
*/
generateReportJson(config, resultsByAuditId) {
generateReportJson(configOrLhr, resultsByAuditId) {
let config = configOrLhr;
if (configOrLhr.config && configOrLhr.audits) {
config = configOrLhr.config;
resultsByAuditId = configOrLhr.audits;
}

const categories = Object.keys(config.categories).map(categoryId => {
const category = config.categories[categoryId];
category.id = categoryId;
Expand Down Expand Up @@ -131,8 +137,14 @@ class ReportGeneratorV2 {
* @param {!Object} reportAsJson
* @return {string}
*/
generateReportHtml(reportAsJson) {
const sanitizedJson = JSON.stringify(reportAsJson).replace(/</g, '\\u003c');
generateReportHtml(reportJsonOrLhr) {
let reportJson = reportJsonOrLhr;
if (reportJsonOrLhr.config && reportJsonOrLhr.audits) {
const clonedLhr = Object.assign({}, reportJsonOrLhr, {config: undefined});
reportJson = Object.assign(clonedLhr, this.generateReportJson(reportJsonOrLhr));
}

const sanitizedJson = JSON.stringify(reportJson).replace(/</g, '\\u003c');
const sanitizedJavascript = REPORT_JAVASCRIPT.replace(/<\//g, '\\u003c/');

return ReportGeneratorV2.replaceStrings(REPORT_TEMPLATE, [
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class Runner {
score,
reportCategories,
reportGroups: config.groups,
config,
aggregations
};
});
Expand Down