Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do continuous build/unit testing in Coffeescript?

Tags:

coffeescript

I'm writing a (ever larger) set of unit tests using Coffeescript and node.js. I build the files using the coffee "watch" option (-w)

coffee -w -b -c -o web/ src/

My problem is that running the unit tests takes 20 secs (I'm assuming for the compile to .js).

If possible, I'd like automatically run the unit tests on a (compiled .js) file change, which would eliminate the long wait for the results.

My current Cakefile:

fs            = require 'fs'
{print}       = require 'sys'
{spawn, exec} = require 'child_process'

build = (watch, callback) ->
  if typeof watch is 'function'
    callback = watch
    watch = false
  options = ['-c', '-b', '-o', 'web', 'src']
  options.unshift '-w' if watch

  coffee = spawn 'coffee', options
  coffee.stdout.on 'data', (data) -> print data.toString()
  coffee.stderr.on 'data', (data) -> print data.toString()
  coffee.on 'exit', (status) -> callback?() if status is 0

task 'test', 'Run the test suite', ->
  build ->
    require.paths.unshift __dirname + "/lib"
    {reporters} = require 'nodeunit'
    process.chdir __dirname
    reporters.default.run ['test']
like image 972
Todd Chambery Avatar asked Nov 13 '22 13:11

Todd Chambery


1 Answers

Take a look at the Cakefile for my connect-assets project: https://github.com/adunkman/connect-assets/blob/master/Cakefile

It's a bit more complex than sstephenson's (which I assume your example is derived from), but it shows how you can watch a directory of files for changes and respond to those changes by re-running tests.

like image 163
Trevor Burnham Avatar answered Dec 06 '22 23:12

Trevor Burnham