public
anonymous / gist:4465655
Created

Unit test for node server

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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();
});
});
 
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.