Overdrivr / micro-ci

Continuous Integration for embedded platforms
0 stars 0 forks source link

mockery.RegisterSubstitute side effects #107

Open Overdrivr opened 8 years ago

Overdrivr commented 8 years ago

@DanFaudemer

I realized that mockery.RegisterSubstitute has very bad side effects in our test suite, leading to a lot of pollution between test.

For instance, calling

mockery.registerSubstitute('../../lib/gce_api', "../../lib/localhost_slave_api");
clear('../../server/server');
var app = require('../../server/server');

in a test where the server was required in another test before is not enough to replace the gce_api by localhost_slave_api.

What happens is the following:

  1. First test that doesnt need to substitute gce_api. Server is required, and requires gce_api
  2. Second test. mockery is called to substitute gceapi by localhost... Server is cleared. However, at this point it is still the gce_api module that is in require cache, and is used,

To reproduce this issue, add the following test in a file starting with the letter a so that it is executed before build_queued_test.js.

describe('Foo test that requires server before build_queued_test', function() {
  before(function(done) {
    clear('../../server/server');
    app = require('../../server/server');
    done();
  });

  it('doesnt allow unauthenticated clients to activate a repository',
  function(done){
        done();
      });
  });
});

I suggest we purely and simply remove mockery from our test suites, and replace it with nock. Which is much better as by design it is easy to avoid any pollution with it.