From 93dec1248def09821d7a46567b450dc1c5331bdb Mon Sep 17 00:00:00 2001 From: David Mohr Date: Wed, 6 Jan 2016 18:57:27 +1100 Subject: [PATCH] fix(gulp:mocha): have tests clean up once complete mocha unit and integration tests will hang unless express (and optionally mongoose) are closed once the tests are complete --- app/templates/gulpfile.babel(gulp).js | 4 ++-- app/templates/mocha.global(gulp).js | 8 ++++++++ app/templates/server/app.js | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 app/templates/mocha.global(gulp).js diff --git a/app/templates/gulpfile.babel(gulp).js b/app/templates/gulpfile.babel(gulp).js index 5b6e9d547..7d6ef7f59 100644 --- a/app/templates/gulpfile.babel(gulp).js +++ b/app/templates/gulpfile.babel(gulp).js @@ -42,8 +42,8 @@ const paths = { scripts: [`${serverPath}/**/!(*.spec|*.integration).js`], json: [`${serverPath}/**/*.json`], test: { - integration: `${serverPath}/**/*.integration.js`, - unit: `${serverPath}/**/*.spec.js` + integration: [`${serverPath}/**/*.integration.js`, 'mocha.global.js'], + unit: [`${serverPath}/**/*.spec.js`, 'mocha.global.js'] } }, karma: 'karma.conf.js', diff --git a/app/templates/mocha.global(gulp).js b/app/templates/mocha.global(gulp).js new file mode 100644 index 000000000..c34b2da8c --- /dev/null +++ b/app/templates/mocha.global(gulp).js @@ -0,0 +1,8 @@ +import app from './';<% if (filters.mongoose) { %> +import mongoose from 'mongoose';<% } %> + +after(function(done) { + app.angularFullstack.on('close', () => done());<% if (filters.mongoose) { %> + mongoose.connection.close();<% } %> + app.angularFullstack.close(); +}); diff --git a/app/templates/server/app.js b/app/templates/server/app.js index 20d4aefe8..c3e2eaefe 100644 --- a/app/templates/server/app.js +++ b/app/templates/server/app.js @@ -34,7 +34,7 @@ require('./routes')(app); // Start server function startServer() { - server.listen(config.port, config.ip, function() { + app.angularFullstack = server.listen(config.port, config.ip, function() { console.log('Express server listening on %d, in %s mode', config.port, app.get('env')); }); }