Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created December 10, 2011 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardhotchkiss/1455339 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/1455339 to your computer and use it in GitHub Desktop.
Testing a NodeJS spawned process (.spawn) with Vows BDD Test Suite
var child
, stdout = ''
, stderr = ''
, exitCode = 0
, vows = require('vows')
, path = require('path')
, assert = require('assert')
, request = require('request')
, spawn = require('child_process').spawn;
vows.describe('general http tests').addBatch({
'index page "/"': {
topic: function() {
var self = this
, args = [path.join(__dirname, '/../', 'app.js')]
child = spawn('node', args)
child.stdout.on('data', function(data){
stdout += data;
});
child.stderr.on('data', function(data){
stderr += data;
});
child.on('exit', function(code){
exitCode = code;
});
setTimeout(function() {
request('http://localhost:8000/', self.callback);
}, 1000);
},
'should have no errors':function(error, response, body){
child.kill('SIGHUP');
assert.isNull(error);
},
'with a response code of 200':function(error, response, body){
assert.equal(response.statusCode, 200);
},
'the body should be html':function(error, response, body){
assert.equal(/html/m.test(body), true);
},
'with an exit code of 0':function(error, response, body){
assert.equal(exitCode, 0);
},
'an empty stderr':function(error, response, body){
assert.equal(stderr.length, 0);
}
}
}).export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment