• Blog
  • Talks
  • Investing
  • About

Instructing Cakefile to exit with error if a vows test fails

2011-12-21This post is over 2 years old and may now be out of date

(1 minute read)

I'm using the vows "behaviour-driven development" framework to test the squel Javascript library. I have a Cakefile which acts as my build script and inside it there is function which runs all of my tests. I decided to hook it up to the excellent Travis CI automated build system to ensure continuous testing on commits. One of the problems I had was that cake script exited normally even when one of the vows tests broke.

I came up with this little snippet to ensure that cake exited abnormally (with error code 1) if any of the tests failed:

run_tests = (callback) ->
    options = [
    vows = spawn "#{binpath}/vows", options
    output = ""
    data_handler = (data) ->
        output =+ data if data
        stream_data_handler data
    vows.stdout.on 'data', data_handler
    vows.stderr.on 'data', data_handler
    vows.on 'exit', (status) ->
        if 0 isnt status or (output and -1 isnt output.indexOf("✗ Broken"))
            return process.exit(1)

Essentially it looks for the — Broken string in the vows output - this string only gets output if one or more vows were 'broken'. Now Travis also picks up on test failures. There might be a more elegant way to do the above - if you know give me a shout. Otherwise I hope somebody else finds this useful.

  • Home
  • Blog
  • Talks
  • Investing
  • About
  • Twitter
  • Github
  • Linked-in
  • Email
  • RSS
© Hiddentao Ltd