Skip to content

Commit

Permalink
fix: only record a trace if needed by an audit (#2117)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed May 3, 2017
1 parent cb06adb commit ff21a33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,22 @@ class Config {
* @return {!Object} fresh passes object
*/
static generatePassesNeededByGatherers(oldPasses, requiredGatherers) {
const auditsNeedTrace = requiredGatherers.has('traces');
const passes = JSON.parse(JSON.stringify(oldPasses));
const filteredPasses = passes.map(pass => {
// remove any unncessary gatherers from within the passes
pass.gatherers = pass.gatherers.filter(gathererName => {
gathererName = GatherRunner.getGathererClass(gathererName).name;
return requiredGatherers.has(gathererName);
});

// disable the trace if no audit requires a trace
if (pass.recordTrace && !auditsNeedTrace) {
const passName = pass.passName || 'unknown pass';
log.warn('config', `Trace not requested by an audit, dropping trace in ${passName}`);
pass.recordTrace = false;
}

return pass;
}).filter(pass => {
// remove any passes lacking concrete gatherers, unless they are dependent on the trace
Expand Down
21 changes: 20 additions & 1 deletion lighthouse-core/test/config/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,31 @@ describe('Config', () => {

assert.ok(config.audits.length, 3);
assert.equal(config.passes.length, 2);
assert.ok(config.passes[0].recordTrace, 'preserves recordTrace pass');
assert.ok(!config.categories['unused-category'], 'removes unused categories');
assert.equal(config.categories['needed-category'].audits.length, 2);
assert.equal(config.categories['other-category'].audits.length, 1);
});

it('filtering works with extension', () => {
it('filtering filters out traces when not needed', () => {
const warnings = [];
const saveWarning = evt => warnings.push(evt);
log.events.addListener('warning', saveWarning);
const config = new Config({
extends: true,
settings: {
onlyCategories: ['accessibility'],
},
});

log.events.removeListener('warning', saveWarning);
assert.ok(config.audits.length, 'inherited audits by extension');
assert.equal(config.passes.length, 1, 'filtered out passes');
assert.equal(warnings.length, 1, 'warned about dropping trace');
assert.equal(config.passes[0].recordTrace, false, 'turns off tracing if not needed');
});

it('filters works with extension', () => {
const config = new Config({
extends: true,
settings: {
Expand Down

0 comments on commit ff21a33

Please sign in to comment.