Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockgoose is downloading 234mb when running mockgoose.prepareStorage

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

like image 707
Julien TASSIN Avatar asked Oct 17 '22 15:10

Julien TASSIN


1 Answers

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.

like image 98
Calvin K Cox Avatar answered Oct 21 '22 06:10

Calvin K Cox