Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only record a trace if needed by an audit #2117

Merged
merged 4 commits into from
May 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,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 @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove listener when finished?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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