# mock-bin

> Mock any executable binary

Latest version **2.0.0** (published 2017-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install mock-bin
pnpm add mock-bin
yarn add mock-bin
bun add mock-bin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2017-05-14 |
| First published | 2016-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Steve Mao |
| Maintainers | stevemao, tapppi |
| Keywords | mock, test, bin, binary, command, executable |

## Links

- npm: https://www.npmjs.com/package/mock-bin
- Repository: https://github.com/stevemao/mock-bin
- Homepage: https://github.com/stevemao/mock-bin#readme
- Issues: https://github.com/stevemao/mock-bin/issues
- npm.io page: https://npm.io/package/mock-bin

## Dependencies (5)

- [pify](https://npm.io/package/pify.md) ^2.3.0
- [shelljs](https://npm.io/package/shelljs.md) ^0.7.0
- [cmd-shim](https://npm.io/package/cmd-shim.md) ^2.0.2
- [temp-write](https://npm.io/package/temp-write.md) ^3.3.0
- [shebang-regex](https://npm.io/package/shebang-regex.md) ^2.0.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2017-05-14
- 1.0.1 — 2016-06-23
- 1.0.0 — 2016-05-07
- 0.0.0 — 2016-05-07

## README

# mock-bin [![Build Status: Linux](https://travis-ci.org/stevemao/mock-bin.svg?branch=master)](https://travis-ci.org/stevemao/mock-bin) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/76bg3fbqo2ox9s11/branch/master?svg=true)](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)

---
_Source: https://npm.io/package/mock-bin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
