- Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
|
I took #1393 (comment) to read us having consensus on only forwarding Does it make sense to pass AVA's command line arguments? Should we instead look for a |
👍
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.
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. |
| @kevva You need to handle the color option in the worker, by setting the Chalk singleton |
| Is this going to be merged anytime soon? Please, I really need to pass some arguments to my tests :) |
| @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. |
| @novemberborn, I'm going to address your comments soon :). |
| Sorry @duartealexf, @kevva is still on the case :) |
| Ok, so I've changed the PR to only forward the Should we include support for different levels as in #1455 too? |
color flag to worker if supplied by user | Some tests are failing now because they relied upon checking the |
novemberborn left a comment
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.
Should we include support for different levels as in #1455 too?
That'd be good, but we can do it as a follow-up.
| const args = [JSON.stringify(opts)]; | ||
| | ||
| if (hasFlag('--color') || hasFlag('--no-color')) { | ||
| args.push(`--color=${opts.color}`); |
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.
Shouldn't this forward --no-color if specified? And forward --color exactly as it was received?
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.
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.
lib/test-worker.js Outdated
| const serializeError = require('./serialize-error'); | ||
| | ||
| // Initialize color support | ||
| chalk.enabled = typeof opts.color === 'boolean' && opts.color; |
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.
opts.color already is a boolean, courtesy of
Line 78 in 1df502d
| color: 'color' in conf ? conf.color : require('supports-color') !== false, |
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.
Yeah, I did this just to make this test pass since it doesn't run the CLI.
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.
That's an odd test. Just remove it 😄
novemberborn left a comment
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.
👍 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`); |
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.
Although XO doesn't complain, I'd have expected a regular string here, not a templated one.
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.
Oh, escaped my eyes.
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 |
Nice! So we could do the following:
(I'm not sure now whether AVA configures @kevva does this strike the right balance between forwarding color mode by default and not behaving against the user's intention when And do we need to handle |
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.