Saturday, June 11, 2016

Why do I have to duplicate packages that I specified in Package.onUse in Package.onTest in Meteor?

Leave a Comment

On the following command, I get the following error

$ meteor test-packages --driver-package practicalmeteor:mocha rocketchat:spotify 

Console output

=> Errors prevented startup:     While building package local-test:rocketchat:spotify:    error: No plugin known to handle file 'spotify.test.coffee'. If you want this file to be a static asset, use    addAssets instead of addFiles; eg, api.addAssets('spotify.test.coffee', 'client'). 

I'm confused as I have specified the coffeescript package under Package.onUse.

rocketchat-spotify/package.js

Package.describe({     name: 'rocketchat:spotify',     version: '0.0.1',     summary: 'Message pre-processor that will translate spotify on messages',     git: '' });  Package.onUse(function(api) {     api.versionsFrom('1.0');      api.use([         'coffeescript', # Coffeescript is included here?         'templating',         'underscore',         'rocketchat:oembed@0.0.1',         'rocketchat:lib'     ]);      api.addFiles('lib/client/widget.coffee', 'client');     api.addFiles('lib/client/oembedSpotifyWidget.html', 'client');      api.addFiles('lib/spotify.coffee', ['server', 'client']); });  Package.onTest(function (api) {     api.use([         'rocketchat:spotify'     ]);     api.addFiles('spotify.test.coffee'); }); 

Adding the coffeescript package as follows resolves the issue

Package.onTest(function (api) {     api.use([         'coffeescript',         'rocketchat:spotify'     ]);     api.addFiles('spotify.test.coffee'); });  => Modified -- restarting. => Meteor server restarted => Started your app. 

Console output

=> App running at: http://localhost:3000/ I20160602-17:55:02.867(9)? Updating process.env.MAIL_URL I20160602-17:55:04.528(9)? MochaRunner.runServerTests: Starting server side tests with run id aXdi2H3kBS8M8Fuhx W20160602-17:55:04.577(9)? (STDERR) MochaRunner.runServerTests: failures: 10 

Version info

$ meteor --version Meteor 1.2.1 

1 Answers

Answers 1

According to Package.onTest documentation you need to specify dependencies of your tests separately. So, if your unit tests use CoffeeScript then you need to specify it explicitly in onTest callback.

You can think of package's unit tests as of separate package built on top of package you are testing.

Why?

MDG did it, because sometimes your tests have different dependencies then package you are testing. For example: you wrote package on CoffeeScript, but your tests are written on plain JavaScript. Then CoffeeScript dependency is redundant for tests. And current version of API allows you to specify those dependencies separately.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment