Skip to content

Commit

Permalink
feat(config): add extends lighthouse:full (#2557)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored Jun 29, 2017
1 parent 7b2e404 commit 57bcf43
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const defaultConfigPath = './default.js';
const defaultConfig = require('./default.js');
const fullConfig = require('./full-config.js');

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

// Extend the default config if specified
if (configJSON.extends) {
// Extend the default or full config if specified
if (configJSON.extends === 'lighthouse:full') {
const explodedFullConfig = Config.extendConfigJSON(deepClone(defaultConfig),
deepClone(fullConfig));
configJSON = Config.extendConfigJSON(explodedFullConfig, configJSON);
} else if (configJSON.extends) {
configJSON = Config.extendConfigJSON(deepClone(defaultConfig), configJSON);
}

Expand Down
2 changes: 0 additions & 2 deletions lighthouse-core/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ module.exports = {
'dobetterweb/link-blocking-first-paint',
'dobetterweb/no-document-write',
'dobetterweb/no-mutation-events',
// 'dobetterweb/no-old-flexbox',
'dobetterweb/no-websql',
'dobetterweb/notification-on-start',
'dobetterweb/password-inputs-can-be-pasted-into',
Expand Down Expand Up @@ -294,7 +293,6 @@ module.exports = {
{id: 'no-websql', weight: 1},
{id: 'is-on-https', weight: 1},
{id: 'uses-http2', weight: 1},
// {id: 'no-old-flexbox', weight: 1},
{id: 'uses-passive-event-listeners', weight: 1},
{id: 'no-mutation-events', weight: 1},
{id: 'no-document-write', weight: 1},
Expand Down
28 changes: 28 additions & 0 deletions lighthouse-core/config/full-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @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',
passes: [
{
passName: 'extraPass',
gatherers: [
'styles',
]
},
],
audits: [
'dobetterweb/no-old-flexbox',
],
categories: {
'best-practices': {
audits: [
{id: 'no-old-flexbox', weight: 1},
]
}
},
};
31 changes: 31 additions & 0 deletions lighthouse-core/test/config/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,37 @@ describe('Config', () => {
});
});

it('extends the full config', () => {
class CustomAudit extends Audit {
static get meta() {
return {
name: 'custom-audit',
category: 'none',
description: 'none',
helpText: 'none',
requiredArtifacts: [],
};
}

static audit() {
throw new Error('Unimplemented');
}
}

const config = new Config({
extends: 'lighthouse:full',
audits: [
CustomAudit,
],
});

const auditNames = new Set(config.audits.map(audit => audit.meta.name));
assert.ok(config, 'failed to generate config');
assert.ok(auditNames.has('custom-audit'), 'did not include custom audit');
assert.ok(auditNames.has('no-old-flexbox'), 'did not include full audits');
assert.ok(auditNames.has('first-meaningful-paint'), 'did not include default audits');
});

describe('artifact loading', () => {
it('expands artifacts', () => {
const config = new Config({
Expand Down

0 comments on commit 57bcf43

Please sign in to comment.