Nock-exec is a child_process.exec
mocking library for Node.js
Usage
In your test you can write:
var nockExec = require('nock-exec');
nockExec('myapp').err('some error').reply(0, 'This command was mocked');
This means that any call in the form
var exec = require('child_process').exec;
exec('myapp', function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
will produce this output:
stdout: This command was mocked
stderr: some error