使用 mocha 测试包的正确结构是什么?

What is the correct structure for using mocha to test your package?

现在我有:

Package.describe({
  name: 'parlay:synapsepay',
  version: '0.0.1',
  summary: 'synapse_pay_rest for Meteor',
  git: 'https://github.com/parlaywithme/meteor-synapsepay',
  documentation: 'README.md'
});

Package.onUse(function(api) {
  api.versionsFrom('1.2.0.2');
  api.use('coffeescript');
  api.addFiles('synapsepay.coffee');
});

Package.onTest(function(api) {
  api.use('coffeescript');
  api.use('mike:mocha-package');
  api.use('parlay:synapsepay');
  api.addFiles('synapsepay-tests.coffee');
});

MochaWeb?.testOnly ->
  describe 'sanity', ->
    it 'is visible', ->
      chai.assert.isDefined SynapsePay

https://github.com/parlaywithme/meteor-synapsepay

我遇到 has no method 'testOnly' 错误,运行

meteor test-packages ./

里面 packages/meteor-synapsepay:

ERROR: packages.json parsing error [ ENOENT, no such file or directory '/Users/me/parlay/packages/meteor-synapsepay/packages.json' ]
[[[[[ Tests ]]]]]                             

=> Started proxy.                             
=> Started MongoDB.                           
W20151018-00:24:58.123(-4)? (STDERR)          
W20151018-00:24:58.125(-4)? (STDERR) /Users/me/.meteor/packages/meteor-tool/.1.1.9.osr2yb++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20151018-00:24:58.125(-4)? (STDERR)                        throw(ex);
W20151018-00:24:58.125(-4)? (STDERR)                              ^
W20151018-00:24:58.125(-4)? (STDERR) TypeError: Object [object Object] has no method 'testOnly'
W20151018-00:24:58.125(-4)? (STDERR)     at Package (packages/local-test_parlay_synapsepay/synapsepay-tests.coffee:1:11)
W20151018-00:24:58.125(-4)? (STDERR)     at packages/local-test_parlay_synapsepay/synapsepay-tests.coffee:1:1
W20151018-00:24:58.126(-4)? (STDERR)     at packages/local-test_parlay_synapsepay/synapsepay-tests.coffee:1:1
W20151018-00:24:58.126(-4)? (STDERR)     at /private/tmp/meteor-test-run1tbmejw/.meteor/local/build/programs/server/boot.js:242:10
W20151018-00:24:58.126(-4)? (STDERR)     at Array.forEach (native)
W20151018-00:24:58.126(-4)? (STDERR)     at Function._.each._.forEach (/Users/me/.meteor/packages/meteor-tool/.1.1.9.osr2yb++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20151018-00:24:58.126(-4)? (STDERR)     at /private/tmp/meteor-test-run1tbmejw/.meteor/local/build/programs/server/boot.js:137:5
=> Exited with code: 8

虽然目前记录不多,但这个问题很容易解决:
只需放弃 testOnly 并直接在测试文件中编写测试。

describe 'sanity', ->
  it 'is visible', ->
    chai.assert.isDefined SynapsePay

Mocha 最初是为应用程序测试而设计的。将其用于包装测试可能具有挑战性。
当您进行测试时 运行,您也可以 see big Meteor.methods Match errors in the console。这是一个常见问题,不应干扰测试本身。