-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
cli: add --plugins flag to load from the command line #7407
Conversation
const getFlags = require('../../cli-flags').getFlags; | ||
|
||
describe('CLI run', function() { | ||
it('runLighthouse completes a LH round trip', () => { | ||
const url = 'chrome://version'; | ||
describe('LH round trip', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split this up as it seems like there are a few different things being tested (and channel
is about to be another check added to this)
|
||
it('returns results that match the saved results', () => { | ||
const {lhr} = passedResults; | ||
assert.equal(fileResults.audits.viewport.rawValue, false); | ||
|
||
// passed results match saved results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea why this is being checked this way, but going with it :)
assert.strictEqual(groupIds[groupIds.length - 1], 'lighthouse-plugin-simple-new-group'); | ||
}); | ||
|
||
it('should append and use plugin-prefixed groups', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jburger424 I split the should append audits and a group
in two because I was having trouble following it all in one :) Should be exactly the same functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this is cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since plugins isn't a setting (it's a top level field in the config), it can't go through our normal flags/settings pipeline and instead has to be yet another optional argument to run.runLighthouse() and the lighthouse() module interface.
I think we should avoid adding plumbing through lighthouse index/runLighthouse. AFAICT, plugins are purely a config concern that don't have any other impacts to core, so it's certainly possible to contain the impact to CLI and config.
What if instead, CLI could call into Config.mergePlugins
if the plugins CLI flag was set? It's already doing the work to figure out configJSON
based on a set of flags that affect the config, so adding one more conditional to check for plugins seems like a small price to pay for nuking all the other complexity to our entrypoints that would be introduced otherwise.
WDYT?
We could do this now ( |
I think we'll want node module users to be able to use this too, but that just made me realize I made this way too complicated (I think). We don't want it in |
Perfect 👍 |
ah, so much better |
|
||
fs.unlinkSync(filename); | ||
it('merged the plugin into the config', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is well beyond just stretching the "unit" part of "unit tests", but this check has trivial overhead and until we have a smoketest for plugins I'd like to leave this in
lighthouse-cli/test/cli/run-test.js
Outdated
@@ -19,42 +19,73 @@ const fastConfig = { | |||
}, | |||
}; | |||
|
|||
// Map plugin name to fixture since not actually installed in node_modules/. | |||
jest.mock('lighthouse-plugin-simple', () => { | |||
return require('../../../lighthouse-core/test/fixtures/config-plugins/lighthouse-plugin-simple'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.js
of the real file?
or we are making it work like a package so it's ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we are making it work like a package so it's ok?
I was making it like a package (I added a /
to make it clear it's a directory), but can also make it the js file if you'd rather
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, it's cool
}, | ||
}; | ||
const baseFlags = {configPath: configFixturePath}; | ||
const simplePlugin = 'lighthouse-plugin-simple'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could we go with PluginName
here? just easier to remember down below it's a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call
* @param {string=} configDir | ||
* @return {LH.Config.Json} | ||
*/ | ||
static mergePlugins(configJSON, configDir) { | ||
const pluginNames = configJSON.plugins; | ||
static mergePlugins(configJSON, flags, configDir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are like the only meaningful changes, right?
so clean ✨ 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are like the only meaningful changes, right?
yep, that's it! soooo much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, I also just realized this was the original plan all along, so at least we got back to it :)
so it seems ok to add this to the handful of special-cased flag/config mergings in config.js when we add support for the CLI flag.
Should make e.g. the recipe a lot clearer since you don't need a config file.
Old:
lighthouse --config-path=my-config.json ...
New:
lighthouse --plugins=lighthouse-plugin-preload-as ...
Two things:
--plugins
or--plugin
?--plugin
seems like it might be more natural (--plugin=lighthouse-plugin-preload-as
) and it's what e.g.eslint
does, but technically you can have multiple values (--plugin=plugin1 plugin2
),plugins
is the property name in the config, and we use the plural for other possibly single things, e.g.--only-categories
.Since(see below)plugins
isn't a setting (it's a top level field in the config), it can't go through our normal flags/settings pipeline and instead has to be yet another optional argument torun.runLighthouse()
and thelighthouse()
module interface. This is ugly enough that I almost don't want to do it, but we've already talked about switching to an options object for v5, so maybe it's fine for now?