From 5bc58742ddd8919869e42b9052ed64736f9802b2 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 25 Apr 2018 13:35:59 -0700 Subject: [PATCH 01/12] core(config): switch to lantern by default, add config-preset --- lighthouse-cli/bin.js | 15 +++--- lighthouse-cli/cli-flags.js | 9 ++-- lighthouse-cli/test/smokehouse/byte-config.js | 14 +++++- .../test/smokehouse/perf/expectations.js | 2 +- lighthouse-cli/test/smokehouse/run-smoke.js | 3 +- .../smokehouse/tricky-ttci/expectations.js | 2 +- lighthouse-core/config/config.js | 7 ++- lighthouse-core/config/constants.js | 2 +- lighthouse-core/config/default-config.js | 7 ++- lighthouse-core/config/fast-config.js | 48 ------------------- .../config/mixed-content-config.js | 4 -- lighthouse-core/config/observed-config.js | 22 +++++++++ lighthouse-core/config/perf-config.js | 2 +- lighthouse-core/test/config/config-test.js | 14 ++++++ readme.md | 1 - typings/externs.d.ts | 1 + 16 files changed, 76 insertions(+), 77 deletions(-) delete mode 100644 lighthouse-core/config/fast-config.js create mode 100644 lighthouse-core/config/observed-config.js diff --git a/lighthouse-cli/bin.js b/lighthouse-cli/bin.js index a8bd557c2161..dbe42c46f686 100644 --- a/lighthouse-cli/bin.js +++ b/lighthouse-cli/bin.js @@ -14,8 +14,6 @@ const getFlags = require('./cli-flags.js').getFlags; const runLighthouse = require('./run').runLighthouse; const log = require('lighthouse-logger'); -const perfOnlyConfig = require('../lighthouse-core/config/perf-config.js'); -const mixedContentConfig = require('../lighthouse-core/config/mixed-content-config.js'); // @ts-ignore const pkg = require('../package.json'); const Sentry = require('../lighthouse-core/lib/sentry'); @@ -54,12 +52,13 @@ if (cliFlags.configPath) { // Resolve the config file path relative to where cli was called. cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath); config = /** @type {LH.Config.Json} */ (require(cliFlags.configPath)); -} else if (cliFlags.perf) { - config = perfOnlyConfig; -} else if (cliFlags.mixedContent) { - config = mixedContentConfig; - // The mixed-content audits require headless Chrome (https://crbug.com/764505). - cliFlags.chromeFlags = `${cliFlags.chromeFlags} --headless`; +} else if (cliFlags.configPreset) { + if (cliFlags.configPreset === 'mixed-content') { + // The mixed-content audits require headless Chrome (https://crbug.com/764505). + cliFlags.chromeFlags = `${cliFlags.chromeFlags} --headless`; + } + + config = require(`../lighthouse-core/config/${cliFlags.configPreset}-config.js`); } // set logging preferences diff --git a/lighthouse-cli/cli-flags.js b/lighthouse-cli/cli-flags.js index 63f2bae30ced..8bb261944a0d 100644 --- a/lighthouse-cli/cli-flags.js +++ b/lighthouse-cli/cli-flags.js @@ -58,7 +58,7 @@ function getFlags(manualArgv) { .group( [ 'save-assets', 'list-all-audits', 'list-trace-categories', 'additional-trace-categories', - 'config-path', 'chrome-flags', 'perf', 'mixed-content', 'port', 'hostname', + 'config-path', 'config-preset', 'chrome-flags', 'port', 'hostname', 'max-wait-for-load', 'enable-error-reporting', 'gather-mode', 'audit-mode', 'only-audits', 'only-categories', 'skip-audits', ], @@ -86,11 +86,10 @@ function getFlags(manualArgv) { 'additional-trace-categories': 'Additional categories to capture with the trace (comma-delimited).', 'config-path': 'The path to the config JSON.', - 'mixed-content': 'Use the mixed-content auditing configuration.', + 'config-preset': 'Use a built-in configuration.', 'chrome-flags': `Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://bit.ly/chrome-flags Additionally, use the CHROME_PATH environment variable to use a specific Chrome binary. Requires Chromium version 54.0 or later. If omitted, any detected Chrome Canary or Chrome stable will be used.`, - 'perf': 'Use a performance-test-only configuration', 'hostname': 'The hostname to use for the debugging protocol.', 'port': 'The port to use for the debugging protocol. Use 0 for a random port', 'max-wait-for-load': @@ -117,11 +116,11 @@ function getFlags(manualArgv) { // boolean values .boolean([ 'disable-storage-reset', 'disable-device-emulation', 'save-assets', 'list-all-audits', - 'list-trace-categories', 'perf', 'view', 'verbose', 'quiet', 'help', - 'mixed-content', + 'list-trace-categories', 'view', 'verbose', 'quiet', 'help', ]) .choices('output', printer.getValidOutputOptions()) .choices('throttling-method', ['devtools', 'provided', 'simulate']) + .choices('config-preset', ['observed', 'full', 'perf', 'mixed-content']) // force as an array // note MUST use camelcase versions or only the kebab-case version will be forced .array('blockedUrlPatterns') diff --git a/lighthouse-cli/test/smokehouse/byte-config.js b/lighthouse-cli/test/smokehouse/byte-config.js index d41aa7a18d6e..60e6ddaa009d 100644 --- a/lighthouse-cli/test/smokehouse/byte-config.js +++ b/lighthouse-cli/test/smokehouse/byte-config.js @@ -6,7 +6,7 @@ 'use strict'; /** - * Config file for running PWA smokehouse audits. + * Config file for running byte efficiency smokehouse audits. */ module.exports = { extends: 'lighthouse:full', @@ -22,5 +22,17 @@ module.exports = { 'unused-css-rules', 'unused-javascript', ], + + // TODO(phulce): re-write testers to work with faster lantern loading and remove all this + throttlingMethod: 'devtools', }, + passes: [ + { + passName: 'defaultPass', + useThrottling: true, + pauseAfterLoadMs: 5250, + networkQuietThresholdMs: 5250, + cpuQuietThresholdMs: 5250, + }, + ], }; diff --git a/lighthouse-cli/test/smokehouse/perf/expectations.js b/lighthouse-cli/test/smokehouse/perf/expectations.js index e033d622a66c..fe74212d1600 100644 --- a/lighthouse-cli/test/smokehouse/perf/expectations.js +++ b/lighthouse-cli/test/smokehouse/perf/expectations.js @@ -6,7 +6,7 @@ 'use strict'; /** - * Expected Lighthouse audit values for --perf tests + * Expected Lighthouse audit values for --config-preset=perf tests */ module.exports = [ { diff --git a/lighthouse-cli/test/smokehouse/run-smoke.js b/lighthouse-cli/test/smokehouse/run-smoke.js index 8c43334974bd..ea8f35d9ac60 100644 --- a/lighthouse-cli/test/smokehouse/run-smoke.js +++ b/lighthouse-cli/test/smokehouse/run-smoke.js @@ -77,7 +77,8 @@ const SMOKETESTS = [{ }, { id: 'ttci', expectations: 'tricky-ttci/expectations.js', - config: 'lighthouse-core/config/default-config.js', + // Explicitly tests a tricky case when in observed mode, use observed config + config: 'lighthouse-core/config/observed-config.js', batch: 'parallel-second', }]; diff --git a/lighthouse-cli/test/smokehouse/tricky-ttci/expectations.js b/lighthouse-cli/test/smokehouse/tricky-ttci/expectations.js index 2e068256ad03..c732f96ae0b1 100644 --- a/lighthouse-cli/test/smokehouse/tricky-ttci/expectations.js +++ b/lighthouse-cli/test/smokehouse/tricky-ttci/expectations.js @@ -6,7 +6,7 @@ 'use strict'; /** - * Expected Lighthouse audit values for --perf tests + * Expected Lighthouse audit values for tricky TTI tests */ module.exports = [ { diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index 4f2a891d7b0b..56525d0c24de 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -9,6 +9,7 @@ const defaultConfigPath = './default-config.js'; const defaultConfig = require('./default-config.js'); const fullConfig = require('./full-config.js'); +const observedConfig = require('./observed-config'); const constants = require('./constants'); const isDeepEqual = require('lodash.isequal'); @@ -187,7 +188,7 @@ function deepClone(json) { // injection of plugins. if (Array.isArray(json.passes)) { cloned.passes.forEach((pass, i) => { - pass.gatherers = cloneArrayWithPluginSafety(json.passes[i].gatherers); + pass.gatherers = cloneArrayWithPluginSafety(json.passes[i].gatherers || []); }); } @@ -224,6 +225,10 @@ class Config { const explodedFullConfig = Config.extendConfigJSON(deepClone(defaultConfig), deepClone(fullConfig)); configJSON = Config.extendConfigJSON(explodedFullConfig, configJSON); + } else if (configJSON.extends === 'lighthouse:observed') { + const explodedObservedConfig = Config.extendConfigJSON(deepClone(defaultConfig), + deepClone(observedConfig)); + configJSON = Config.extendConfigJSON(explodedObservedConfig, configJSON); } else if (configJSON.extends) { configJSON = Config.extendConfigJSON(deepClone(defaultConfig), configJSON); } diff --git a/lighthouse-core/config/constants.js b/lighthouse-core/config/constants.js index a667d3efc983..5e0e1dadd896 100644 --- a/lighthouse-core/config/constants.js +++ b/lighthouse-core/config/constants.js @@ -30,7 +30,7 @@ const throttling = { const defaultSettings = { output: 'json', maxWaitForLoad: 45 * 1000, - throttlingMethod: 'devtools', + throttlingMethod: 'simulate', throttling: throttling.mobile3G, auditMode: false, gatherMode: false, diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index d7f9af23b5e7..d24809fca513 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -14,10 +14,9 @@ module.exports = { passes: [{ passName: 'defaultPass', recordTrace: true, - useThrottling: true, - pauseAfterLoadMs: 5250, - networkQuietThresholdMs: 5250, - cpuQuietThresholdMs: 5250, + pauseAfterLoadMs: 500, + networkQuietThresholdMs: 500, + cpuQuietThresholdMs: 500, gatherers: [ 'url', 'scripts', diff --git a/lighthouse-core/config/fast-config.js b/lighthouse-core/config/fast-config.js deleted file mode 100644 index 366fb5875cbf..000000000000 --- a/lighthouse-core/config/fast-config.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @license Copyright 2017 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -module.exports = { - extends: 'lighthouse:default', - settings: { - skipAudits: [ - // disabled for now because they are too slow - 'no-mutation-events', - 'screenshot-thumbnails', - - // disabled for now because their results are not meaningful/cannot be computed anymore - 'first-meaningful-paint', - 'first-cpu-idle', - 'consistently-interactive', - 'estimated-input-latency', - 'speed-index', - 'offscreen-images', - 'load-fast-enough-for-pwa', - ], - }, - passes: [ - { - passName: 'defaultPass', - // overwrite the throttling and load wait parameters - useThrottling: false, - pauseAfterLoadMs: 0, - networkQuietThresholdMs: 500, - cpuQuietThresholdMs: 500, - // no need to add any gatherers yet, but this property is required - gatherers: [], - }, - ], - audits: [ - 'predictive-perf', - ], - categories: { - performance: { - audits: [ - {id: 'predictive-perf', weight: 5, group: 'perf-metric'}, - ], - }, - }, -}; diff --git a/lighthouse-core/config/mixed-content-config.js b/lighthouse-core/config/mixed-content-config.js index 1afe3de322a8..29ba715239e1 100644 --- a/lighthouse-core/config/mixed-content-config.js +++ b/lighthouse-core/config/mixed-content-config.js @@ -11,10 +11,6 @@ module.exports = { // (2) Re-load page but attempt to upgrade each request to HTTPS. passes: [{ passName: 'defaultPass', - // overwrite the throttling and load wait parameters to regular pass defaults - pauseAfterLoadMs: 0, - networkQuietThresholdMs: 0, - cpuQuietThresholdMs: 0, gatherers: ['url'], }, { passName: 'mixedContentPass', diff --git a/lighthouse-core/config/observed-config.js b/lighthouse-core/config/observed-config.js new file mode 100644 index 000000000000..d0a070a44653 --- /dev/null +++ b/lighthouse-core/config/observed-config.js @@ -0,0 +1,22 @@ +/** + * @license Copyright 2018 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +module.exports = { + extends: 'lighthouse:default', + settings: { + throttlingMethod: 'devtools', + }, + passes: [ + { + passName: 'defaultPass', + useThrottling: true, + pauseAfterLoadMs: 5250, + networkQuietThresholdMs: 5250, + cpuQuietThresholdMs: 5250, + }, + ], +}; diff --git a/lighthouse-core/config/perf-config.js b/lighthouse-core/config/perf-config.js index 916dd5968efc..309b74ce8900 100644 --- a/lighthouse-core/config/perf-config.js +++ b/lighthouse-core/config/perf-config.js @@ -6,7 +6,7 @@ 'use strict'; module.exports = { - extends: 'lighthouse:default', + extends: 'lighthouse:observed', settings: { onlyCategories: ['performance'], }, diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index e47d1c81b269..d246009bfe76 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -454,6 +454,20 @@ describe('Config', () => { assert.ok(auditNames.has('first-meaningful-paint'), 'did not include default audits'); }); + it('extends the observed config', () => { + const config = new Config({ + extends: 'lighthouse:observed', + settings: { + onlyCategories: ['performance'], + }, + }); + + const auditNames = new Set(config.audits.map(audit => audit.implementation.meta.name)); + assert.equal(config.settings.throttlingMethod, 'devtools'); + assert.ok(config.passes[0].networkQuietThresholdMs >= 5000, 'did not inherit network quiet ms'); + assert.ok(auditNames.has('first-contentful-paint'), 'did not include default audits'); + }); + it('merges settings with correct priority', () => { const config = new Config( { diff --git a/readme.md b/readme.md index 8850d383ea22..65296671114e 100644 --- a/readme.md +++ b/readme.md @@ -58,7 +58,6 @@ Configuration: CHROME_PATH: Explicit path of intended Chrome binary. If set must point to an executable of a build of Chromium version 54.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched. [default: ""] - --perf Use a performance-test-only configuration [boolean] --port The port to use for the debugging protocol. Use 0 for a random port [default: 0] --hostname The hostname to use for the debugging protocol. [default: "localhost"] --max-wait-for-load The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. diff --git a/typings/externs.d.ts b/typings/externs.d.ts index a5c8ceab5713..5caf348855a5 100644 --- a/typings/externs.d.ts +++ b/typings/externs.d.ts @@ -70,6 +70,7 @@ declare global { listAllAudits: boolean; listTraceCategories: boolean; configPath?: string; + configPreset?: 'observed'|'full'|'mixed-content'|'perf'; perf: boolean; mixedContent: boolean; verbose: boolean; From a7d0089b3ce6aaf556f23c8114610fde7e14ac3f Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 25 Apr 2018 14:08:43 -0700 Subject: [PATCH 02/12] continute to use observed for LHR diffing --- lighthouse-core/scripts/assert-golden-lhr-unchanged.sh | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh b/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh index 9b1ccae2b8aa..7191ac07f7f2 100644 --- a/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh +++ b/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh @@ -28,7 +28,8 @@ trap teardown EXIT colorText "Generating a fresh LHR..." "$purple" set -x -node "$lhroot_path/lighthouse-cli" -A="$lhroot_path/lighthouse-core/test/results/artifacts" --quiet --output=json --output-path="$freshLHRPath" http://localhost/dobetterweb/dbw_tester.html +# TODO(phulce): add a lantern LHR-differ +node "$lhroot_path/lighthouse-cli" -A="$lhroot_path/lighthouse-core/test/results/artifacts" --config-preset=observed --quiet --output=json --output-path="$freshLHRPath" http://localhost/dobetterweb/dbw_tester.html set +x # remove timing from both diff --git a/package.json b/package.json index 60fb6ba2135e..1dfef306008d 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile changelog.md --same-file", "type-check": "tsc -p .", "update:sample-artifacts": "node lighthouse-core/scripts/update-report-fixtures.js -G", - "update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing", + "update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --config-preset=observed --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing", "diff:sample-json": "bash lighthouse-core/scripts/assert-golden-lhr-unchanged.sh", "update:crdp-typings": "node lighthouse-core/scripts/extract-crdp-mapping.js", "mixed-content": "./lighthouse-cli/index.js --chrome-flags='--headless' --config-path=./lighthouse-core/config/mixed-content.js" From 2b24c228f5f8ec537def6a9674e2d8f90c266437 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 27 Apr 2018 17:08:20 -0700 Subject: [PATCH 03/12] feedback --- lighthouse-cli/bin.js | 6 ++-- lighthouse-cli/cli-flags.js | 6 ++-- .../test/smokehouse/perf/expectations.js | 2 +- lighthouse-cli/test/smokehouse/run-smoke.js | 3 +- lighthouse-core/config/config.js | 27 ++++++++++++--- lighthouse-core/config/default-config.js | 1 + lighthouse-core/config/perf-config.js | 3 +- .../scripts/assert-golden-lhr-unchanged.sh | 2 +- lighthouse-core/test/config/config-test.js | 33 ++++++++++++++++--- package.json | 2 +- typings/externs.d.ts | 2 +- 11 files changed, 65 insertions(+), 22 deletions(-) diff --git a/lighthouse-cli/bin.js b/lighthouse-cli/bin.js index dbe42c46f686..0a476317467e 100644 --- a/lighthouse-cli/bin.js +++ b/lighthouse-cli/bin.js @@ -52,13 +52,13 @@ if (cliFlags.configPath) { // Resolve the config file path relative to where cli was called. cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath); config = /** @type {LH.Config.Json} */ (require(cliFlags.configPath)); -} else if (cliFlags.configPreset) { - if (cliFlags.configPreset === 'mixed-content') { +} else if (cliFlags.preset) { + if (cliFlags.preset === 'mixed-content') { // The mixed-content audits require headless Chrome (https://crbug.com/764505). cliFlags.chromeFlags = `${cliFlags.chromeFlags} --headless`; } - config = require(`../lighthouse-core/config/${cliFlags.configPreset}-config.js`); + config = require(`../lighthouse-core/config/${cliFlags.preset}-config.js`); } // set logging preferences diff --git a/lighthouse-cli/cli-flags.js b/lighthouse-cli/cli-flags.js index 8bb261944a0d..0f63451451c2 100644 --- a/lighthouse-cli/cli-flags.js +++ b/lighthouse-cli/cli-flags.js @@ -58,7 +58,7 @@ function getFlags(manualArgv) { .group( [ 'save-assets', 'list-all-audits', 'list-trace-categories', 'additional-trace-categories', - 'config-path', 'config-preset', 'chrome-flags', 'port', 'hostname', + 'config-path', 'preset', 'chrome-flags', 'port', 'hostname', 'max-wait-for-load', 'enable-error-reporting', 'gather-mode', 'audit-mode', 'only-audits', 'only-categories', 'skip-audits', ], @@ -86,7 +86,7 @@ function getFlags(manualArgv) { 'additional-trace-categories': 'Additional categories to capture with the trace (comma-delimited).', 'config-path': 'The path to the config JSON.', - 'config-preset': 'Use a built-in configuration.', + 'preset': 'Use a built-in configuration.', 'chrome-flags': `Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://bit.ly/chrome-flags Additionally, use the CHROME_PATH environment variable to use a specific Chrome binary. Requires Chromium version 54.0 or later. If omitted, any detected Chrome Canary or Chrome stable will be used.`, @@ -120,7 +120,7 @@ function getFlags(manualArgv) { ]) .choices('output', printer.getValidOutputOptions()) .choices('throttling-method', ['devtools', 'provided', 'simulate']) - .choices('config-preset', ['observed', 'full', 'perf', 'mixed-content']) + .choices('preset', ['full', 'perf', 'mixed-content']) // force as an array // note MUST use camelcase versions or only the kebab-case version will be forced .array('blockedUrlPatterns') diff --git a/lighthouse-cli/test/smokehouse/perf/expectations.js b/lighthouse-cli/test/smokehouse/perf/expectations.js index fe74212d1600..6df2f0acaf01 100644 --- a/lighthouse-cli/test/smokehouse/perf/expectations.js +++ b/lighthouse-cli/test/smokehouse/perf/expectations.js @@ -6,7 +6,7 @@ 'use strict'; /** - * Expected Lighthouse audit values for --config-preset=perf tests + * Expected Lighthouse audit values for --preset=perf tests */ module.exports = [ { diff --git a/lighthouse-cli/test/smokehouse/run-smoke.js b/lighthouse-cli/test/smokehouse/run-smoke.js index ea8f35d9ac60..5b1ad9004301 100644 --- a/lighthouse-cli/test/smokehouse/run-smoke.js +++ b/lighthouse-cli/test/smokehouse/run-smoke.js @@ -77,8 +77,7 @@ const SMOKETESTS = [{ }, { id: 'ttci', expectations: 'tricky-ttci/expectations.js', - // Explicitly tests a tricky case when in observed mode, use observed config - config: 'lighthouse-core/config/observed-config.js', + config: 'lighthouse-core/config/perf-config.js', batch: 'parallel-second', }]; diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index 56525d0c24de..06d8cbbf0fd2 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -9,7 +9,6 @@ const defaultConfigPath = './default-config.js'; const defaultConfig = require('./default-config.js'); const fullConfig = require('./full-config.js'); -const observedConfig = require('./observed-config'); const constants = require('./constants'); const isDeepEqual = require('lodash.isequal'); @@ -225,10 +224,6 @@ class Config { const explodedFullConfig = Config.extendConfigJSON(deepClone(defaultConfig), deepClone(fullConfig)); configJSON = Config.extendConfigJSON(explodedFullConfig, configJSON); - } else if (configJSON.extends === 'lighthouse:observed') { - const explodedObservedConfig = Config.extendConfigJSON(deepClone(defaultConfig), - deepClone(observedConfig)); - configJSON = Config.extendConfigJSON(explodedObservedConfig, configJSON); } else if (configJSON.extends) { configJSON = Config.extendConfigJSON(deepClone(defaultConfig), configJSON); } @@ -254,6 +249,8 @@ class Config { skipAuditIds); } + Config.adjustDefaultPassForThrottling(configJSON); + // Store the directory of the config path, if one was provided. this._configDir = configPath ? path.dirname(configPath) : undefined; @@ -386,6 +383,26 @@ class Config { return mergedItems; } + /** + * Observed throttling methods (devtools/provided) require at least 5s of quiet for the metrics to + * be computed. This method adjusts the quiet thresholds to the required minimums if necessary. + * + * @param {LH.Config.Json} config + */ + static adjustDefaultPassForThrottling(config) { + if (config.settings.throttlingMethod !== 'devtools' && + config.settings.throttlingMethod !== 'provided') { + return; + } + + const defaultPass = config.passes.find(pass => pass.passName === 'defaultPass'); + if (!defaultPass) return; + + defaultPass.pauseAfterLoadMs = Math.max(5250, defaultPass.pauseAfterLoadMs); + defaultPass.cpuQuietThresholdMs = Math.max(5250, defaultPass.cpuQuietThresholdMs); + defaultPass.networkQuietThresholdMs = Math.max(5250, defaultPass.networkQuietThresholdMs); + } + /** * Filter out any unrequested items from the config, based on requested top-level categories. * @param {!Object} oldConfig Lighthouse config object diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index d24809fca513..a3b5d9b4f6c7 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -14,6 +14,7 @@ module.exports = { passes: [{ passName: 'defaultPass', recordTrace: true, + useThrottling: true, pauseAfterLoadMs: 500, networkQuietThresholdMs: 500, cpuQuietThresholdMs: 500, diff --git a/lighthouse-core/config/perf-config.js b/lighthouse-core/config/perf-config.js index 309b74ce8900..a00e1445912e 100644 --- a/lighthouse-core/config/perf-config.js +++ b/lighthouse-core/config/perf-config.js @@ -6,8 +6,9 @@ 'use strict'; module.exports = { - extends: 'lighthouse:observed', + extends: 'lighthouse:default', settings: { + throttlingMethod: 'devtools', onlyCategories: ['performance'], }, }; diff --git a/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh b/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh index 7191ac07f7f2..efe6a3311bb7 100644 --- a/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh +++ b/lighthouse-core/scripts/assert-golden-lhr-unchanged.sh @@ -29,7 +29,7 @@ trap teardown EXIT colorText "Generating a fresh LHR..." "$purple" set -x # TODO(phulce): add a lantern LHR-differ -node "$lhroot_path/lighthouse-cli" -A="$lhroot_path/lighthouse-core/test/results/artifacts" --config-preset=observed --quiet --output=json --output-path="$freshLHRPath" http://localhost/dobetterweb/dbw_tester.html +node "$lhroot_path/lighthouse-cli" -A="$lhroot_path/lighthouse-core/test/results/artifacts" --throttling-method=devtools --quiet --output=json --output-path="$freshLHRPath" http://localhost/dobetterweb/dbw_tester.html set +x # remove timing from both diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index d246009bfe76..e508d1cc31fd 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -454,18 +454,43 @@ describe('Config', () => { assert.ok(auditNames.has('first-meaningful-paint'), 'did not include default audits'); }); - it('extends the observed config', () => { + it('ensures quiet thresholds are sufficient when using devtools', () => { const config = new Config({ - extends: 'lighthouse:observed', + extends: 'lighthouse:default', + settings: { + throttlingMethod: 'devtools', + onlyCategories: ['performance'], + }, + }); + + const auditNames = new Set(config.audits.map(audit => audit.implementation.meta.name)); + assert.equal(config.settings.throttlingMethod, 'devtools'); + assert.ok(config.passes[0].pauseAfterLoadMs >= 5000, 'did not adjust load quiet ms'); + assert.ok(config.passes[0].cpuQuietThresholdMs >= 5000, 'did not adjust cpu quiet ms'); + assert.ok(config.passes[0].networkQuietThresholdMs >= 5000, 'did not adjust network quiet ms'); + }); + + it('does nothing when thresholds for devtools are already sufficient', () => { + const config = new Config({ + extends: 'lighthouse:default', settings: { + throttlingMethod: 'devtools', onlyCategories: ['performance'], }, + passes: [ + { + pauseAfterLoadMs: 10001, + cpuQuietThresholdMs: 10002, + networkQuietThresholdMs: 10003, + } + ], }); const auditNames = new Set(config.audits.map(audit => audit.implementation.meta.name)); assert.equal(config.settings.throttlingMethod, 'devtools'); - assert.ok(config.passes[0].networkQuietThresholdMs >= 5000, 'did not inherit network quiet ms'); - assert.ok(auditNames.has('first-contentful-paint'), 'did not include default audits'); + assert.equal(config.passes[0].pauseAfterLoadMs, 10001); + assert.equal(config.passes[0].cpuQuietThresholdMs, 10002); + assert.equal(config.passes[0].networkQuietThresholdMs, 10003); }); it('merges settings with correct priority', () => { diff --git a/package.json b/package.json index 1dfef306008d..7135ecaad74f 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile changelog.md --same-file", "type-check": "tsc -p .", "update:sample-artifacts": "node lighthouse-core/scripts/update-report-fixtures.js -G", - "update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --config-preset=observed --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing", + "update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --throttling-method=devtools --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing", "diff:sample-json": "bash lighthouse-core/scripts/assert-golden-lhr-unchanged.sh", "update:crdp-typings": "node lighthouse-core/scripts/extract-crdp-mapping.js", "mixed-content": "./lighthouse-cli/index.js --chrome-flags='--headless' --config-path=./lighthouse-core/config/mixed-content.js" diff --git a/typings/externs.d.ts b/typings/externs.d.ts index 5caf348855a5..61861015dc0d 100644 --- a/typings/externs.d.ts +++ b/typings/externs.d.ts @@ -70,7 +70,7 @@ declare global { listAllAudits: boolean; listTraceCategories: boolean; configPath?: string; - configPreset?: 'observed'|'full'|'mixed-content'|'perf'; + preset?: 'full'|'mixed-content'|'perf'; perf: boolean; mixedContent: boolean; verbose: boolean; From ed63596ab24d7ee57d12f64bc143d3ee6b204911 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 27 Apr 2018 17:10:28 -0700 Subject: [PATCH 04/12] remove observed --- lighthouse-core/config/observed-config.js | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 lighthouse-core/config/observed-config.js diff --git a/lighthouse-core/config/observed-config.js b/lighthouse-core/config/observed-config.js deleted file mode 100644 index d0a070a44653..000000000000 --- a/lighthouse-core/config/observed-config.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @license Copyright 2018 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -module.exports = { - extends: 'lighthouse:default', - settings: { - throttlingMethod: 'devtools', - }, - passes: [ - { - passName: 'defaultPass', - useThrottling: true, - pauseAfterLoadMs: 5250, - networkQuietThresholdMs: 5250, - cpuQuietThresholdMs: 5250, - }, - ], -}; From 08d65f88bb27459e6d59bcfc8f689f0f8aafe39d Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 27 Apr 2018 17:11:12 -0700 Subject: [PATCH 05/12] remove defaultPass rejigger --- lighthouse-cli/test/smokehouse/byte-config.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lighthouse-cli/test/smokehouse/byte-config.js b/lighthouse-cli/test/smokehouse/byte-config.js index 60e6ddaa009d..78c58b7fbab2 100644 --- a/lighthouse-cli/test/smokehouse/byte-config.js +++ b/lighthouse-cli/test/smokehouse/byte-config.js @@ -23,16 +23,7 @@ module.exports = { 'unused-javascript', ], - // TODO(phulce): re-write testers to work with faster lantern loading and remove all this + // TODO(phulce): re-write testers to work with faster lantern loading throttlingMethod: 'devtools', }, - passes: [ - { - passName: 'defaultPass', - useThrottling: true, - pauseAfterLoadMs: 5250, - networkQuietThresholdMs: 5250, - cpuQuietThresholdMs: 5250, - }, - ], }; From b71d604407ae6d9148aa5dc0ea7e186fecd05fff Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 27 Apr 2018 17:16:55 -0700 Subject: [PATCH 06/12] lint --- lighthouse-core/test/config/config-test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index e508d1cc31fd..2492eea6d1a1 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -463,7 +463,6 @@ describe('Config', () => { }, }); - const auditNames = new Set(config.audits.map(audit => audit.implementation.meta.name)); assert.equal(config.settings.throttlingMethod, 'devtools'); assert.ok(config.passes[0].pauseAfterLoadMs >= 5000, 'did not adjust load quiet ms'); assert.ok(config.passes[0].cpuQuietThresholdMs >= 5000, 'did not adjust cpu quiet ms'); @@ -482,11 +481,10 @@ describe('Config', () => { pauseAfterLoadMs: 10001, cpuQuietThresholdMs: 10002, networkQuietThresholdMs: 10003, - } + }, ], }); - const auditNames = new Set(config.audits.map(audit => audit.implementation.meta.name)); assert.equal(config.settings.throttlingMethod, 'devtools'); assert.equal(config.passes[0].pauseAfterLoadMs, 10001); assert.equal(config.passes[0].cpuQuietThresholdMs, 10002); From 287c94c0787ae18ba47bd243e237fcf53069d686 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Mon, 30 Apr 2018 09:50:37 -0700 Subject: [PATCH 07/12] remove fastMode option from extension --- lighthouse-extension/app/src/lighthouse-background.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lighthouse-extension/app/src/lighthouse-background.js b/lighthouse-extension/app/src/lighthouse-background.js index 7ac1fc2f4cf1..3e33a6d288ca 100644 --- a/lighthouse-extension/app/src/lighthouse-background.js +++ b/lighthouse-extension/app/src/lighthouse-background.js @@ -9,7 +9,6 @@ const RawProtocol = require('../../../lighthouse-core/gather/connections/raw'); const Runner = require('../../../lighthouse-core/runner'); const Config = require('../../../lighthouse-core/config/config'); const defaultConfig = require('../../../lighthouse-core/config/default-config.js'); -const fastConfig = require('../../../lighthouse-core/config/fast-config.js'); const log = require('lighthouse-logger'); /** @@ -22,7 +21,7 @@ const log = require('lighthouse-logger'); window.runLighthouseForConnection = function( connection, url, options, categoryIDs, updateBadgeFn = function() { }) { - const config = options && options.fastMode ? new Config(fastConfig, options.flags) : new Config({ + const config = new Config({ extends: 'lighthouse:default', settings: {onlyCategories: categoryIDs}, }, options.flags); From 94f5155691ee1bc90d4d56de1929cdf8dc5b4c1c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Mon, 30 Apr 2018 17:43:34 -0700 Subject: [PATCH 08/12] bump to 1000 --- lighthouse-core/config/default-config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index 16beb0df1563..b38c98fb8c4a 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -15,9 +15,9 @@ module.exports = { passName: 'defaultPass', recordTrace: true, useThrottling: true, - pauseAfterLoadMs: 500, - networkQuietThresholdMs: 500, - cpuQuietThresholdMs: 500, + pauseAfterLoadMs: 1000, + networkQuietThresholdMs: 1000, + cpuQuietThresholdMs: 1000, gatherers: [ 'url', 'scripts', From 3126132decb524081a295b36333df78a68fca0c8 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 1 May 2018 19:28:30 -0700 Subject: [PATCH 09/12] move to constants --- lighthouse-core/config/config.js | 10 +++++++--- lighthouse-core/config/constants.js | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index 06d8cbbf0fd2..a25a1709112b 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -398,9 +398,13 @@ class Config { const defaultPass = config.passes.find(pass => pass.passName === 'defaultPass'); if (!defaultPass) return; - defaultPass.pauseAfterLoadMs = Math.max(5250, defaultPass.pauseAfterLoadMs); - defaultPass.cpuQuietThresholdMs = Math.max(5250, defaultPass.cpuQuietThresholdMs); - defaultPass.networkQuietThresholdMs = Math.max(5250, defaultPass.networkQuietThresholdMs); + const overrides = constants.observedPassConfigOverrides; + defaultPass.pauseAfterLoadMs = + Math.max(overrides.pauseAfterLoadMs, defaultPass.pauseAfterLoadMs); + defaultPass.cpuQuietThresholdMs = + Math.max(overrides.cpuQuietThresholdMs, defaultPass.cpuQuietThresholdMs); + defaultPass.networkQuietThresholdMs = + Math.max(overrides.networkQuietThresholdMs, defaultPass.networkQuietThresholdMs); } /** diff --git a/lighthouse-core/config/constants.js b/lighthouse-core/config/constants.js index 5e0e1dadd896..647cc4d338d1 100644 --- a/lighthouse-core/config/constants.js +++ b/lighthouse-core/config/constants.js @@ -60,8 +60,15 @@ const defaultPassConfig = { gatherers: [], }; +const observedPassConfigOverrides = { + pauseAfterLoadMs: 5250, + networkQuietThresholdMs: 5250, + cpuQuietThresholdMs: 5250, +}; + module.exports = { throttling, defaultSettings, defaultPassConfig, + observedPassConfigOverrides, }; From 4b7c1fbcbae68ab942155c49a5b492d471d7d579 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 2 May 2018 16:25:04 -0700 Subject: [PATCH 10/12] put offline in its own batch --- lighthouse-cli/test/smokehouse/run-smoke.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-cli/test/smokehouse/run-smoke.js b/lighthouse-cli/test/smokehouse/run-smoke.js index 5374c7fdf63c..96c185130fca 100644 --- a/lighthouse-cli/test/smokehouse/run-smoke.js +++ b/lighthouse-cli/test/smokehouse/run-smoke.js @@ -63,7 +63,7 @@ const SMOKETESTS = [{ id: 'offline', expectations: 'offline-local/offline-expectations.js', config: smokehouseDir + 'offline-config.js', - batch: 'parallel-second', + batch: 'offline', }, { id: 'byte', expectations: 'byte-efficiency/expectations.js', From 0baf005c3fd5f230493e4a811bdc11069f58328c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Thu, 3 May 2018 08:30:43 -0700 Subject: [PATCH 11/12] observed -> nonSimulated --- lighthouse-core/config/config.js | 2 +- lighthouse-core/config/constants.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index a25a1709112b..b25233db8254 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -398,7 +398,7 @@ class Config { const defaultPass = config.passes.find(pass => pass.passName === 'defaultPass'); if (!defaultPass) return; - const overrides = constants.observedPassConfigOverrides; + const overrides = constants.nonSimulatedPassConfigOverrides; defaultPass.pauseAfterLoadMs = Math.max(overrides.pauseAfterLoadMs, defaultPass.pauseAfterLoadMs); defaultPass.cpuQuietThresholdMs = diff --git a/lighthouse-core/config/constants.js b/lighthouse-core/config/constants.js index 647cc4d338d1..a8995d633264 100644 --- a/lighthouse-core/config/constants.js +++ b/lighthouse-core/config/constants.js @@ -60,7 +60,7 @@ const defaultPassConfig = { gatherers: [], }; -const observedPassConfigOverrides = { +const nonSimulatedPassConfigOverrides = { pauseAfterLoadMs: 5250, networkQuietThresholdMs: 5250, cpuQuietThresholdMs: 5250, @@ -70,5 +70,5 @@ module.exports = { throttling, defaultSettings, defaultPassConfig, - observedPassConfigOverrides, + nonSimulatedPassConfigOverrides, }; From 3412c82ccc0b5dfc54d322e58634c5fee5de784c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Thu, 3 May 2018 12:32:06 -0700 Subject: [PATCH 12/12] feedback --- lighthouse-core/test/config/config-test.js | 3 ++- readme.md | 1 + typings/config.d.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index 2492eea6d1a1..156509a144f0 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -459,14 +459,15 @@ describe('Config', () => { extends: 'lighthouse:default', settings: { throttlingMethod: 'devtools', - onlyCategories: ['performance'], }, }); assert.equal(config.settings.throttlingMethod, 'devtools'); + assert.equal(config.passes[0].passName, 'defaultPass'); assert.ok(config.passes[0].pauseAfterLoadMs >= 5000, 'did not adjust load quiet ms'); assert.ok(config.passes[0].cpuQuietThresholdMs >= 5000, 'did not adjust cpu quiet ms'); assert.ok(config.passes[0].networkQuietThresholdMs >= 5000, 'did not adjust network quiet ms'); + assert.equal(config.passes[1].pauseAfterLoadMs, 0, 'should not have touched non-defaultPass'); }); it('does nothing when thresholds for devtools are already sufficient', () => { diff --git a/readme.md b/readme.md index 65296671114e..f8d0bab8fef8 100644 --- a/readme.md +++ b/readme.md @@ -59,6 +59,7 @@ Configuration: Chromium version 54.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched. [default: ""] --port The port to use for the debugging protocol. Use 0 for a random port [default: 0] + --preset Use a built-in configuration. [choices: "full", "perf", "mixed-content"] --hostname The hostname to use for the debugging protocol. [default: "localhost"] --max-wait-for-load The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. WARNING: Very high values can lead to large traces and instability [default: 45000] diff --git a/typings/config.d.ts b/typings/config.d.ts index d10ccaf5f1f6..7ddb48c8166f 100644 --- a/typings/config.d.ts +++ b/typings/config.d.ts @@ -45,7 +45,7 @@ declare global { blockedUrlPatterns?: string[]; blankPage?: string; blankDuration?: number; - gatherers: GathererJson[]; + gatherers?: GathererJson[]; } export type GathererJson = {