Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var should = require('should'),
srcd = process.cwd() + '/src',
rd = srcd + '/routines',
runner = require(rd + '/server/runner'),
configurer = require(rd + '/server/configurer'),
creator = require(rd + '/server/creator'),
EventEmitter2 = require('eventemitter2').EventEmitter2,
config = require(srcd + '/config'),
express = require('express');
describe('server init', function() {
var mediator;
beforeEach(function() {
++config.server.port;
mediator = new EventEmitter2();
});
it('should create server', function(done) {
creator(mediator);
mediator.once('server.created', function(server) {
server.should.exist;
done();
});
mediator.emit('boot.ready');
});
it('should configure server', function(done) {
configurer(mediator);
//emulate a server
var eserver = express.createServer();
mediator.once('server.configured', function(server) {
server.should.eql(eserver);
done();
});
//emulate server created
mediator.emit('server.created', eserver);
//emulate routes ready
mediator.emit('server.routes.ready');
});
it('should run the server', function(done) {
runner(mediator);
//emulate a server
var eserver = express.createServer();
mediator.once('server.running', function(server, port) {
server.should.exist;
server.should.eql(eserver);
port.should.eql(config.server.port);
done();
});
//emulate server configured
mediator.emit('server.configured', eserver);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment