Mock any executable binary
Useful for mocking tests that run executable binary, especially to fake edge cases and increase test coverage.
$ npm install --save-dev mock-bin
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);
Returns a promise which resolves with an unmock()
function.
Type: string
EG: 'git'
.
Type: string
Shebang or environment
EG: '#!/usr/bin/env node'
or 'bash'
Type: string
The actual code you want to execute.
- mock-git - Mock any git command
MIT © Steve Mao