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

core(runner): add custom folder support to -G/-A #4792

Merged
merged 5 commits into from
Mar 20, 2018
Merged

Conversation

paulirish
Copy link
Member

Enable this:

lighthouse -G=./cnn_artifacts http://cnn.com
...
lighthouse -A=./cnn_artifacts http://cnn.com

Path is resolved via pwd, but absolute paths are allowable, too.

@@ -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();
Copy link
Collaborator

@patrickhulce patrickhulce Mar 17, 2018

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

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 sgtm!

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

❤️it!

@@ -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)));
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

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

fun!

const flags = opts.flags;
if (flags.gatherMode) {
const path = Runner._getArtifactsPath(flags);
await Runner._saveArtifacts(artifacts, path);
Copy link
Member

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()

Copy link
Member Author

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?

Copy link
Member

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?

}

module.exports = Runner;


Copy link
Member

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',
Copy link
Member

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?


/**
* Get path to use for -G and -A modes. Defaults to $CWD/latest-run
* @param {*} flags
Copy link
Member

Choose a reason for hiding this comment

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

more specific type pls

Copy link
Member

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

const artifactsPath = '.tmp/test_artifacts';

after(() => {
const path = Runner._getArtifactsPath({auditMode: artifactsPath});
Copy link
Member

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

*/
static _getArtifactsPath(flags) {
// This enables usage like: -GA=./custom-folder
if (typeof flags.auditMode === 'string') return path.join(process.cwd(), flags.auditMode);
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 you want path.resolve? To handle absolute paths

@@ -36,17 +38,23 @@ describe('Runner', () => {
resetSpies();
});

describe('Gather Mode & Audit Mode', () => {
describe.only('Gather Mode & Audit Mode', () => {
Copy link
Member

Choose a reason for hiding this comment

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

remove

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});
Copy link
Member

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)

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 on the 🍏!

@paulirish paulirish merged commit 8b02a90 into master Mar 20, 2018
@paulirish paulirish deleted the customfoldersupport branch April 27, 2018 21:51
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.

4 participants