https://github.com/stevemao/mock-bin
Mock any executable binary
https://github.com/stevemao/mock-bin
bin binary mock mocking shebang test testing testing-tools tests
Last synced: 4 months ago
JSON representation
Mock any executable binary
- Host: GitHub
- URL: https://github.com/stevemao/mock-bin
- Owner: stevemao
- License: mit
- Created: 2016-05-07T06:02:57.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-18T05:58:02.000Z (over 7 years ago)
- Last Synced: 2025-01-13T20:52:28.476Z (4 months ago)
- Topics: bin, binary, mock, mocking, shebang, test, testing, testing-tools, tests
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 12
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# mock-bin [](https://travis-ci.org/stevemao/mock-bin) [](https://ci.appveyor.com/project/stevemao/mock-bin/branch/master)
> Mock any executable binary
Useful for mocking tests that run executable binary, especially to fake edge cases and increase test coverage.
## Install
```
$ npm install --save-dev mock-bin
```## Usage
```js
const mockBin = require('mock-bin');
const log = 'mocking git!';
const unmock = await mockBin('git', 'node', `console.log('${log}')`);
let actual = shell.exec('git').stdout;
t.is(log + '\n', actual);unmock();
actual = shell.exec('git').stdout;
t.not(log + '\n', actual);
```## API
### mockBin(bin, shebang, code)
Returns a promise which resolves with an `unmock()` function.
#### bin
Type: `string`
EG: `'git'`.
#### shebang
Type: `string`
Shebang or environment
EG: `'#!/usr/bin/env node'` or `'bash'`
##### code
Type: `string`
The actual code you want to execute.
## Related
- [mock-git](https://github.com/stevemao/mock-git) - Mock any git command
## License
MIT © [Steve Mao](https://github.com/stevemao)