meteor test-packages can't find npm module

2019-07-22 20:09发布

问题:

I'm trying to use lodash package in testing packages in Meteor version 1.3.2.4.

I've installed lodash via command: meteor npm install --save lodash.

It works fine in module but it doesn't work in tests. Here is my onTest:

Package.onTest(function(api) {
  var dependencies = [
    'practicalmeteor:mocha@2.4.5_2',
    'practicalmeteor:chai@2.1.0_1', 
    'practicalmeteor:sinon@1.14.1_2'
  ];
  api.use('core');
  api.use(dependencies);
  api.mainModule('tests/core.specs.js');
});

and when I try to use lodash (I've also tried moment, same result) in spec file, I run command: meteor test-packages --driver-package practicalmeteor:mocha core

I got an error: Error: Can't find npm module 'lodash'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?

I've also tried to use Npm.depends in package.js - got the same error.

Any idea how to fix that?

Edit

I've found solution. I have to use Npm.depends exactly in package where I want to use it. So when I put it in package called test-core but wanted in package named e.g collections it won't work. Npm.depends should right in collections package.js file.

Hope this will help someone else!