node.js - mocha 单元测试返回 0 作为未捕获异常的退出代码

标签 node.js unit-testing continuous-integration mocha.js

我有一个适用于我当前应用的测试套件。

有时我会引入错误,这会导致抛出未捕获的异常。

我可以在手动运行单元测试时看到错误。但是当我将它与我们的 CI 系统集成时,该过程仍然返回 0,就好像一切正​​常。

由于这个肯定的退出代码,我们无法检测到错误。我做错了什么?

最佳答案

感谢 nodeJS 域,我终于解决了这个问题:

这是我的 test/server.coffee,我在其中设置测试:

d = require("domain").create()

# set up error handling to exit with error code on uncaught exceptions
d.on "error", (err) ->
  console.log "Uncaught Exception:", err.message
  console.log err.stack

  process.exit(1)

before (done) ->
  d.run ->
    # bootstrap application
    done()

这会捕获所有错误,打印跟踪并以退出状态 1 退出。

关于node.js - mocha 单元测试返回 0 作为未捕获异常的退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18786325/

相关文章:

node.js - 如何在 Bookshelf js 中使用 groupBy?

unit-testing - 如何使用 Angular 翻译进行单元测试

azure - 按计划仅运行一项构建管道任务

node.js - 安装和使用 NVM/Node.js 命令时获取 "mkdir: cannot create directory..."

node.js - Express js中通过id删除mongodb文档

javascript - Node.js NodeList 到 XML 字符串

c++ - 单元测试模板代码

angularjs - Promise.catch() 不会在 AngularJS 单元测试中捕获异常

continuous-integration - Gitlab-ci:扩展脚本部分

unit-testing - 从TFS2010运行xUnit测试