如何在Coffeescript中进行连续构建/单元测试?

Tod*_*ery 5 coffeescript

我正在使用Coffeescript和node.js编写一组(更大)的单元测试.我使用咖啡"watch"选项(-w)构建文件

coffee -w -b -c -o web/ src/
Run Code Online (Sandbox Code Playgroud)

我的问题是运行单元测试需要20秒(我假设编译为.js).

如果可能的话,我想自动运行(编译的.js)文件更改的单元测试,这将消除漫长的等待结果.

我目前的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']
Run Code Online (Sandbox Code Playgroud)

Tre*_*ham 1

看看我的 connect-assets 项目的 Cakefile:https://github.com/adunkman/connect-assets/blob/master/Cakefile

它比 sstephenson 的(我假设您的示例源自该示例)复杂一点,但它展示了如何监视文件目录的更改并通过重新运行测试来响应这些更改。