Skip to content

Commit

Permalink
Update loading models for mocha testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagjeet committed Oct 29, 2018
1 parent 29a380d commit 133de5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
42 changes: 20 additions & 22 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,30 +419,28 @@ function mocha(done) {
mongooseService.connect(function (db) {
// Clean out test database to have clean base
mongooseService.dropDatabase(db, function () {
mongooseService.loadModels(function () {
// Run the tests
gulp.src(testSuites)
.pipe(plugins.mocha({
reporter: 'spec',
timeout: 10000
}))
.on('error', function (err) {
// If an error occurs, save it
error = err;
console.error(err);
})
.on('end', function () {
// When the tests are done, disconnect agenda/mongoose
// and pass the error state back to gulp
// @TODO: https://github.com/Trustroots/trustroots/issues/438
// @link https://github.com/agenda/agenda/pull/450
agenda._mdb.close(function () {
mongooseService.disconnect(function () {
done(error);
});
gulp.src(testSuites)
.pipe(plugins.mocha({
reporter: 'spec',
timeout: 10000,
file: './testutils/loadmodels.testutil'
}))
.on('error', function (err) {
// If an error occurs, save it
error = err;
console.error(err);
})
.on('end', function () {
// When the tests are done, disconnect agenda/mongoose
// and pass the error state back to gulp
// @TODO: https://github.com/Trustroots/trustroots/issues/438
// @link https://github.com/agenda/agenda/pull/450
agenda._mdb.close(function () {
mongooseService.disconnect(function () {
done(error);
});
});
});
});
});
});
}
Expand Down
13 changes: 13 additions & 0 deletions testutils/loadmodels.testutil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var mongooseService = require('../config/lib/mongoose');

var loadModelsDone = new Promise(function (resolve) {
mongooseService.loadModels(function () {
resolve(true);
});
});

loadModelsDone.then(
function (resolved) {
return resolved;
}
);

0 comments on commit 133de5c

Please sign in to comment.