vendredi 23 janvier 2015

jasmine node testing child process.send

I have a node.js application that has a main process main-process.js and a child process child-process.js. The main-process.js looks like this,



var childProcess = require('child_process');
var job = childProcess.spawn('node', ["child-process.js"], {
detached = true,
stdio: ['ipc']
});


My child-process.js does some task and to notify the parent process about its status, it uses



exports.init = function() {
//some processing here
process.send({status: 'success or pending'});
}


Now I want to unit test child-process.js using jasmine-node. But when I call the method init() from the spec, jasmine-node is throwing an error saying



TypeError: Object #<process> has no method 'send'


Is there any way to mock the process variable? In other words, how do I unit test this scenario?


Aucun commentaire:

Enregistrer un commentaire