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

refactor(aggregations): switch usage of aggregations to categories #1935

Merged
merged 7 commits into from
Apr 10, 2017

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Mar 29, 2017

replaces other major spot that needed aggregations

Paves the way for...

  • complete removal of aggregations from the config
  • addition of only setting in config to specify specific categories/audits to run

@paulirish paulirish mentioned this pull request Mar 30, 2017
52 tasks
@patrickhulce
Copy link
Collaborator Author

MC 🔨

@patrickhulce
Copy link
Collaborator Author

◀️ 🐿 🗻

@patrickhulce
Copy link
Collaborator Author

there's only so much more cryptic my emoji messages can get so PTAL :)

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

This PR currently does break the --perf config. I don't think that was intentional, was it?

image
image

@patrickhulce
Copy link
Collaborator Author

🤦‍♂️ doh! it doesn't matter how many times this happens, I can't ever remember that there's a perf config...

@brendankenny
Copy link
Member

brendankenny commented Apr 3, 2017

if only there were some automated way to get a machine to check if it's working.... :P

@patrickhulce
Copy link
Collaborator Author

if only there was some automated way to get a machine to check if it's working.... :P

hey I proposed adding to smoke and paul vetoed!

fixed

@brendankenny
Copy link
Member

the :P wasn't aimed at you :)

@paulirish
Copy link
Member

FYI The new perf smoketest PR (#1957) wouldn't actually catch the above bug, as the JSON results are fine.. The failure was more on the reportGenerator side.

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.

looking good. Lots of comments but most are about jsdocs :)

const config = JSON.parse(JSON.stringify(oldConfig));
// 1. Filter to just the chosen aggregations
config.aggregations = config.aggregations.filter(agg => aggregationIDs.includes(agg.id));
config = Object.assign({}, config);
Copy link
Member

Choose a reason for hiding this comment

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

do we need to drop the JSON.parse(JSON.stringify())? If this is still just for the extension/devtools we're never going to have a live gatherer or audit class.

As hacky as it looks, until we have a proper deep clone utility it does ensure we don't have to audit all the methods this function calls (and you don't have to keep a copy of default.js open for reference to make sure every part is properly Object.assign()ed); we know the code can't modify the original even if it wanted to

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dislike the idea of random parts of config not supporting a consistent feature set a little more than being careful about mutation, but I'll revert for now

Copy link
Member

Choose a reason for hiding this comment

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

I dislike the idea of random parts of config not supporting a consistent feature set a little more than being careful about mutation

yeah, I agree. I was thinking more of future changes to the config format and having to reverify this invariant every time. e.g. we add some object on the audit objects in the future and in that PR we forget to verify that we Object.assign() at that level as well, and then (maybe in some future PR after that) the report generator or whatever augments those audit objects, and then we have those extra properties on subsequent uses of the default config in the extension/tests.

Part of that is inevitable due to require()'s behavior, and maybe we should only be loading config files with fs.readFile(), but regardless it's technical debt which we noted we had when we first wrote JSON.parse(JSON.stringify()), so we really should have come up with a better solution before now :S

* @return {Object} new config
*/
static generateNewConfigOfAggregations(oldConfig, aggregationIDs) {
* @param {!Object} config
Copy link
Member

Choose a reason for hiding this comment

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

keep the function and param descriptions?

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

* @param {!Array<string>} categoryIds
* @return {!Object}
*/
static generateNewConfigOfCategories(config, categoryIds) {
Copy link
Member

Choose a reason for hiding this comment

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

I think I personally prefer the old way of differentiating between the parameter passed in and the config being operated on with different variable names, but maybe there's an argument I'm missing. It seems like you lose a clear definition point, especially because you lose the constness in this case

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

id: agg.id
}));
/**
* @param {!Object<{audits: !Array<{id: string}>}>} categories
Copy link
Member

Choose a reason for hiding this comment

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

learned recently that, from the Closure Compiler side of things, at least, we really should be adding the string for the object key type in these: @param {!Object<string, {audits: !Array<{id: string}>}>}, otherwise you don't get the parameterized type checking on the entire parameter. Unfortunate but not the worst thing ever

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you mean all this time you've misled us!? :P haha will do

Copy link
Member

Choose a reason for hiding this comment

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

you mean all this time you've misled us!?

I know! Also, it's dumb that it doesn't default to string cause that's what you get no matter what you use anyways

* @param {!Object<{audits: !Array<{id: string}>}>} categories
* @param {Array<string>=} categoryIds
* @param {Array<string>=} auditIds
* @return {!Object<{audits: !Array<{id: string}>}>}
Copy link
Member

Choose a reason for hiding this comment

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

!Object<string, {audits: !Array<{id: 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

@@ -61,6 +61,30 @@ class ReportGeneratorV2 {
}

/**
* Convert categories into old-school aggregations for old HTML report compat.
* @param {!Array<!Object>} categories
Copy link
Member

Choose a reason for hiding this comment

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

!Array<{name: string, description: string, id: string, score: number, audits: !Array}>? :)

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 haveName = aggs.every(agg => agg.name.length);
const haveID = aggs.every(agg => agg.id.length);
assert.equal(haveName === haveID === true, true, 'they dont have IDs and names');
const categories = Config.getCategories(defaultConfig);
Copy link
Member

Choose a reason for hiding this comment

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

we could maybe move the JSON.parse(JSON.stringify(defaultConfig)) to a before() to make it more consistent per test?

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 origConfig = JSON.parse(JSON.stringify(defaultConfig));
Config.generateNewConfigOfAggregations(defaultConfig, aggregationIDs);
assert.deepStrictEqual(origConfig, defaultConfig, 'Original config mutated');
const origConfig = Object.freeze(JSON.parse(JSON.stringify(defaultConfig)));
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 do a deep freeze if we do the test this way, e.g. setting origConfig.categories.pwa = 5 wouldn't throw here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted

describe('generateConfigOfAggregations', () => {
const aggregationIDs = ['perf'];
describe('generateConfigOfCategories', () => {
const categoryIds = ['performance'];
Copy link
Member

Choose a reason for hiding this comment

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

nit: inheriting this, but maybe just inline this in the three tests that use it? doesn't seem helpful to have on its own

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

@@ -155,16 +155,16 @@ function onGenerateReportButtonClick(background, selectedAggregations) {

/**
* Generates a document fragment containing a list of checkboxes and labels
* for the aggregation categories.
* for the category categories.
Copy link
Member

Choose a reason for hiding this comment

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

delete 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

@patrickhulce patrickhulce force-pushed the switch_extension_to_categories branch from 017d74a to b7d46ba Compare April 5, 2017 16:29
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.

LGTM!

👋 aggregations

@brendankenny
Copy link
Member

brendankenny commented Apr 6, 2017

arg, sorry, I thought I caught any potential conflicts with #1964 but looks like I failed. Just score -> overallScore, I think.

@paulirish do you want to take a look since you were in the filtering/config generation code last?

Config.generateNewConfigOfAggregations(defaultConfig, aggregationIDs);
assert.deepStrictEqual(origConfig, defaultConfig, 'Original config mutated');
const configCopy = JSON.parse(JSON.stringify(origConfig));
Config.generateNewConfigOfCategories(configCopy, ['performance']);
Copy link
Member

Choose a reason for hiding this comment

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

just as an FYI, the rename of "perf" to "performance" will break any saved checkboxes people have in audits 2.0.
(that's totally fine with me at this stage, but something to keep in mind going forward)

Copy link
Member

Choose a reason for hiding this comment

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

failure mode will be if they have it unchecked it will now be checked, right? We'll definitely want to be additive only in the future, especially once your checkboxes in devtools are persisted

Copy link
Member

Choose a reason for hiding this comment

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

yes correct. "break" very gently. :)

@brendankenny
Copy link
Member

@patrickhulce going to rebase?

@patrickhulce
Copy link
Collaborator Author

Oh yep, sorry!

@patrickhulce patrickhulce merged commit e475bdb into master Apr 10, 2017
@patrickhulce patrickhulce deleted the switch_extension_to_categories branch April 10, 2017 18:50
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.

None yet

3 participants