Running gulp-mocha with mongoose Timeout with missing schema error

100 Views Asked by At

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());
});
1

There are 1 best solutions below

1
vkarpov15 On

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.