Declare test dependency using Npm.depends

I would like to know how to declare an Npm module dependency in Meteor in test only.

When testing a package, I can easily declare an Npm dependency in the package.js

following way:

Npm.depends({
  ...
  'sinon': '1.15.3'
  ...
});

      

But I only use sinon

in test and I want to make it explicit.

I have tried the following with no success.

Package.onTest(function(api) {
  // # 1
  // can't do this because it is not a meteor module
  api.use('sinon');

  // # 2
  // can't because I have other production Npm dependencies
  // and Meteor only allows one `Npm.depends` call per `package.js`.
  // Also, not sure if nesting Npm.depends() is allowed at all.
  Npm.depends({
    'sinon': '1.15.3'
  });


});

      

Any suggestions?

+3


source to share


1 answer


The only way to do this is to wrap sinon in a bag and api.use

that. You can do the following:

$ meteor create --package sinon

      

Replace the content packages/sinon

with the following:

package.js

Package.describe({
  summary: 'Standalone test spies, stubs and mocks for JavaScript.'
});

Package.onUse(function(api) {
  api.versionsFrom('1.0.4');
  api.export('sinon', 'server');
  api.addFiles('sinon.js');
  api.addFiles('post.js');
});

      

post.js



sinon = this.sinon;

      

sinon.js

Download the latest version here .

Finally, in the package under test, you can add api.use('sinon');

to Package.onTest

.


As an alternative to creating your own package, you can simply use one of the community versions available here .

+1


source







All Articles