diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index 41159dd46025..a25c51bedd1b 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -482,6 +482,7 @@ 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 @@ -489,6 +490,14 @@ class Config { 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 diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index 6c5e6571d123..2a93d5dc82b8 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -330,12 +330,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: {