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

misc(proto): adjust configSetting.output in preprocessor #6310

Merged
merged 4 commits into from
Oct 18, 2018
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
16 changes: 13 additions & 3 deletions lighthouse-core/lib/proto-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ function processForProto(result) {
/** @type {LH.Result} */
const reportJson = JSON.parse(result);

// Clean up the configSettings
if (reportJson.configSettings) {
// make sure the 'output' field is an array
if (reportJson.configSettings.output) {
if (!Array.isArray(reportJson.configSettings.output)) {
reportJson.configSettings.output = [reportJson.configSettings.output];
}
}
}

// Clean up actions that require 'audits' to exist
if ('audits' in reportJson) {
if (reportJson.audits) {
Object.keys(reportJson.audits).forEach(auditName => {
const audit = reportJson.audits[auditName];

// Rewrite the 'not-applicable' scoreDisplayMode to 'not_applicable'. #6201
if ('scoreDisplayMode' in audit) {
if (audit.scoreDisplayMode) {
if (audit.scoreDisplayMode === 'not-applicable') {
// @ts-ignore Breaking the LH.Result type
audit.scoreDisplayMode = 'not_applicable';
Expand All @@ -52,7 +62,7 @@ function processForProto(result) {
}

// Drop the i18n icuMessagePaths. Painful in proto, and low priority to expose currently.
if ('i18n' in reportJson && 'icuMessagePaths' in reportJson.i18n) {
if (reportJson.i18n && reportJson.i18n.icuMessagePaths) {
delete reportJson.i18n.icuMessagePaths;
}

Expand Down
18 changes: 18 additions & 0 deletions lighthouse-core/test/lib/proto-preprocessor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ const processForProto = require('../../lib/proto-preprocessor').processForProto;

/* eslint-env jest */
describe('processing for proto', () => {
it('cleans up configSettings', () => {
const input = {
'configSettings': {
'output': 'json',
},
};
const expectation = {
'configSettings': {
'output': [
'json',
],
},
};
const output = processForProto(JSON.stringify(input));

expect(JSON.parse(output)).toMatchObject(expectation);
});

it('cleans up audits', () => {
const input = {
'audits': {
Expand Down