Skip to content

Commit

Permalink
misc(proto): adjust configSetting.output in preprocessor (#6310)
Browse files Browse the repository at this point in the history
  • Loading branch information
exterkamp authored and paulirish committed Oct 18, 2018
1 parent c6ae9f5 commit 771fb5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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

0 comments on commit 771fb5a

Please sign in to comment.