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

feat: support category and audit whitelisting #1988

Merged
merged 4 commits into from
Apr 13, 2017

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Apr 10, 2017

addresses burndown items for I/O #1937

usage to run just TTI, PSI, and the PWA audits

{
  settings: {
     onlyAudits: ["time-to-interactive", "speed-index-metric"],
     onlyCategories: ["pwa"]
  }
}

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

this looks like it's going to be great.

General things:

  • I've seen the : format used more for referencing special values (e.g. 'lighthouse:default') rather than just giving the type of thing. Does it make more sense to have onlyCategories and onlyAudits properties instead of the less explicit only prop?
  • We need to be clear about the hierarchy here (but where?). It's a little confusing that it's one or the other, category or audit, but not both. e.g. if you say only: ["audit:service-worker", "category:pwa"], the category wins and you run all of the pwa category, not just the service-worker audit within it
  • definitely want warnings to the user about things like trying to do only an audit when you're also doing only the category that includes it (see above) and unknown audit/category names to catch misspellings and the like.
  • tests! :)

@@ -344,14 +356,21 @@ class Config {
* Filter out any unrequested categories from the categories object.
* @param {!Object<string, {audits: !Array<{id: string}>}>} categories
* @param {Array<string>=} categoryIds
* @param {Array<string>=} auditIds
Copy link
Member

Choose a reason for hiding this comment

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

looks like we missed this before and these should be {!Array<string>=}

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

@@ -344,14 +356,21 @@ class Config {
* Filter out any unrequested categories from the categories object.
Copy link
Member

Choose a reason for hiding this comment

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

need to update

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

"dobetterweb/tags-blocking-first-paint",
"dobetterweb/optimized-images"
]
"extends": "lighthouse:default",
Copy link
Member

Choose a reason for hiding this comment

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

this is a lie depending on the current check just being truthiness of extends, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup

@patrickhulce
Copy link
Collaborator Author

Does it make more sense to have onlyCategories and onlyAudits properties instead of the less explicit only prop?

I'm fine with this too, but with the goal of having all config settings map to CLI flags that seemed slightly polluting. WFM if others agree to split though.

We need to be clear about the hierarchy here (but where?)

Agreed, this keeps it simple by being 100% additive so if it's listed in only it's guaranteed to run, added warnings too.

@paulirish
Copy link
Member

Does it make more sense to have onlyCategories and onlyAudits properties instead of the less explicit only prop?

I'm fine with both and consider them equivalent from an ergonomics POV.

@patrickhulce
Copy link
Collaborator Author

this waiting on anything else? PTAL :)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

almost :)

const categories = {};

// warn if the category is not found
categoryIds.forEach(category => {
Copy link
Member

Choose a reason for hiding this comment

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

category -> categoryId

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

});

// warn if the audit is not found in a category
auditIds.forEach(audit => {
Copy link
Member

Choose a reason for hiding this comment

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

audit -> auditId

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

// warn if the category is not found
categoryIds.forEach(category => {
if (!oldCategories[category]) {
log.warn('config', `unrecognized category: ${category}`);
Copy link
Member

Choose a reason for hiding this comment

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

need a clearer way of saying this, since users will see it without context. Not sure what would be good though... maybe just unrecognized category in `onlyCategories`: ${category}?

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

});

if (!foundCategory) {
log.warn('config', `unrecognized audit: ${audit}`);
Copy link
Member

Choose a reason for hiding this comment

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

same for this

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

}

if (categoryIds.includes(foundCategory)) {
log.warn('config', `${foundCategory} category already includes "${audit}"`);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how to word this one either. ${audit} in `onlyAudits` already included by `onlyCategories` entry ${foundCategory}? Or something less terrible :)

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

});

assert.ok(config.audits.length, 'inherited audits by extension');
assert.ok(config.audits.length < origConfig.audits.length, 'filtered out audits');
Copy link
Member

Choose a reason for hiding this comment

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

could you do origConfig.categories.performance.audits.length + 1? Seems future compatible

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 auditCount = Object.keys(selectedCategory.audits).length;
assert.equal(config.passes.length, 3, 'incorrect # of passes');
assert.equal(config.audits.length, auditCount, 'audit filtering failed');
});
Copy link
Member

Choose a reason for hiding this comment

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

tests for the new warnings would be good, too. log.events.addListener('warning', callback) can be an easy way to do that rather than going to the trouble of overriding log, like is done elsewhere in that file

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

@@ -99,7 +99,7 @@ function filterOutArtifacts(result) {
* @return {!Promise}
*/
window.runLighthouseForConnection = function(connection, url, options, categoryIDs) {
const newConfig = Config.generateNewConfigOfCategories(defaultConfig, categoryIDs);
const newConfig = Config.generateNewFilteredConfig(defaultConfig, categoryIDs);
Copy link
Member

Choose a reason for hiding this comment

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

should we switch this to just

const newConfig = {
  "extends": "lighthouse:default",
  "settings": {
    "onlyCategories": categoryIDs
  }
};

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

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

sweet, LGTM!

@brendankenny brendankenny merged commit 16b0b04 into master Apr 13, 2017
@brendankenny brendankenny deleted the cat_audit_whitelisting branch April 13, 2017 19:44
@paulirish paulirish mentioned this pull request Apr 13, 2017
52 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants