-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Test bin command #1980
Test bin command #1980
Conversation
src/cli/commands/bin.js
Outdated
@@ -19,6 +19,6 @@ export function run( | |||
config.registries[RegistryYarn.registry].folder, | |||
'.bin', | |||
); | |||
console.log(binFolder); | |||
reporter.log(binFolder); |
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 will output an ansi code at the beginning of the line that resets the cursor to the start making it unsuitable for consumption via another tool.
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 ok, interesting. Is there a good way to test the console output of this command without using the reporter
?
__tests__/commands/bin.js
Outdated
|
||
const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'bin'); | ||
|
||
async function runBin( |
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.
Can you use the helper method that I cleaned up in #2007?
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.
Ok sure, had a pretty similar thought about this boilerplate code.
@hpurmann, what is left to get this merged? |
Thanks for having a look at this. Actually a few things are missing here:
|
|
The problem here is that I can't speficy a directory from where I'd like to simulate calling `bin`. Therefore, a test like that doesn't work.
|
@@ -71,6 +71,7 @@ | |||
"gulp-watch": "^4.3.5", | |||
"jest": "^19.0.2", | |||
"mock-stdin": "^0.3.0", | |||
"sinon": "^1.17.7", |
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 jest can spy on its own without sinon
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.
Ok, didn't know this. I'll change this. Can you give me a hint how to handle the problem described in 3.?
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.
Re 3, maybe you should not test for Path but rather test that a script from bin can be executed?
@hpurmann, are you blocked by something on this PR? |
No, currently just missing time. Will get back to it. |
Hey, @hpurmann, your contribution is very much welcome. |
Summary
This PR is a response to #1804
In the first step, I added a test for the existing behaviour. I was about to fix the bug @shnhrrsn reported. But then I noticed that none of yarns commands work in subdirectories. This is certainly a difference compared to
npm
. Is this intended?We could add logic to find the current package root. I did so locally by traversing the folders up and searching for a
package.json
, then taking this as thecwd
. It would add some complexity which could lead to other bugs. What do you think?And a minor thing: Do we want to tell the user when he uses too many arguments (like we do in
yarn why
) or do we want be consistent withnpm bin
and just work, no matter how many arguments got passed tobin
?