Skip to content

Instantly share code, notes, and snippets.

Created January 6, 2013 06:38
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 anonymous/4465655 to your computer and use it in GitHub Desktop.
Save anonymous/4465655 to your computer and use it in GitHub Desktop.
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