gemini-express
Advanced tools
Comparing version 0.9.0 to 0.9.1
var Server = require('./server'); | ||
var Q = require('q'); | ||
@@ -7,10 +8,21 @@ module.exports = function(gemini, opts) { | ||
gemini.on('startRunner', function(runner) { | ||
var deferred = Q.defer(); | ||
server.start(opts, function(rootUrl) { | ||
gemini.config.rootUrl = rootUrl; | ||
deferred.resolve(); | ||
}); | ||
return deferred.promise; | ||
}); | ||
gemini.on('endRunner', function(runner, data) { | ||
server.stop(); | ||
var deferred = Q.defer(); | ||
server.stop(function() { | ||
deferred.resolve(); | ||
}); | ||
return deferred.promise; | ||
}); | ||
}; |
{ | ||
"name": "gemini-express", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "Plugin for starting up Express when running tests with Gemini", | ||
@@ -20,6 +20,8 @@ "main": "lib/plugin.js", | ||
"freeport": "^1.0.4", | ||
"http-close": "0.0.2" | ||
"http-close": "0.0.2", | ||
"q": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^2.1.2", | ||
"mocha": "^2.2.1", | ||
"mockery": "^1.4.0", | ||
@@ -26,0 +28,0 @@ "sinon": "^1.14.1" |
@@ -1,2 +0,1 @@ | ||
var assert = require('chai').assert; | ||
var expect = require('chai').expect; | ||
@@ -7,23 +6,35 @@ var mockery = require('mockery'); | ||
describe('gemini-express', function() { | ||
var listeners; | ||
var root, | ||
var serverRoot, | ||
gemini, | ||
server, | ||
plugin; | ||
plugin, | ||
q, | ||
deferred; | ||
before(function() { | ||
q = sinon.spy(); | ||
server = sinon.spy(); | ||
mockery.registerMock('q', q); | ||
mockery.registerMock('./server', function(root) { serverRoot = root; return server; }); | ||
}); | ||
beforeEach(function() { | ||
server.reset(); | ||
server.start = sinon.spy(); | ||
deferred = sinon.spy(); | ||
deferred.resolve = sinon.spy(); | ||
q.reset(); | ||
q.defer = sinon.spy(function() { | ||
return deferred; | ||
}); | ||
gemini = sinon.stub(); | ||
gemini.config = sinon.spy(); | ||
gemini.on = function(event, callback) { | ||
listeners[event] = callback; | ||
gemini[event] = callback; | ||
}; | ||
var Server = sinon.stub(); | ||
Server.returns(server); | ||
server = sinon.spy(); | ||
server.start = sinon.spy(); | ||
listeners = {}; | ||
mockery.enable({ | ||
@@ -34,4 +45,2 @@ warnOnReplace: false, | ||
mockery.registerMock('./server', function(_root) { root = _root; return server; }); | ||
plugin = require('../lib/plugin'); | ||
@@ -42,10 +51,2 @@ | ||
function startRunner() { | ||
listeners.startRunner({}); | ||
} | ||
function endRunner() { | ||
listeners.endRunner({}); | ||
} | ||
function init(opts) { | ||
@@ -55,40 +56,78 @@ plugin(gemini, opts); | ||
it('should use root from options', function() { | ||
init({ root: 'foobar' }); | ||
describe('on startRunner', function() { | ||
function startRunner() { | ||
return gemini.startRunner({}); | ||
} | ||
expect(root).to.equal('foobar'); | ||
}); | ||
it('should set server root from options', function() { | ||
init({ root: 'foobar' }); | ||
it('should use root from options', function() { | ||
init(true); | ||
expect(serverRoot).to.equal('foobar'); | ||
}); | ||
expect(root).to.be.undefined; | ||
}); | ||
it('should set server root from options', function() { | ||
init(true); | ||
it('should start server on startRunner', function() { | ||
init({}); | ||
startRunner(); | ||
expect(serverRoot).to.be.undefined; | ||
}); | ||
assert(server.start.calledOnce); | ||
}); | ||
it('should start server on startRunner', function() { | ||
init({}); | ||
startRunner(); | ||
it('should set rootUrl', function() { | ||
server.start = function(opts, cb) { | ||
cb('http://foo.bar'); | ||
}; | ||
expect(server.start.calledOnce); | ||
}); | ||
init({}); | ||
startRunner(); | ||
it('should set rootUrl', function() { | ||
server.start = function(opts, cb) { | ||
cb('http://foo.bar'); | ||
}; | ||
expect(gemini.config.rootUrl).to.equal('http://foo.bar'); | ||
init({}); | ||
startRunner(); | ||
expect(gemini.config.rootUrl).to.equal('http://foo.bar'); | ||
}); | ||
it('should return a promise on startRunner', function() { | ||
deferred.promise = sinon.spy(); | ||
init({}); | ||
expect(startRunner()).to.equal(deferred.promise); | ||
}); | ||
}); | ||
it('should stop the server on endRunner', function() { | ||
server.stop = sinon.spy(); | ||
describe('on endRunner', function() { | ||
function endRunner() { | ||
return gemini.endRunner({}); | ||
} | ||
init({}); | ||
endRunner(); | ||
beforeEach(function() { | ||
server.stop = sinon.spy(); | ||
init({}); | ||
}); | ||
assert(server.stop.called); | ||
it('should stop the server on endRunner', function() { | ||
endRunner(); | ||
expect(server.stop.called); | ||
}); | ||
it('should return a promise on endRunner', function() { | ||
deferred.promise = sinon.spy(); | ||
expect(endRunner()).to.equal(deferred.promise); | ||
}); | ||
it('should resolve the given promise', function() { | ||
server.stop = function(cb) { | ||
cb(); | ||
} | ||
endRunner(); | ||
expect(deferred.resolve.called); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
92682
20
251
5
4