我在写一个(更大的)使用Coffeescript和node.js的单元测试集。我建立使用咖啡的文件“监视”选项(-w)如何在Coffeescript中连续编译/单元测试?
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']
哇 - 20秒?我从来没有一个花费那么长时间编译的CoffeeScript项目。甚至2秒,就此而言。你可以尝试编译你的每个'.coffee'文件,看看哪个(如果有的话)需要超过1秒才能编译?然后发布报告到[问题跟踪器](https://github.com/jashkenas/coffee-script/issues)。 –
这可能不是编译 - 也许它是node.js开销?我正在加载8个左右的需求。测试本身似乎在约300ms内执行。 –
你的意思是你在测试中加载了8个左右'require's?你可以尝试对他们每个人进行计时,看看哪些时间超过几毫秒? –