Created
January 7, 2012 08:00
-
-
Save edwardhotchkiss/1574147 to your computer and use it in GitHub Desktop.
Vows Async Node.JS Process Testing w/ Request
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
child = undefined | |
stdout = '' | |
stderr = '' | |
exitCode = 0 | |
vows = require('vows') | |
path = require('path') | |
assert = require('assert') | |
request = require('request') | |
spawn = require('child_process').spawn | |
args = [ path.join(__dirname, '/../', 'app.coffee') ] | |
class Fetcher | |
get: (callback) -> | |
setTimeout () -> | |
request 'http://localhost:8000/', callback | |
, 1000 | |
vows.describe('general http tests').addBatch('index page /': | |
topic: -> | |
child = spawn('coffee', args) | |
child.stderr.on 'data', (data) -> | |
stderr += data | |
child.on 'exit', (code) -> | |
exitCode = code | |
(new Fetcher).get(@callback) | |
undefined | |
'should have no errors': (error, response, body) -> | |
child.kill 'SIGHUP' | |
assert.isNull error | |
'with a response code of 200': (error, response, body) -> | |
assert.equal response.statusCode, 200 | |
'the body should be html': (error, response, body) -> | |
assert.equal /html/m.test(body), true | |
'with an exit code of 0': (error, response, body) -> | |
assert.equal exitCode, 0 | |
'an empty stderr': (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