Create a gist now

Instantly share code, notes, and snippets.

anonymous /gist:4465655
Created Jan 6, 2013

Unit test for node server
var assert = require("assert");
var request = require("request");
var fork = require("child_process").fork;
describe("Server", function(){
var child;
before(function(done){
child = fork('index.js', null);
child.send({func: 'start'});
child.on('message', function(msg){
if(msg === 'listening'){
done();
}
});
});
after(function(){
child.kill();
});
it('listens on port 4000', function(done){
request('http://localhost:4000', function(err, res, body){
assert(res.statusCode == 200);
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment