Skip to content

Commit ea5afa4

Browse files
authoredDec 15, 2020
core(config): only allow lighthouse:default extension (#11835)
1 parent a30953c commit ea5afa4

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed
 

‎docs/configuration.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,17 @@ lighthouse('https://example.com/', {port: 9222}, config);
3939

4040
| Name | Type |
4141
| - | - |
42-
| extends | <code>string&#124;boolean&#124;undefined</code> |
42+
| extends | <code>string&#124;undefined</code> |
4343
| settings | <code>Object&#124;undefined</code> |
4444
| passes | <code>Object[]</code> |
4545
| audits | <code>string[]</code> |
4646
| categories | <code>Object&#124;undefined</code> |
4747
| groups | <code>Object&#124;undefined</code> |
4848

49-
### `extends: "lighthouse:default"|boolean|undefined`
49+
### `extends: "lighthouse:default"|undefined`
5050

5151
The `extends` property controls if your configuration should inherit from the default Lighthouse configuration. [Learn more.](#config-extension)
5252

53-
Both the values `"lighthouse:default"` and `true` will enable inheritance, while `false` and `undefined` will not.
54-
5553
#### Example
5654
```js
5755
{

‎lighthouse-core/config/config.js

+3
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ class Config {
325325

326326
// Extend the default config if specified
327327
if (configJSON.extends) {
328+
if (configJSON.extends !== 'lighthouse:default') {
329+
throw new Error('`lighthouse:default` is the only valid extension method.');
330+
}
328331
configJSON = Config.extendConfigJSON(deepCloneConfigJson(defaultConfig), configJSON);
329332
}
330333

‎lighthouse-core/test/config/config-test.js

+18-15
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ describe('Config', () => {
620620
const saveWarning = evt => warnings.push(evt);
621621
log.events.addListener('warning', saveWarning);
622622
const config = new Config({
623-
extends: true,
623+
extends: 'lighthouse:default',
624624
settings: {
625625
onlyCategories: ['accessibility'],
626626
},
@@ -638,7 +638,7 @@ describe('Config', () => {
638638
const saveWarning = evt => warnings.push(evt);
639639
log.events.addListener('warning', saveWarning);
640640
const config = new Config({
641-
extends: true,
641+
extends: 'lighthouse:default',
642642
settings: {
643643
onlyCategories: ['performance', 'pwa'],
644644
},
@@ -655,7 +655,7 @@ describe('Config', () => {
655655

656656
it('filters works with extension', () => {
657657
const config = new Config({
658-
extends: true,
658+
extends: 'lighthouse:default',
659659
settings: {
660660
onlyCategories: ['performance'],
661661
onlyAudits: ['is-on-https'],
@@ -672,7 +672,7 @@ describe('Config', () => {
672672
const saveWarning = evt => warnings.push(evt);
673673
log.events.addListener('warning', saveWarning);
674674
const config = new Config({
675-
extends: true,
675+
extends: 'lighthouse:default',
676676
settings: {
677677
onlyCategories: ['performance', 'missing-category'],
678678
onlyAudits: ['first-cpu-idle', 'missing-audit'],
@@ -687,7 +687,7 @@ describe('Config', () => {
687687
it('throws for invalid use of skipAudits and onlyAudits', () => {
688688
assert.throws(() => {
689689
new Config({
690-
extends: true,
690+
extends: 'lighthouse:default',
691691
settings: {
692692
onlyAudits: ['first-meaningful-paint'],
693693
skipAudits: ['first-meaningful-paint'],
@@ -697,22 +697,17 @@ describe('Config', () => {
697697
});
698698

699699
it('cleans up flags for settings', () => {
700-
const config = new Config({extends: true}, {nonsense: 1, foo: 2, throttlingMethod: 'provided'});
700+
const config = new Config({extends: 'lighthouse:default'},
701+
{nonsense: 1, foo: 2, throttlingMethod: 'provided'});
701702
assert.equal(config.settings.throttlingMethod, 'provided');
702703
assert.ok(config.settings.nonsense === undefined, 'did not cleanup settings');
703704
});
704705

705706
it('allows overriding of array-typed settings', () => {
706-
const config = new Config({extends: true}, {output: ['html']});
707+
const config = new Config({extends: 'lighthouse:default'}, {output: ['html']});
707708
assert.deepStrictEqual(config.settings.output, ['html']);
708709
});
709710

710-
it('does not throw on "lighthouse:full"', () => {
711-
const config = new Config({extends: 'lighthouse:full'}, {output: ['html', 'json']});
712-
assert.deepStrictEqual(config.settings.throttlingMethod, 'simulate');
713-
assert.deepStrictEqual(config.settings.output, ['html', 'json']);
714-
});
715-
716711
it('extends the config', () => {
717712
class CustomAudit extends Audit {
718713
static get meta() {
@@ -783,6 +778,14 @@ describe('Config', () => {
783778
assert.equal(config.passes[0].networkQuietThresholdMs, 10003);
784779
});
785780

781+
it('only supports `lighthouse:default` extension', () => {
782+
const createConfig = extendsValue => new Config({extends: extendsValue});
783+
784+
expect(() => createConfig(true)).toThrowError(/default` is the only valid extension/);
785+
expect(() => createConfig('lighthouse')).toThrowError(/default` is the only valid/);
786+
expect(() => createConfig('lighthouse:full')).toThrowError(/default` is the only valid/);
787+
});
788+
786789
it('merges settings with correct priority', () => {
787790
const config = new Config(
788791
{
@@ -897,9 +900,9 @@ describe('Config', () => {
897900
devtoolsLogs: {defaultPass: 'path/to/devtools/log'},
898901
};
899902
const configA = {};
900-
const configB = {extends: true, artifacts};
903+
const configB = {extends: 'lighthouse:default', artifacts};
901904
const merged = Config.extendConfigJSON(configA, configB);
902-
assert.equal(merged.extends, true);
905+
assert.equal(merged.extends, 'lighthouse:default');
903906
assert.equal(merged.artifacts, configB.artifacts);
904907
});
905908
});

‎types/config.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare global {
1717
* The pre-normalization Lighthouse Config format.
1818
*/
1919
export interface Json {
20-
extends?: 'lighthouse:default' | string | boolean;
20+
extends?: 'lighthouse:default' | string;
2121
settings?: SharedFlagsSettings;
2222
passes?: PassJson[] | null;
2323
audits?: Config.AuditJson[] | null;

0 commit comments

Comments
 (0)
Please sign in to comment.