Skip to content

Only forward color flag to worker if supplied by user #1401

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

Closed
wants to merge 4 commits into from

Conversation

kevva
Copy link
Contributor

@kevva kevva commented Jun 4, 2017

Fixes #1393.

Didn't bother to add tests since we already have ones in place for this here. Also removed a test that is moot now.

@novemberborn
Copy link
Member

process.argv is still a little different from what users might expect. Should we splice out the options?

I took #1393 (comment) to read us having consensus on only forwarding --color and --no-color. Previously we've argued that users should use environment variables to pass runtime values to their tests. These flags don't sit well with that though.

Does it make sense to pass AVA's command line arguments? Should we instead look for a -- argument and forward everything after that? But then does that imply users need to do ava --color -- --color if they want colors from AVA and whatever code runs in their tests? OTOH that would make it possible to do ava --color -- --no-color.

@sindresorhus?

@sindresorhus
Copy link
Member

Should we splice out the options?

👍

I took #1393 (comment) to read us having consensus on only forwarding --color and --no-color. Previously we've argued that users should use environment variables to pass runtime values to their tests. These flags don't sit well with that though.

Yes, we should forward them if they're specified by the user. It's an exception since the flags apply to both us and other modules. ava --color -- --color would be super weird. I do not want that.

OTOH that would make it possible to do ava --color -- --no-color.

I don't see why you would want to do that. Colors is a binary thing. Either you want them or you don't. I don't think we should complicate it more.

@sindresorhus
Copy link
Member

@kevva You need to handle the color option in the worker, by setting the Chalk singleton .enabled property to the same value as the .enabled property of Chalk in the CLI process. So the automatic color support is brought into the child worker, which defaults to no colors always because it's not a TTY.

@duartealexf
Copy link

Is this going to be merged anytime soon? Please, I really need to pass some arguments to my tests :)

@novemberborn
Copy link
Member

@duartealexf the PR is not ready yet. If you could take @kevva's commit and iterate on it in a new PR then we could get it to a state where we can land it. I'm sure he won't mind.

@kevva
Copy link
Contributor Author

kevva commented Jul 13, 2017

@novemberborn, I'm going to address your comments soon :).

@novemberborn
Copy link
Member

Sorry @duartealexf, @kevva is still on the case :)

@kevva
Copy link
Contributor Author

kevva commented Sep 13, 2017

Ok, so I've changed the PR to only forward the color/no-color flag if it's set, and I'm also setting chalk.enabled in the worker.

Should we include support for different levels as in #1455 too?

@kevva kevva changed the title Run workers with user supplied command line arguments Only forward color flag to worker if supplied by user Sep 13, 2017
@kevva
Copy link
Contributor Author

kevva commented Sep 13, 2017

Some tests are failing now because they relied upon checking the ava options forwarded as arguments before.

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

Should we include support for different levels as in #1455 too?

That'd be good, but we can do it as a follow-up.

lib/fork.js Outdated
const args = [JSON.stringify(opts)];

if (hasFlag('--color') || hasFlag('--no-color')) {
args.push(`--color=${opts.color}`);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this forward --no-color if specified? And forward --color exactly as it was received?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To forward them exactly like they were received requires some sort of parsing. We can forward --no-color instead of --color=false if it was specified though.

@@ -27,6 +27,9 @@ globals.options = opts;

const serializeError = require('./serialize-error');

// Initialize color support
chalk.enabled = typeof opts.color === 'boolean' && opts.color;
Copy link
Member

Choose a reason for hiding this comment

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

opts.color already is a boolean, courtesy of

ava/lib/cli.js

Line 78 in 1df502d

color: 'color' in conf ? conf.color : require('supports-color') !== false,
.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I did this just to make this test pass since it doesn't run the CLI.

Copy link
Member

Choose a reason for hiding this comment

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

That's an odd test. Just remove it 😄

@novemberborn novemberborn mentioned this pull request Sep 17, 2017
Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

👍 on passing --no-color as is.

I can't figure out what to do with --color, and I'm continually confused about it 😭

My take, if --color is set, it should be forwarded in exactly the same way. If it's not set, it shouldn't be forwarded.

But then how do we forward the actual color support to the workers? Do we inject it into chalk / support-color? Or really should we always set --color regardless of how AVA is called (unless of course --no-color was used)?

I think I'm fine with doing that, but it goes against the idea of AVA forwarding arguments as-is…

lib/fork.js Outdated
}

if (hasFlag('--no-color')) {
args.push(`--no-color`);
Copy link
Member

Choose a reason for hiding this comment

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

Although XO doesn't complain, I'd have expected a regular string here, not a templated one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, escaped my eyes.

@kevva
Copy link
Contributor Author

kevva commented Sep 24, 2017

My take, if --color is set, it should be forwarded in exactly the same way. If it's not set, it shouldn't be forwarded.

Reason I didn't implement it that way is because it would've required some sort of command line arguments parsing, and it wouldn't look too good using meow in there. I extracted the command line parsing out of meow though, and created an option that I think would fix this use case https://github.com/kevva/argvments#any.

@novemberborn
Copy link
Member

Reason I didn't implement it that way is because it would've required some sort of command line arguments parsing, and it wouldn't look too good using meow in there. I extracted the command line parsing out of meow though, and created an option that I think would fix this use case kevva/argvments#any.

Nice! So we could do the following:

No flags --color --color=mode --no-color
Set flag on worker process No Yes, as is Yes, as is Yes, as is
AVA configures chalk directly Yes, with supported mode from main process Yes, with supported mode from main process No No

(I'm not sure now whether AVA configures chalk or another package.)

@kevva does this strike the right balance between forwarding color mode by default and not behaving against the user's intention when --color or --no-color are provided?

And do we need to handle FORCE_COLOR environment variables?

@novemberborn
Copy link
Member

@kevva any thoughts on my last comment?

@nowells does my proposal satisfy your concerns raised in #1455?

@novemberborn
Copy link
Member

#1700 clears up what arguments are exposed to the test worker. Let's discuss the specifics around configuring color in #1701.

@sindresorhus sindresorhus deleted the remove-flags branch February 13, 2018 07:14
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