diff --git a/lighthouse-core/lib/proto-preprocessor.js b/lighthouse-core/lib/proto-preprocessor.js index 6e9f85331e4e..a23d1d660877 100644 --- a/lighthouse-core/lib/proto-preprocessor.js +++ b/lighthouse-core/lib/proto-preprocessor.js @@ -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'; @@ -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; } diff --git a/lighthouse-core/test/lib/proto-preprocessor-test.js b/lighthouse-core/test/lib/proto-preprocessor-test.js index 3b2b33c130df..b35982970117 100644 --- a/lighthouse-core/test/lib/proto-preprocessor-test.js +++ b/lighthouse-core/test/lib/proto-preprocessor-test.js @@ -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': {