0

After updating gulp-mocha to latest version 6.0.0 all my tests crashed. mongoose is complaining with MissingSchemaError, all the tests Timeout even after increasing the timer, I cant find whats wrong. It appears setting up Mocha and Mongoose has changed and cant find any resource, I tried with promises/ sync and nothing here is how my old code that worked in gulp-mocha :3.0.1 looked

gulp.task('mocha', () => {
  process.env.NODE_CONFIG_DIR = './server/tools/config';
  let config = require('configuration')();
  const mongooseTools = require("./server/tools/mongoose-tools");

  return mongooseTools.connect(config.db)
    .then(db => mongooseTools.dropDatabase(db))
    .then(() => Promise.all([
      new Promise((resolve, reject) => gulp.src(testSuites, {read: false})
        .pipe(plugins.mocha({
          reporter: 'spec',
          exit: true,
          checkLeaks: true,
          timeout: 10000
        }))
        .on('error', reject)
        .on('end', resolve))
    ]))
    .catch(err => console.log(err))
    .then(() => mongooseTools.disconnect());
});
ramon22
  • 3,528
  • 2
  • 35
  • 48

1 Answers1

0

Try creating a new mongoose connection every time. So mongoose.createConnection().then(conn => {}) instead of mongooseTools.connect(config.db).then(). Using the mongoose global connection is messy if you're using something like gulp tasks that re-run continuously.

vkarpov15
  • 3,614
  • 24
  • 21
  • I want to start and close the DB in the task not in the tests, saves me from repetitive code and I can always clear DB in the tests so no mess, also the most important reason Webstorm will fail to stop at debug break points if I run db in tests a bug in their IDE – ramon22 Jun 19 '18 at 15:56