Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
Last active September 8, 2015 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbeletsky/1b0dca8e788015bd6272 to your computer and use it in GitHub Desktop.
Save alexbeletsky/1b0dca8e788015bd6272 to your computer and use it in GitHub Desktop.
Wait for Express.js app starting before running tests
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;
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