Created
December 10, 2011 14:52
-
-
Save edwardhotchkiss/1455339 to your computer and use it in GitHub Desktop.
Testing a NodeJS spawned process (.spawn) with Vows BDD Test Suite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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