mfncooper / mockery

Simplifying the use of mocks with Node.js
Other
1.1k stars 60 forks source link

WARNING: loading non-allowed module #27

Closed mariantatarau closed 9 years ago

mariantatarau commented 9 years ago

why i get this warning every time ?

davglass commented 9 years ago

You can stop those warnings with this: https://github.com/mfncooper/mockery#options

mockery.enable({
    warnOnReplace: false,
    warnOnUnregistered: false
});
maxfelker commented 8 years ago

Hey @davglass

These suppress the warning but as @mariantatarau asked - why does this warning happen and how do we prevent it? I would like to resolve the issue rather than suppressing the warning.

Thanks!

davglass commented 8 years ago

There isn't an issue, it's more of a logging thing. The warning is on by default and AFAIK it's always been on. I guess it's supposed to help you know when a module is being mocked vs one that isn't?

maxfelker commented 8 years ago

Hey @davglass

I see, thanks for the information. Take this example from my current test experiment block below. When I register getPopulatedItemMock, it complains form Test 1 like about all of my modules then only complains about my mocked one in Test 2.

Why is that? Any information would be super helpful, thanks!!!

WARNING: loading non-allowed module: ../../lib/helpers/getPopulatedItems.js
WARNING: loading non-allowed module: lodash
WARNING: loading non-allowed module: ../../config/logger
WARNING: loading non-allowed module: ./environment
WARNING: loading non-allowed module: convict
WARNING: loading non-allowed module: depd
Helper/getPopulatedItems Tests
  ✔ 1) Empty item should not be returned (8 ms)
WARNING: loading non-allowed module: ../../lib/helpers/getPopulatedItems.js
  ✔ 2) Item with data should be returned (0 ms)
  var getPopulatedItems;
  var mockCredentials = { userToken: 'testGuid' };

  lab.before(function (done) {
    mockery.enable({
      useCleanCache: true
    });
    done();
  });

  lab.beforeEach(function (done) {
    var getPopulatedItemMock = function(item) {
      return item;
    };
    mockery.registerMock('./getPopulatedItem', getPopulatedItemMock);
    getPopulatedItems = require('../../lib/helpers/getPopulatedOtemss.js');

    done();
  });

  lab.after(function(done) {
    mockery.disable();
    done();
  });

  lab.afterEach(function(done) {
    mockery.deregisterAll();
    done();
  });

  var validItem = {data: [{}]};
  var invalidItem = {};

  lab.test('Empty item should not be returned', function(done) {
    getPopulatedItems([invalidItem], mockCredentials)
    .then(function(result) {
        Code.expect(result.length).to.equal(0);
        done();
    })
    .catch(function(err) {
        done(err);
    });
  });

  lab.test('Item with data should be returned', function(done) {
      getPopulatedItems([validItem], mockCredentials)
      .then(function(result) {
        Code.expect(result.length).to.equal(1);
          done();
      })
      .catch(function(err) {
          done(err);
      });
  });
delapuente commented 7 years ago

@maxatbrs Wording is hard but it happens each time you load a non mocked module.

  • warnOnUnregistered determines whether or not warnings are issued when a module is not mocked, substituted or allowed. This has the same effect as the warnOnUnregistered function. [Default: true]