Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mocha unit test returns 0 as exit code on uncaught exceptions

I have a test suite for my current app.

Sometimes I introduce an error and this results in an uncaught exception that is thrown.

I can see the error when running the unit tests manually. But when I integrate this with our CI system, the process still returns 0 as if everything was ok.

Because of this positive exit code we can't detect errors. What am I doing wrong?

like image 899
Sebastian Hoitz Avatar asked Sep 13 '13 12:09

Sebastian Hoitz


1 Answers

I finally fixed this issue, thanks to nodeJS domains:

This is my test/server.coffee, where I set the tests up:

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()

This catches all the errors, prints the trace and exits with exit status 1.

like image 134
Sebastian Hoitz Avatar answered Oct 04 '22 17:10

Sebastian Hoitz