我在寫一個(更大的)使用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?你可以嘗試對他們每個人進行計時,看看哪些時間超過幾毫秒? –