Skip to content

Instantly share code, notes, and snippets.

@metasansana
Created December 31, 2014 15:21
Show Gist options
  • Save metasansana/d4215508ad2e01e4fc21 to your computer and use it in GitHub Desktop.
Save metasansana/d4215508ad2e01e4fc21 to your computer and use it in GitHub Desktop.
Running a multiple functional tests for a http.Server app.
var http = require('http');
var q = require('q');
require('must');
var server;
var sockets = [];
beforeEach(function(done) {
server = http.createServer();
server.listen(8000, done);
});
afterEach(function() {
var list = [];
console.log('cleaning up');
sockets.forEach(function(socket) {
console.log('closing ', socket);
list.push(q.ninvoke(socket, 'destroy'));
});
console.log('closing http');
list.push(q.ninvoke(server, 'close'));
server.on('close', function() {
console.log('closing the connections');
});
list.push(q.ninvoke({
wait: function(cb) {
setTimeout(cb, 1000);
}
}, 'wait'));
return q.all(list);
});
describe('this silly test', function() {
it('should work', function() {
console.log('Work once');
'string'.must.equal('string');
});
});
describe('this silly test part two', function() {
it('should work twice', function() {
console.log('work twice');
'string'.must.equal('string');
});
});
describe('this silly test part three', function() {
it('should work thrice', function() {
console.log('work thrice');
'string'.must.equal('string');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment