5

I have a node application with access to mongodb thrown mongoose tested with mocha and mockgoose. I moved recently to mockgoose 7.0.5. I followed the getting started on github and upped my mocha timeout to 2 minutes.

Here are my before functions in my tests :

import mongoose from 'mongoose';
var Mockgoose = require('mockgoose').Mockgoose;
[...]

const mockgoose = new Mockgoose(mongoose);

before(function(done) {
  try {
    console.log('BEFORE prepareStorage');
    mockgoose.prepareStorage().then(() => {
    console.log('IN prepareStorage');
      mongoose.connect('mongodb://example.com/TestingDB', function(err) {
        done(err);
      });
    }).catch((error) => {
      done(error);
    });
  } catch(e) {
    done(e);
  }
  console.log('AFTER prepareStorage');  
});

beforeEach(function(done) {
  mockgoose.helper.reset();
  done();
});

When I run the tests, during the mockgoose.prepareStorage step, mockgoose seems to be downloading something.

BEFORE prepareStorage
AFTER prepareStorage
Completed: 0.1 % (0.2mb / 234.3mb

I guess it has something to do with the requested 2 minutes timeout.

My questions / problems are :

  • Does anybody know what mockgoose is downloading ? (I don't remember this behaviour with previous versions of mockgoose)

  • Does mockgoose need this download at each run (npm test) or will the result be reused in the next runs (npm test) ?

  • Can I prevent him to download something. Ideally, I would like to run my unit test in a sandbox env, with no access to the web (in a docker). Can I download the 234mb somewhere and ask mockgoose to reuse it ?

Thanks

Julien TASSIN
  • 5,004
  • 1
  • 25
  • 40

2 Answers2

2

I'm pretty sure this is an issue with the post-install step of mockgoose 7, although I can not nail down exactly what. Reverting to mockgoose ^6.0.0 fixes this issue.

Update

The issue is that the first time mockgoose runs it has to download the mongodb source, this can take a while. You should attempt to update your timeout on your tests to something long (5-10 minutes). This did solve the issue. Luckily that is only required once.

  • Hello, thanks for your response. This behaviour comes from the usage of mongodb-download in mongodb-prebuild. You're right about the fact that I can download it with one first npm test on my dev post. The problem is that, I would like to run my unit tests in continuous integration without access to the web. I will try to play with mongodb-download to pre-download it. I'll keep you informed – Julien TASSIN Mar 16 '17 at 19:57
1

I searched for hours on this issue, but I finally managed to have a dirty way to fix it:

Copy paste one test a few times. In my case, each test has a 10s time-out, which was not enough to make the percentage to 100%. So if you run enough tests (in my case about 6), you'll make it to 100%.

Once you get to 100%, you can run it again and all the tests can run fast now, so you can delete the duplicate tests again!

Tessa I
  • 108
  • 1
  • 6