mock-bin

2.0.0 • Public • Published

mock-bin Build Status: Linux Build Status: Windows

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

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

License

MIT © Steve Mao

Package Sidebar

Install

npm i mock-bin

Weekly Downloads

21

Version

2.0.0

License

MIT

Last publish

Collaborators

  • tapppi
  • stevemao