【问题标题】:mocha unit test returns 0 as exit code on uncaught exceptionsmocha 单元测试返回 0 作为未捕获异常的退出代码
【发布时间】:2013-09-13 12:27:55
【问题描述】:

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    感谢 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 退出。

    【讨论】:

      猜你喜欢
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多