Created
May 11, 2012 17:50
-
-
Save tommedema/2661323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EventEmitter2 = require('eventemitter2').EventEmitter2, | |
should = require('should'), | |
request = require('request'), | |
config = require('../../src/config'); | |
describe('server', function() { | |
var mediator, | |
port = config.server.port; | |
beforeEach(function() { | |
//bind to a different port on each test | |
config.server.port = ++port; | |
mediator = new EventEmitter2({ | |
wildcard: false | |
}); | |
require('../../src/routines/server/creator')(mediator); | |
require('../../src/routines/server/configurer')(mediator); | |
require('../../src/routines/server/runner')(mediator); | |
require('../../src/routines/server/routes/registration')(mediator); | |
require('../../src/routines/server/routes/root')(mediator); | |
require('../../src/routines/server/routes/404')(mediator); | |
}); | |
it('should cause server to be created', function(done) { | |
mediator.once('server.created', function(server) { | |
server.should.exist; | |
done(); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should cause server to be configured', function(done) { | |
mediator.once('server.configured', function(server) { | |
server.should.exist; | |
done(); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should cause route registration to start', function(done) { | |
mediator.once('server.routes.registration', function(server, registrator) { | |
server.should.exist; | |
registrator.should.exist; | |
registrator.should.be.a('function'); | |
done(); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should cause server to run', function(done) { | |
mediator.once('server.running', function(server, port) { | |
server.should.exist; | |
port.should.be.a('number'); | |
done(); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should cause route registration to finish', function(done) { | |
mediator.once('server.routes.ready', function() { | |
done(); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should cause root route to be installed before 404 route', function(done) { | |
var installedRoot = false; | |
mediator.on('server.routes.installed', function(name) { | |
if (name == 'root') installedRoot = true; | |
else if (name == '404') { | |
if (installedRoot) done(); | |
} | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should cause root route to be registered', function(done) { | |
mediator.on('server.routes.registered', function(name) { | |
if (name == 'root') done(); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should cause 404 route to be registered', function(done) { | |
mediator.on('server.routes.registered', function(name) { | |
if (name == '404') done(); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should give 200 status when root (/) is requested', function(done) { | |
mediator.once('server.running', function(server, port) { | |
request('http://localhost:' + port + '/', function(err, res, body) { | |
should.not.exist(err); | |
res.statusCode.should.eql(200); | |
done(); | |
}); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
it('should give 404 status when nonexisting path is requested', function(done) { | |
mediator.once('server.running', function(server, port) { | |
request('http://localhost:' + port + '/idonotexist', function(err, res, body) { | |
should.not.exist(err); | |
res.statusCode.should.eql(404); | |
done(); | |
}); | |
}); | |
mediator.emit('boot.ready'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment