2011-12-01 55 views
5

我在写一个(更大的)使用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'] 
+1

哇 - 20秒?我从来没有一个花费那么长时间编译的CoffeeScript项目。甚至2秒,就此而言。你可以尝试编译你的每个'.coffee'文件,看看哪个(如果有的话)需要超过1秒才能编译?然后发布报告到[问题跟踪器](https://github.com/jashkenas/coffee-script/issues)。 –

+0

这可能不是编译 - 也许它是node.js开销?我正在加载8个左右的需求。测试本身似乎在约300ms内执行。 –

+1

你的意思是你在测试中加载了8个左右'require's?你可以尝试对他们每个人进行计时,看看哪些时间超过几毫秒? –

回答

1

看看在Cakefile我的连接资产项目:https://github.com/adunkman/connect-assets/blob/master/Cakefile

这是一个有点比sstephenson的更复杂(我假设源自你的例子) ,但它显示了如何通过重新运行测试来观察文件的更改目录并对这些更改作出响应。

+0

在整理出一个node.js问题(从0.4.12-> 0.6.4移动)后,我得到一些运行你的Cakefile的错误: execvp():没有这样的文件或目录 \t(node)warning :检测到可能的EventEmitter内存泄漏。添加了11位听众。使用emitter.setMaxListeners()来增加限制。 \t Traceit: \t at WatchitEmitter。 (events.js:133:17) \t在/Users/chambery/node_modules/watchit/lib/watchit.js:35:13 \t在Object.oncomplete(/用户/贝里/ node_modules/watchit/LIB/watchit .js:141:21) \t致命错误:v8 :: HandleScope :: Close()本地范围已被关闭这是版本问题吗? –

+0

嗯。如果您可以创建一个测试用例来复制此内容,请将其作为[watchit问题跟踪器](https://github.com/TrevorBurnham/watchit/issues)上的错误报告发布。 –

+0

你的Cakefile会诀窍。我仍然无法完全运行测试,但是致命错误是由于链接器错误(?)导致节点升级造成的:http://groups.google.com/group/nodejs/browse_thread/thread/ 877ff6e7434826dd –