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']
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With