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

时间:2011-12-01 18:46:25

标签: coffeescript

我正在使用Coffeescript和node.js编写一组(更大)的单元测试。我使用咖啡“watch”选项(-w)

构建文件
coffee -w -b -c -o web/ src/

我的问题是运行单元测试需要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']

1 个答案:

答案 0 :(得分:1)

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

它比sstephenson(我假设您的示例源自)更复杂,但它显示了如何通过重新运行测试来查看文件目录以进行更改并响应这些更改。