Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created January 7, 2012 08:00
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/1574147 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/1574147 to your computer and use it in GitHub Desktop.
Vows Async Node.JS Process Testing w/ Request
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