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

refactor(mockGit): modulization #36

Merged
merged 1 commit into from
May 19, 2016
Merged

refactor(mockGit): modulization #36

merged 1 commit into from
May 19, 2016

Conversation

stevemao
Copy link
Member

@stevemao stevemao commented May 7, 2016

https://github.com/stevemao/mock-git

The standalone module has a few improvements:

  1. It is async
  2. It uses temp folder for path which is better than cwd
  3. It also handles some potential edge cases

https://github.com/stevemao/mock-git

The standalone module has a few improvements:
1. It is async
2. It uses temp folder for path which is better than `cwd`
3. It also handles some potential edge cases
@bcoe
Copy link
Member

bcoe commented May 11, 2016

@stevemao @nexdrew love it.

@@ -94,36 +83,48 @@ describe('cli', function () {
describe('with mocked git', function () {
it('--sign signs the commit and tag', function () {
// mock git with file that writes args to gitcapture.log
mockGit('require("fs").appendFileSync("gitcapture.log", JSON.stringify(process.argv.splice(2)) + "\\n", "utf8")')
writePackageJson('1.0.0')
mockGit('require("fs").appendFileSync("gitcapture.log", JSON.stringify(process.argv.splice(2)) + "\\n")')
Copy link
Member

@bcoe bcoe May 13, 2016

Choose a reason for hiding this comment

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

@nexdrew @stevemao clever :) a couple thoughts about mockGit:

  • I wonder if the mocking library could be made more generic, as a tool for mocking an arbitrary bin in path (then you could instantiate one for git).
  • If we opt for the git-specific approach, I wonder if we could provide a few common "logic scripts" that would fit common use-cases that folks would run into while testing git.

¯_(ツ)_/¯

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if the mocking library could be made more generic, as a tool for mocking an arbitrary bin in path (then you could instantiate one for git).

I have created mock-bin and mock-git is depending on it.

I wonder if we could provide a few common "logic scripts"

There is an optional arg, command, you could specify. The edge case I mentioned is when your command is commit, it won't affect other commands such as push. Although it doesn't matter at the moment here.

@bcoe
Copy link
Member

bcoe commented May 13, 2016

@nexdrew I'm cool with landing this, if you sign off.

Curious about your thoughts on my comment though.

})

it('exits with error code if git commit fails', function () {
// mock git by throwing on attempt to commit
mockGit('if (process.argv[2] === "commit") { console.error("commit yourself"); process.exit(128); }')
writePackageJson('1.0.0')
mockGit('console.error("commit yourself"); process.exit(128);', 'commit')
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an example of using command. If we did use git push here, it shouldn't be mocked @bcoe

@nexdrew
Copy link
Member

nexdrew commented May 19, 2016

@bcoe @stevemao Cool, I like this. 👍

I do think it'd be neat to build some conveniences around mock-bin, like the ability to capture args and return/fetch them from the API, but I guess that could always be another module/package. ¯_(ツ)_/¯

Otherwise, nice work Steve!

@stevemao
Copy link
Member Author

Cool, thanks guys :)

@stevemao stevemao merged commit 013b145 into master May 19, 2016
@stevemao stevemao deleted the mock-git branch May 19, 2016 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants