Skip to content

NodeJS mock module around the child_process.exec function inspired by nock

Notifications You must be signed in to change notification settings

vlad-c/nock-exec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nock-exec is a child_process.exec mocking library for Node.js inspired by nock library.

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

You can limit the execution of the command one time:

var nockExec = require('nock-exec');
nockExec('myapp').once().err('some error').reply(0, 'This command was mocked');

If you try to call this command again will not work.

To do

arguments

Manage conditional arguments like

var nockExec = require('nock-exec');
nockExec('myapp').args('a b c').reply(0, 'done');

delay

var nockExec = require('nock-exec');
nockExec('myapp').args('a b c').delay(300).reply(0, 'done');

filtering

var nockExec = require('nock-exec');
nockExec('myapp')
    .filteringArgs(function(args) {
       return 'a b c';
    })
    .reply(0, 'done');

About

NodeJS mock module around the child_process.exec function inspired by nock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published