-
Notifications
You must be signed in to change notification settings - Fork 798
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
Conversation
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
@@ -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")') |
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.
@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.
¯_(ツ)_/¯
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 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.
@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') |
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 is an example of using command
. If we did use git push
here, it shouldn't be mocked @bcoe
Cool, thanks guys :) |
https://github.com/stevemao/mock-git
The standalone module has a few improvements:
cwd