【问题标题】:Why isnt bin/mocha running all my tests?为什么 bin/mocha 没有运行我的所有测试?
【发布时间】:2014-02-15 14:55:15
【问题描述】:

我有一个 node.js/express/mocha 项目。从我项目的根目录中,当我这样做时

./node_modules/.bin/mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list

  1) UnitsController /units.json "before all" hook
  ․ CordBloodUnit should set attrs: 0ms
  ․ CordBloodUnit #getMatchCount should get the match count of alleles: 0ms
  ․ pg-adapter #runQuery should get results of the query: 7ms
  ․ pg-adapter #runQuery should get Cord Blood Units: 4ms

  4 passing (2s)
  1 failing

  1) UnitsController /units.json "before all" hook:
     Error: timeout of 2000ms exceeded
    at Object.<anonymous> (/Users/pguruprasad/Projects/jeevan-js/node_modules/mocha/lib/runnable.js:175:14)
    at Timer.list.ontimeout (timers.js:101:19)

我看到所有测试都在运行。但是当我想将长命令放入脚本中执行时,mocha 只运行两个测试并忽略其余测试。这里有什么问题?

➜  ~jjs git:(master) ✗ touch test1
➜  ~jjs git:(master) ✗ echo "./node_modules/.bin/mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list" >> test1
➜  ~jjs git:(master) ✗ cat test1
./node_modules/.bin/mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list
➜  ~jjs git:(master) ✗ chmod +x test1
➜  ~jjs git:(master) ✗ ./test1       

  ․ CordBloodUnit should set attrs: 0ms
  ․ CordBloodUnit #getMatchCount should get the match count of alleles: 0ms

  2 passing (2ms)

【问题讨论】:

  • 您能添加test/ 的树的样子吗?鉴于@dankohn 的回答不起作用?

标签: node.js express mocha.js


【解决方案1】:

您的问题可能是您的脚本运行的路径或环境变量不同。它可能正在运行全局 mocha 而不是您项目中安装的 mocha,或者它可能具有不同的 cwd。

我强烈建议将以下内容添加到 package.json 的脚本部分:

"scripts": {
    "test": "mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list",
  }

然后您可以使用npm test 轻松访问它。请注意,npm 始终运行本地安装的摩卡,而不是全局摩卡。它还可以让你做一些聪明的事情,比如运行多个脚本,比如How to run mocha and mocha-phantomjs tests from one "npm test" command in node.js?。最后,它可以在 Windows 以及 Unix 和 OS X 中可靠地运行。

【讨论】:

  • 不,仍然只运行两个测试。 mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list ․ CordBloodUnit 应设置 attrs: 0ms ․ CordBloodUnit #getMatchCount 应该得到等位基因的匹配计数:0ms 2 通过(2ms)
  • 我想我应该问问 mocha 项目的人为什么会这样
【解决方案2】:

试试./node_modules/.bin/_mocha

【讨论】:

    【解决方案3】:

    确保您的所有测试文件都具有 .coffee 扩展名,而不是 .js。我喜欢做的一件事是,将我所有的测试都使用这个模式名称:my_file_test.coffee。全部包含 _test.coffee。

    【讨论】:

      【解决方案4】:

      这也发生在我身上,问题实际上是我有一个 describe() 块,其中没有 it() 调用。希望对某人有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-24
        • 1970-01-01
        相关资源
        最近更新 更多