Skip to content

Commit 57bcf43

Browse files
authored
feat(config): add extends lighthouse:full (#2557)
1 parent 7b2e404 commit 57bcf43

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

lighthouse-core/config/config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
const defaultConfigPath = './default.js';
99
const defaultConfig = require('./default.js');
10+
const fullConfig = require('./full-config.js');
1011

1112
const GatherRunner = require('../gather/gather-runner');
1213
const log = require('lighthouse-logger');
@@ -285,8 +286,12 @@ class Config {
285286
configJSON.audits = Array.from(inputConfig.audits);
286287
}
287288

288-
// Extend the default config if specified
289-
if (configJSON.extends) {
289+
// Extend the default or full config if specified
290+
if (configJSON.extends === 'lighthouse:full') {
291+
const explodedFullConfig = Config.extendConfigJSON(deepClone(defaultConfig),
292+
deepClone(fullConfig));
293+
configJSON = Config.extendConfigJSON(explodedFullConfig, configJSON);
294+
} else if (configJSON.extends) {
290295
configJSON = Config.extendConfigJSON(deepClone(defaultConfig), configJSON);
291296
}
292297

lighthouse-core/config/default.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ module.exports = {
136136
'dobetterweb/link-blocking-first-paint',
137137
'dobetterweb/no-document-write',
138138
'dobetterweb/no-mutation-events',
139-
// 'dobetterweb/no-old-flexbox',
140139
'dobetterweb/no-websql',
141140
'dobetterweb/notification-on-start',
142141
'dobetterweb/password-inputs-can-be-pasted-into',
@@ -294,7 +293,6 @@ module.exports = {
294293
{id: 'no-websql', weight: 1},
295294
{id: 'is-on-https', weight: 1},
296295
{id: 'uses-http2', weight: 1},
297-
// {id: 'no-old-flexbox', weight: 1},
298296
{id: 'uses-passive-event-listeners', weight: 1},
299297
{id: 'no-mutation-events', weight: 1},
300298
{id: 'no-document-write', weight: 1},

lighthouse-core/config/full-config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license Copyright 2017 Google Inc. All Rights Reserved.
3+
* 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
4+
* 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.
5+
*/
6+
'use strict';
7+
8+
module.exports = {
9+
extends: 'lighthouse:default',
10+
passes: [
11+
{
12+
passName: 'extraPass',
13+
gatherers: [
14+
'styles',
15+
]
16+
},
17+
],
18+
audits: [
19+
'dobetterweb/no-old-flexbox',
20+
],
21+
categories: {
22+
'best-practices': {
23+
audits: [
24+
{id: 'no-old-flexbox', weight: 1},
25+
]
26+
}
27+
},
28+
};

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,37 @@ describe('Config', () => {
436436
});
437437
});
438438

439+
it('extends the full config', () => {
440+
class CustomAudit extends Audit {
441+
static get meta() {
442+
return {
443+
name: 'custom-audit',
444+
category: 'none',
445+
description: 'none',
446+
helpText: 'none',
447+
requiredArtifacts: [],
448+
};
449+
}
450+
451+
static audit() {
452+
throw new Error('Unimplemented');
453+
}
454+
}
455+
456+
const config = new Config({
457+
extends: 'lighthouse:full',
458+
audits: [
459+
CustomAudit,
460+
],
461+
});
462+
463+
const auditNames = new Set(config.audits.map(audit => audit.meta.name));
464+
assert.ok(config, 'failed to generate config');
465+
assert.ok(auditNames.has('custom-audit'), 'did not include custom audit');
466+
assert.ok(auditNames.has('no-old-flexbox'), 'did not include full audits');
467+
assert.ok(auditNames.has('first-meaningful-paint'), 'did not include default audits');
468+
});
469+
439470
describe('artifact loading', () => {
440471
it('expands artifacts', () => {
441472
const config = new Config({

0 commit comments

Comments
 (0)