Last active
September 8, 2015 08:51
-
-
Save alexbeletsky/1b0dca8e788015bd6272 to your computer and use it in GitHub Desktop.
Wait for Express.js app starting before running tests
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 express = require('express'); | |
var data = require('./source/data'); | |
var app = express(); | |
var port = process.env.PORT || 3036; | |
data.boot(env, function (err) { | |
if (err) { | |
app.emit('error', err); | |
throw err; | |
} | |
app.listen(port, function () { | |
app.emit('ready'); | |
}); | |
}); | |
module.exports = app; |
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
process.env.NODE_ENV = process.env.NODE_ENV || 'test'; | |
process.env.TEST_ENV = process.env.TEST_ENV || 'test'; | |
var exit = process.exit; | |
process.exit = function (code) { | |
setTimeout(function () { | |
exit(); | |
}, 200); | |
}; | |
// start server | |
var app = require('../app'); | |
console.log('booting up service, please wait...'); | |
app.on('ready', function () { | |
// run tests | |
require('../node_modules/mocha/bin/_mocha'); | |
}); | |
app.on('error', function (e) { | |
console.error(e); | |
process.exit(-1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment