Meteor test-packages fails to find NPM

I’m trying to test an old package using meteor test-packages ./, with the default driver test-in-browser. I get the following warning from this code:

The jquery npm package could not be found in your node_modules directory.
Please run the following command to install it:

  meteor npm install jquery

If you previously relied on a specific version of jquery, it may be important
to install that version; for example:

  meteor npm install jquery@1.12.1

Indeed, Package.jquery consists of {$: undefined, jQuery: undefined}, suggesting that the Meteor package jquery@3.0.0 loaded, but the NPM peer dependency did not. This causes the Blaze backend to fail.

Here’s the relevant part of my package.json:

Npm.depends({
  //...
  // Just needed for testing:
  jquery: '3.6.0' // also tried '1.12.1' recommended by error message
});

Package.onTest(function (api) {
  api.use('jquery@3.0.0', 'client');
  api.use('blaze@2.5.0', 'client');
  api.use('tinytest@1.1.0', ['server', 'client']);
  api.use('test-helpers@1.2.0', ['server', 'client']);
  //...
});

I don’t understand why Npm.depends isn’t enough to load the jquery NPM package. .npm/package/node_modules/jquery exists and looks fine. I tried adding Npm.require('jquery') to the test code to force it to load in browser, but that doesn’t seem to have an effect.

I figured that switching from jquery@3.0.0 to jquery@1.11.9 (which inlines a specific jquery version) would fix the problem. Unfortunately, test-in-browser@1.3.0 depends on jquery@3.0.0 (not the usual jquery@1.11.9 || jquery@1.3.0) so I can’t get that to work. meteor test-packages ./ --driver-package test-in-browser@1.2.0 and/or api.use('test-in-browser@1.2.0', ['server', 'client']); doesn’t seem to work; it still uses test-in-browser@1.3.0 and thereby fails to resolve dependencies.

If relevant, I’m using Windows 10.

I guess the last thing to try is to copy the package into an application that has npm install jquery. Rather annoyingly, this does seem to work.

Related threads:

Add a package.json to your meteor package, and then add jquery to that as a dev dependency. You’ll just have to remember to delete the node_modules folder when you aren’t specifically running tests.

You can add the node_modules folder to your .meteorignore file to keep it from getting distributed, but you’ll also want to just delete that whenever you are not running tests. I think that’ll get you up and running.

Thanks for the response! Unfortunately, I’m getting the same error even with this package.json. I tried both dependencies and devDependencies. (On the other hand, your answer answers my question of how to depend on jquery just for testing.)

Possibly relevant: require and Npm are undefined on the client side. Perhaps I’m missing a core package? I have ecmascript which depends on dynamic-import and modules

If you need jQuery only during tests you can try the following:

Package.onTest(function (api) {
  Npm.depends({
    jquery: '3.6.0' // only packages required for testing here!
  });
  api.use('jquery@3.0.0', 'client'); // if this is not working, try @3.0.0! (note the exclamation mark)
  api.use('blaze@2.5.0', 'client');
  api.use('tinytest@1.1.0', ['server', 'client']);
  api.use('test-helpers@1.2.0', ['server', 'client']);
  //...
});

Works for me very good with packages that I really need only for testing like chai and sinon, so maybe this can work out smh for you, too.

@jkuester Do you have an example repo you’re getting that from? When I try that in addition to a top-level Npm.depends, I get the following error:

While reading package from `.../meteor-file-collection`:
package.js:51:7: Npm.depends may only be called once per package
1 Like

Oh yeah, if you still have regular dependencies you need to put them in Package.onUse otherwise they will be called twice

1 Like

I haven’t been able to run package tests on any version of meteor newer than like 1.10 or so…

I was having trouble on Meteor 2.2.1 but (as I posted on the GitHub issue) 2.3.2 seems to work now. Did you try that version?

Oh nice! It’s working now on meteor 2.3.4! Cheers!