在 meteor 中安装 mocha 后出错

Error after install mocha in meteor

我想对我的软件做一些测试,所以我按照互联网上的一些教程找到了软件包 practicalmeteor:mocha。但是在安装包并打开本地(没有编写任何测试)之后。我收到错误大喊:

socket-stream-client.js:100 Uncaught TypeError: _this._launchConnection is not a function
    at new ClientStream (socket-stream-client.js:100)
    at new Connection (ddp-client.js:435)
    at Object.DDP.connect (ddp-client.js:2340)
    at client_convenience.js (ddp-client.js:125)
    at fileEvaluate (modules-runtime.js:353)
    at require (modules-runtime.js:248)
    at client.js (ddp-client.js:54)
    at fileEvaluate (modules-runtime.js:353)
    at require (modules-runtime.js:248)
    at ddp-client.js:2381
ddp.js:14 Uncaught TypeError: Cannot read property 'DDP' of undefined
    at ddp.js:14
    at ddp.js:23
allow-deny.js:22 Uncaught TypeError: Cannot read property 'DDP' of undefined
    at allow-deny.js:22
    at allow-deny.js:566
mongo.js:17 Uncaught TypeError: Cannot read property 'AllowDeny' of undefined
    at mongo.js:17
    at mongo.js:871
accounts-base.js:23 Uncaught TypeError: Cannot read property 'DDP' of undefined
    at accounts-base.js:23
    at accounts-base.js:1462
service-configuration.js:17 Uncaught TypeError: Cannot read property 'Accounts' of undefined
    at service-configuration.js:17
    at service-configuration.js:73
accounts-password.js:17 Uncaught TypeError: Cannot read property 'Accounts' of undefined
    at accounts-password.js:17
    at accounts-password.js:329
accounts-ui-unstyled.js:19 Uncaught TypeError: Cannot read property 'ServiceConfiguration' of undefined
    at accounts-ui-unstyled.js:19
    at accounts-ui-unstyled.js:2113
meteortoys_toykit.js:26 Uncaught TypeError: Cannot read property 'Mongo' of undefined
    at meteortoys_toykit.js:26
    at meteortoys_toykit.js:410
msavin_mongol.js:20 Uncaught TypeError: Cannot read property 'Mongo' of undefined
    at msavin_mongol.js:20
    at msavin_mongol.js:1058
autoupdate.js:20 Uncaught TypeError: Cannot read property 'DDP' of undefined
    at autoupdate.js:20
    at autoupdate.js:231
practicalmeteor_mocha.js:18 Uncaught TypeError: Cannot read property 'DDP' of undefined
    at practicalmeteor_mocha.js:18
    at practicalmeteor_mocha.js:13186
livedata.js:14 Uncaught TypeError: Cannot read property 'DDP' of undefined
    at livedata.js:14
    at livedata.js:27
global-imports.js:3 Uncaught TypeError: Cannot read property 'Mongo' of undefined
    at global-imports.js:3
meteor.js:1081 Uncaught Error: Can't find test driver package: practicalmeteor:mocha
    at meteor.js:1081
    at maybeReady (meteor.js:871)
    at HTMLDocument.loadingCompleted (meteor.js:883)

我正在使用 meteor 1.6.1.1

我会把这个作为答案,因为它可能仍然相关,所以新用户也有同样的想法。

practialmeteor:mocha 是一个推荐的软件包,但不再与 Meteor >=1.6.1 兼容,并且它不再被维护的可能性非常高(正如您在他们的 open gh issues 中看到的那样)。

替代包包括

  • cultofcoders:mocha

  • meteortesting:mocha

我也遇到过这样的事情,真是费了好大劲才弄明白。

根据 Meteor Todo App with Angular 教程,推荐使用 practicalmeteor:mocha 包。有趣的是,meteortesting:mocha 用于典型的 脚手架 项目。

  "scripts": {
    "start": "meteor run",
    "test": "meteor test --once --driver-package meteortesting:mocha",
    "test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
    "visualize": "meteor --production --extra-packages bundle-visualizer"
  },

但是,仅使用从 practicalmeteor:mocha 派生的 cultofcoders:mocha 确实有效。

meteor remove practicalmeteor:mocha
meteor add cultofcoders:mocha
meteor test --driver-package cultofcoders:mocha

享受编码吧!