Fixed server tests to exit when they are finished. jasmine-node will never exit unless all connections are closed.

This helped:
https://github.com/mhevery/jasmine-node/issues/318#issuecomment-43914090
This commit is contained in:
Scott Erickson 2014-06-11 13:21:11 -07:00
parent 6d15b5e631
commit ea06bb3d52
3 changed files with 15 additions and 12 deletions

View file

@ -9,6 +9,10 @@ jasmine.getEnv().addReporter(new jasmine.SpecReporter({
displaySuccessfulSpec: true, displaySuccessfulSpec: true,
displayFailedSpec: true displayFailedSpec: true
})) }))
rep = new jasmine.JsApiReporter()
jasmine.getEnv().addReporter(rep)
GLOBAL._ = require('lodash') GLOBAL._ = require('lodash')
_.str = require('underscore.string') _.str = require('underscore.string')
_.mixin(_.str.exports()) _.mixin(_.str.exports())
@ -149,3 +153,13 @@ _drop = (done) ->
chunks = mongoose.connection.db.collection('media.chunks') chunks = mongoose.connection.db.collection('media.chunks')
chunks.remove {}, -> chunks.remove {}, ->
done() done()
tickInterval = null
tick = ->
# When you want jasmine-node to exit after running the tests,
# you have to close the connection first.
if rep.finished
mongoose.disconnect()
clearTimeout tickInterval
tickInterval = setInterval tick, 1000

View file

@ -6,9 +6,8 @@ urlLogin = getURL('/auth/login')
urlReset = getURL('/auth/reset') urlReset = getURL('/auth/reset')
describe '/auth/whoami', -> describe '/auth/whoami', ->
http = require 'http'
it 'returns 200', (done) -> it 'returns 200', (done) ->
http.get(getURL('/auth/whoami'), (response) -> request.get(getURL('/auth/whoami'), (err, response) ->
expect(response).toBeDefined() expect(response).toBeDefined()
expect(response.statusCode).toBe(200) expect(response.statusCode).toBe(200)
done() done()

View file

@ -18,13 +18,3 @@ describe 'Level', ->
level.save (err) -> level.save (err) ->
throw err if err throw err if err
done() done()
it 'loads again after being saved', (done) ->
url = getURL('/db/level/'+level._id)
request.get url, (err, res, body) ->
expect(res.statusCode).toBe(200)
sameLevel = JSON.parse(body)
expect(sameLevel.name).toEqual(level.get 'name')
expect(sameLevel.description).toEqual(level.get 'description')
expect(sameLevel.permissions).toEqual(simplePermissions)
done()