diff --git a/docs/configuration.md b/docs/configuration.md index 5ad909268beb..8dd2f796f450 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -39,19 +39,17 @@ lighthouse('https://example.com/', {port: 9222}, config); | Name | Type | | - | - | -| extends | string|boolean|undefined | +| extends | string|undefined | | settings | Object|undefined | | passes | Object[] | | audits | string[] | | categories | Object|undefined | | groups | Object|undefined | -### `extends: "lighthouse:default"|boolean|undefined` +### `extends: "lighthouse:default"|undefined` The `extends` property controls if your configuration should inherit from the default Lighthouse configuration. [Learn more.](#config-extension) -Both the values `"lighthouse:default"` and `true` will enable inheritance, while `false` and `undefined` will not. - #### Example ```js { diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index a9ae01b88a26..06ac0e8eb22f 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -325,6 +325,9 @@ class Config { // Extend the default config if specified if (configJSON.extends) { + if (configJSON.extends !== 'lighthouse:default') { + throw new Error('`lighthouse:default` is the only valid extension method.'); + } configJSON = Config.extendConfigJSON(deepCloneConfigJson(defaultConfig), configJSON); } diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index 4feaea170284..0471f8f08abb 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -620,7 +620,7 @@ describe('Config', () => { const saveWarning = evt => warnings.push(evt); log.events.addListener('warning', saveWarning); const config = new Config({ - extends: true, + extends: 'lighthouse:default', settings: { onlyCategories: ['accessibility'], }, @@ -638,7 +638,7 @@ describe('Config', () => { const saveWarning = evt => warnings.push(evt); log.events.addListener('warning', saveWarning); const config = new Config({ - extends: true, + extends: 'lighthouse:default', settings: { onlyCategories: ['performance', 'pwa'], }, @@ -655,7 +655,7 @@ describe('Config', () => { it('filters works with extension', () => { const config = new Config({ - extends: true, + extends: 'lighthouse:default', settings: { onlyCategories: ['performance'], onlyAudits: ['is-on-https'], @@ -672,7 +672,7 @@ describe('Config', () => { const saveWarning = evt => warnings.push(evt); log.events.addListener('warning', saveWarning); const config = new Config({ - extends: true, + extends: 'lighthouse:default', settings: { onlyCategories: ['performance', 'missing-category'], onlyAudits: ['first-cpu-idle', 'missing-audit'], @@ -687,7 +687,7 @@ describe('Config', () => { it('throws for invalid use of skipAudits and onlyAudits', () => { assert.throws(() => { new Config({ - extends: true, + extends: 'lighthouse:default', settings: { onlyAudits: ['first-meaningful-paint'], skipAudits: ['first-meaningful-paint'], @@ -697,22 +697,17 @@ describe('Config', () => { }); it('cleans up flags for settings', () => { - const config = new Config({extends: true}, {nonsense: 1, foo: 2, throttlingMethod: 'provided'}); + const config = new Config({extends: 'lighthouse:default'}, + {nonsense: 1, foo: 2, throttlingMethod: 'provided'}); assert.equal(config.settings.throttlingMethod, 'provided'); assert.ok(config.settings.nonsense === undefined, 'did not cleanup settings'); }); it('allows overriding of array-typed settings', () => { - const config = new Config({extends: true}, {output: ['html']}); + const config = new Config({extends: 'lighthouse:default'}, {output: ['html']}); assert.deepStrictEqual(config.settings.output, ['html']); }); - it('does not throw on "lighthouse:full"', () => { - const config = new Config({extends: 'lighthouse:full'}, {output: ['html', 'json']}); - assert.deepStrictEqual(config.settings.throttlingMethod, 'simulate'); - assert.deepStrictEqual(config.settings.output, ['html', 'json']); - }); - it('extends the config', () => { class CustomAudit extends Audit { static get meta() { @@ -783,6 +778,14 @@ describe('Config', () => { assert.equal(config.passes[0].networkQuietThresholdMs, 10003); }); + it('only supports `lighthouse:default` extension', () => { + const createConfig = extendsValue => new Config({extends: extendsValue}); + + expect(() => createConfig(true)).toThrowError(/default` is the only valid extension/); + expect(() => createConfig('lighthouse')).toThrowError(/default` is the only valid/); + expect(() => createConfig('lighthouse:full')).toThrowError(/default` is the only valid/); + }); + it('merges settings with correct priority', () => { const config = new Config( { @@ -897,9 +900,9 @@ describe('Config', () => { devtoolsLogs: {defaultPass: 'path/to/devtools/log'}, }; const configA = {}; - const configB = {extends: true, artifacts}; + const configB = {extends: 'lighthouse:default', artifacts}; const merged = Config.extendConfigJSON(configA, configB); - assert.equal(merged.extends, true); + assert.equal(merged.extends, 'lighthouse:default'); assert.equal(merged.artifacts, configB.artifacts); }); }); diff --git a/types/config.d.ts b/types/config.d.ts index c36d3d09e939..5323e383824a 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -17,7 +17,7 @@ declare global { * The pre-normalization Lighthouse Config format. */ export interface Json { - extends?: 'lighthouse:default' | string | boolean; + extends?: 'lighthouse:default' | string; settings?: SharedFlagsSettings; passes?: PassJson[] | null; audits?: Config.AuditJson[] | null;