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

时间:2016-06-02 08:56:23

标签: javascript testing meteor coffeescript mocha

在以下命令中,我收到以下错误

$ 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').

我很困惑,因为我在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.

控制台输出

=> 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

1 个答案:

答案 0 :(得分:2)

根据Package.onTest documentation,您需要单独指定测试的依赖关系。因此,如果您的单元测试使用CoffeeScript,那么您需要在onTest回调中明确指定它。

您可以将包的单元测试视为在您正在测试的包之上构建的独立包。

<强>为什么吗

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