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

Add tests for command "run" #821

Merged
merged 3 commits into from
Oct 28, 2016
Merged

Conversation

AlicanC
Copy link
Contributor

@AlicanC AlicanC commented Oct 12, 2016

Summary

In #809, suggested tests were these (twice, in straight and white-spaced paths):

  • yarn run test -- --help
  • yarn run test-help
  • yarn run jest -- --help

In this PR I test the internal run() command and (AFAIK) it is not responsible converting yarn run test -- --help to test --help so the part where -- --arg becomes --arg should not be covered.

What I cover is:

  1. run()ing a script in package.json.
  2. run()ing a binary in node_modules/.bin/.
  3. run()ing a binary in node_modules/.bin/ with a white-spaced path.
  4. run()ing a binary in node_modules/.bin/ with a single arg.

1, 2 and 4 was working on release. #663 fixed 3, but broke 4 and with #809 all tests pass.

There are more to add, but I want to be sure if I'm doing this right. I'd like to get this merged (if it is right) and add others in another PR when I have more time.

Please comment.

Test plan

(What should a test plan be for a test?)


test.concurrent('run should run binary', (): Promise<void> => {
return runRun({}, ['echo'], 'run-should-run-binary');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see what this is doing! If you do this, and add specs for the same thing but with spaces in the fixture directory name, that should have you covering the issue #633 intended to fix completely! 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, the rest should be just copy&paste. I just want to be sure that I am on the right path. Currently only "add", "install" and "self-update" commands are tested so there isn't much to use as an example.

Copy link
Contributor

Choose a reason for hiding this comment

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

Come to think of it, it could be reasonable to mock out child_process (used all the way over here) for these purposes, but I guess it depends if you want to actually integration test with the shell.

@AlicanC
Copy link
Contributor Author

AlicanC commented Oct 12, 2016

Updated PR and original post.

@AlicanC AlicanC changed the title WIP: Add tests for command "run" Add tests for command "run" Oct 12, 2016
@AlicanC AlicanC force-pushed the alicanc-run-tests branch 2 times, most recently from 95d34eb to 2d1cc8b Compare October 15, 2016 20:24
}

test.concurrent('run should run script', (): Promise<void> => {
return runRun({}, ['some-script'], 'run-should-run-script');
Copy link
Member

Choose a reason for hiding this comment

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

great job!
Usually tests should have something to expect, not just run and expect that it does not crash.
Can you add expectations that verify that the command has been executed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a way to do that, but instead I've added expectations for calling of executeLifecycleScript().

I think these tests should only verify that run() can call executeLifecycleScript() properly, then another test can verify if executeLifecycleScript() can do its job properly.

@bestander bestander merged commit 782fd84 into yarnpkg:master Oct 28, 2016
@bestander
Copy link
Member

Thanks @AlicanC!

bestander added a commit to bestander/yarn that referenced this pull request Oct 28, 2016
bestander added a commit that referenced this pull request Oct 28, 2016
@bestander
Copy link
Member

Hey @AlicanC, the CI failed with errors https://circleci.com/gh/yarnpkg/yarn/1806.
Could you rebase and send a new PR?

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.

3 participants