I believe the issue is due to a couple things:
- The callback is invoked in the Given, essentially exiting the cucumberjs program prior to finishing the child process execution.
- The exit delegate passed into exec() is being overridden when assigning an 'on' event handler.
I believe this will solve your issue:
var ChildProcess = require('child_process');
function execCmd(cb) {
console.log('Testing command...');
var bin = ChildProcess.exec('ls -l', {timeout:5}, function(error, stdout, stderr) {
console.log('executing...');
console.log(error);
console.log(stdout);
console.log(stderr);
cb();
});
}
module.exports = function() {
this.Given(/^I am on the command line$/, function(callback) {
execCmd(callback);
});
}