Javascript 为什么我必须复制Meteor中Package.onTest中Package.onUse中指定的包?

Javascript 为什么我必须复制Meteor中Package.onTest中Package.onUse中指定的包?,javascript,testing,meteor,coffeescript,mocha.js,Javascript,Testing,Meteor,Coffeescript,Mocha.js,在下面的命令中,我得到以下错误 $ meteor test-packages --driver-package practicalmeteor:mocha rocketchat:spotify 控制台输出 => Errors prevented startup: While building package local-test:rocketchat:spotify: error: No plugin known to handle file 'spotify.test.c

在下面的命令中,我得到以下错误

$ meteor test-packages --driver-package practicalmeteor:mocha rocketchat:spotify
控制台输出

=> 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').
=> 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
我很困惑,因为我在package.onUse下指定了coffeescript包

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');
});
按如下方式添加coffeescript包可以解决此问题

Package.onTest(function (api) {
    api.use([
        'coffeescript',
        'rocketchat:spotify'
    ]);
    api.addFiles('spotify.test.coffee');
});

=> Modified -- restarting.
=> Meteor server restarted
=> Started your app.
控制台输出

=> 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').
=> 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
版本信息

$ meteor --version
Meteor 1.2.1

根据
Package.onTest
的要求,您需要单独指定测试的依赖项。因此,如果单元测试使用CoffeeScript,则需要在
onTest
回调中显式指定它

您可以将包的单元测试看作是构建在您正在测试的包之上的独立包

为什么?

MDG做到了这一点,因为有时您的测试与您正在测试的包具有不同的依赖关系。例如:您在CoffeeScript上编写了包,但您的测试是在普通JavaScript上编写的。那么CoffeeScript依赖关系对于测试来说是多余的。当前版本的API允许您单独指定这些依赖项