Skip to content

Instantly share code, notes, and snippets.

@lxe
Last active January 4, 2016 20:49
Show Gist options
  • Select an option

  • Save lxe/8676227 to your computer and use it in GitHub Desktop.

Select an option

Save lxe/8676227 to your computer and use it in GitHub Desktop.
// run with "mocha mocha-proc.js"
var spawn = require('child_process').spawn
, should = require('should')
describe('your thing', function () {
it('should do some stuff', function (done) {
var ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', function (data) {
// Check for data, call done()
console.log('stdout: ' + data);
});
ls.stderr.on('data', function (data) {
// OR check for data and call done() or throw some errors
console.log('stderr: ' + data);
});
ls.on('close', function (code) {
// OR check for status code and call done()
console.log('child process exited with code ' + code);
code.should.equal(0);
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment