Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stevemao/mock-git
Mock any git command
https://github.com/stevemao/mock-git
bin binary git mock mocking test testing testing-tools tests
Last synced: 10 days ago
JSON representation
Mock any git command
- Host: GitHub
- URL: https://github.com/stevemao/mock-git
- Owner: stevemao
- License: mit
- Created: 2016-05-07T08:23:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-26T23:52:54.000Z (almost 5 years ago)
- Last Synced: 2024-10-19T20:00:07.140Z (19 days ago)
- Topics: bin, binary, git, mock, mocking, test, testing, testing-tools, tests
- Language: JavaScript
- Homepage:
- Size: 31.3 KB
- Stars: 11
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# mock-git [![Build Status: Linux](https://travis-ci.org/stevemao/mock-git.svg?branch=master)](https://travis-ci.org/stevemao/mock-git) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/76bg3fbqo2ox9s11/branch/master?svg=true)](https://ci.appveyor.com/project/stevemao/mock-git/branch/master)
> Mock any git command
Useful for mocking tests that run git command, especially to fake edge cases and increase test coverage.
## Install
```
$ npm install --save-dev mock-git
```## Usage
```js
const mockGit = require('mock-git');
const log = 'mocking git bla!';
const unmock = await mockGit(`console.log('${log}')`, 'bla');
let actual = shell.exec('git bla').stdout;
t.is(log + '\n', actual);actual = shell.exec('git').stdout;
t.not(log + '\n', actual);unmock();
actual = shell.exec('git bla').stdout;
t.not(log + '\n', actual);
```Checkout the [tests](./test.js) for more details
## API
### mockGit(js, [command])
Returns a promise which resolves with an unmock function.
##### js
Type: `string`
Nodejs code.
#### command
Type: `string`
EG: `'commit'`.
If omitted, it will mock the git binary.
## Related
- [mock-bin](https://github.com/stevemao/mock-bin) - Mock any executable binary
## License
MIT © [Steve Mao](https://github.com/stevemao)