Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 5f57f9d

Browse files
committed
#450 Now the mocha task synchronously calls mongoose connect and
disconnect.
1 parent 6f09033 commit 5f57f9d

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

gulpfile.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,29 +111,26 @@ gulp.task('less', function () {
111111
.pipe(gulp.dest('./modules/'));
112112
});
113113

114-
// Connect to MongoDB using the mongoose module
115-
gulp.task('openMongoose', function (done) {
114+
// Mocha tests task
115+
gulp.task('mocha', function (done) {
116+
// Open mongoose connections
116117
var mongoose = require('./config/lib/mongoose.js');
117118

119+
var error;
118120
mongoose.connect(function() {
119-
done();
121+
gulp.src(testAssets.tests.server)
122+
.pipe(plugins.mocha({
123+
reporter: 'spec'
124+
}))
125+
.on('error', function (err) {
126+
error = new Error('Mocha tests failed');
127+
}).on('end', function() {
128+
mongoose.disconnect(function(){
129+
done(error);
130+
});
131+
});
120132
});
121-
});
122-
123-
gulp.task('closeMongoose', function (done) {
124-
var mongoose = require('./config/lib/mongoose.js');
125133

126-
mongoose.disconnect(function(err) {
127-
done(err);
128-
});
129-
});
130-
131-
// Mocha tests task
132-
gulp.task('mocha', function () {
133-
return gulp.src(testAssets.tests.server)
134-
.pipe(plugins.mocha({
135-
reporter: 'spec'
136-
}));
137134
});
138135

139136
// Karma test runner task
@@ -143,11 +140,7 @@ gulp.task('karma', function (done) {
143140
configFile: 'karma.conf.js',
144141
action: 'run',
145142
singleRun: true
146-
}))
147-
.on('error', function (err) {
148-
// Make sure failed tests cause gulp to exit non-zero
149-
throw err;
150-
});
143+
}));
151144
});
152145

153146
// Selenium standalone WebDriver update task
@@ -176,7 +169,7 @@ gulp.task('build', function(done) {
176169

177170
// Run the project tests
178171
gulp.task('test', function(done) {
179-
runSequence('env:test', 'openMongoose', ['karma', 'mocha'], 'closeMongoose', done);
172+
runSequence('env:test', ['karma', 'mocha'], done);
180173
});
181174

182175
// Run the project in development mode

0 commit comments

Comments
 (0)