-
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
core(runner): add custom folder support to -G/-A #4792
Conversation
lighthouse-core/runner.js
Outdated
@@ -144,18 +143,20 @@ class Runner { | |||
return GatherRunner.run(opts.config.passes, opts).then(artifacts => { | |||
const flags = opts.flags; | |||
const shouldSave = flags.gatherMode; | |||
const p = shouldSave ? Runner._saveArtifacts(artifacts): Promise.resolve(); | |||
const path = Runner._getArtifactsPath(flags); | |||
const p = shouldSave ? Runner._saveArtifacts(artifacts, path): Promise.resolve(); |
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 we just bumped our ecmaVersion
how about some async/await
to kill this dumb so-node-6 p
variable :D
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.
👍 sgtm!
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.
done
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.
❤️it!
1543d58
to
1ba7d5a
Compare
lighthouse-core/runner.js
Outdated
@@ -68,7 +66,7 @@ class Runner { | |||
// Gather phase | |||
// Either load saved artifacts off disk, from config, or get from the browser | |||
if (opts.flags.auditMode && !opts.flags.gatherMode) { | |||
run = run.then(_ => Runner._loadArtifactsFromDisk()); | |||
run = run.then(_ => Runner._loadArtifactsFromDisk(Runner._getArtifactsPath(opts.flags))); |
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: pull into a var
@@ -135,27 +134,30 @@ class Runner { | |||
* @param {*} connection | |||
* @return {!Promise<!Artifacts>} | |||
*/ | |||
static _gatherArtifactsFromBrowser(opts, connection) { | |||
static async _gatherArtifactsFromBrowser(opts, connection) { |
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.
fun!
lighthouse-core/runner.js
Outdated
const flags = opts.flags; | ||
if (flags.gatherMode) { | ||
const path = Runner._getArtifactsPath(flags); | ||
await Runner._saveArtifacts(artifacts, path); |
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.
inherited, but this would probably make more sense back up in run()
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.
true. but how about we do that when runner goes async/await?
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.
Well you're already refactoring it to async/await so you brought it on yourself :P
It doesn't look like there are any tests of this method (since it's private, yay), so should pop into the surrounding else branch with no side effects?
lighthouse-core/runner.js
Outdated
} | ||
|
||
module.exports = Runner; | ||
|
||
|
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.
extra line?
@@ -111,7 +111,7 @@ function getFlags(manualArgv) { | |||
'disable-storage-reset', 'disable-device-emulation', 'disable-cpu-throttling', | |||
'disable-network-throttling', 'save-assets', 'list-all-audits', | |||
'list-trace-categories', 'perf', 'view', 'verbose', 'quiet', 'help', | |||
'gather-mode', 'audit-mode', 'mixed-content', | |||
'mixed-content', |
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.
mention path option in description?
lighthouse-core/runner.js
Outdated
|
||
/** | ||
* Get path to use for -G and -A modes. Defaults to $CWD/latest-run | ||
* @param {*} flags |
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.
more specific type pls
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.
also need to update externs.d.ts
lighthouse-core/test/runner-test.js
Outdated
const artifactsPath = '.tmp/test_artifacts'; | ||
|
||
after(() => { | ||
const path = Runner._getArtifactsPath({auditMode: artifactsPath}); |
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.
test to verify that artifacts do exist at that location? And preferably since Runner._getArtifactsPath
is private no need to call it for rimraf if verified that runner is saving at that location
9ac25f4
to
56c2a2b
Compare
56c2a2b
to
0589b8f
Compare
lighthouse-core/runner.js
Outdated
*/ | ||
static _getArtifactsPath(flags) { | ||
// This enables usage like: -GA=./custom-folder | ||
if (typeof flags.auditMode === 'string') return path.join(process.cwd(), flags.auditMode); |
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.
I think you want path.resolve
? To handle absolute paths
lighthouse-core/test/runner-test.js
Outdated
@@ -36,17 +38,23 @@ describe('Runner', () => { | |||
resetSpies(); | |||
}); | |||
|
|||
describe('Gather Mode & Audit Mode', () => { | |||
describe.only('Gather Mode & Audit Mode', () => { |
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.
remove
lighthouse-core/test/runner-test.js
Outdated
const url = 'https://example.com'; | ||
const generateConfig = _ => new Config({ | ||
passes: [{ | ||
gatherers: ['viewport-dimensions'], | ||
}], | ||
audits: ['content-width'], | ||
}); | ||
const artifactsPath = '.tmp/test_artifacts'; | ||
const resolvedPath = Runner._getArtifactsPath({auditMode: artifactsPath}); |
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 the expected behavior is that we support a path relative to cwd
, I think we want an impl independent of the thing itself to test it (e.g. const resolvedPath = path.resolve(process.cwd(), artifactsPath)
or whatever works from this file)
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.
LGTM on the 🍏!
Enable this:
Path is resolved via pwd, but absolute paths are allowable, too.