From 0fbfb24167c2fe93886b03e0892f5716d3066c5f Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Wed, 17 Oct 2018 12:28:12 -0700 Subject: [PATCH 1/4] Added output to preprocessor. --- lighthouse-core/lib/proto-preprocessor.js | 10 ++++++++++ .../test/lib/proto-preprocessor-test.js | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lighthouse-core/lib/proto-preprocessor.js b/lighthouse-core/lib/proto-preprocessor.js index 6e9f85331e4e..71e9afbb1697 100644 --- a/lighthouse-core/lib/proto-preprocessor.js +++ b/lighthouse-core/lib/proto-preprocessor.js @@ -22,6 +22,16 @@ function processForProto(result) { /** @type {LH.Result} */ const reportJson = JSON.parse(result); + // Clean up the configSettings + if ('configSettings' in reportJson) { + // make sure the 'output' field is an array + if ('output' in reportJson.configSettings) { + if (!Array.isArray(reportJson.configSettings.output)) { + reportJson.configSettings.output = [reportJson.configSettings.output]; + } + } + } + // Clean up actions that require 'audits' to exist if ('audits' in reportJson) { Object.keys(reportJson.audits).forEach(auditName => { 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': { From 6c83b0433b1f94999c6dad0366f29d1530f55a75 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Wed, 17 Oct 2018 16:45:33 -0700 Subject: [PATCH 2/4] Update lighthouse-core/lib/proto-preprocessor.js --- lighthouse-core/lib/proto-preprocessor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-core/lib/proto-preprocessor.js b/lighthouse-core/lib/proto-preprocessor.js index 71e9afbb1697..7bb17cf298ab 100644 --- a/lighthouse-core/lib/proto-preprocessor.js +++ b/lighthouse-core/lib/proto-preprocessor.js @@ -23,7 +23,7 @@ function processForProto(result) { const reportJson = JSON.parse(result); // Clean up the configSettings - if ('configSettings' in reportJson) { + if (reportJson.configSettings) { // make sure the 'output' field is an array if ('output' in reportJson.configSettings) { if (!Array.isArray(reportJson.configSettings.output)) { From a8b8f1328ffdbc6166a05db9bb950429536cd895 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Wed, 17 Oct 2018 16:45:54 -0700 Subject: [PATCH 3/4] Update lighthouse-core/lib/proto-preprocessor.js --- lighthouse-core/lib/proto-preprocessor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-core/lib/proto-preprocessor.js b/lighthouse-core/lib/proto-preprocessor.js index 7bb17cf298ab..80a2f2602c84 100644 --- a/lighthouse-core/lib/proto-preprocessor.js +++ b/lighthouse-core/lib/proto-preprocessor.js @@ -25,7 +25,7 @@ function processForProto(result) { // Clean up the configSettings if (reportJson.configSettings) { // make sure the 'output' field is an array - if ('output' in reportJson.configSettings) { + if (reportJson.configSettings.output) { if (!Array.isArray(reportJson.configSettings.output)) { reportJson.configSettings.output = [reportJson.configSettings.output]; } From e2d8c89e8bf1e03fc0888adfc2bc8ed7a01643f9 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Wed, 17 Oct 2018 16:50:15 -0700 Subject: [PATCH 4/4] Inspired by brendan's advice. --- lighthouse-core/lib/proto-preprocessor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/lib/proto-preprocessor.js b/lighthouse-core/lib/proto-preprocessor.js index 80a2f2602c84..a23d1d660877 100644 --- a/lighthouse-core/lib/proto-preprocessor.js +++ b/lighthouse-core/lib/proto-preprocessor.js @@ -33,12 +33,12 @@ function processForProto(result) { } // 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'; @@ -62,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; }