【发布时间】:2013-03-21 01:38:27
【问题描述】:
我正在使用 Coffeescript 和 node.js 编写一组(越来越大的)单元测试。我使用咖啡“watch”选项(-w)构建文件
coffee -w -b -c -o web/ src/
我的问题是运行单元测试需要 20 秒(我假设编译为 .js)。
如果可能,我希望自动对(编译的 .js)文件更改运行单元测试,这样可以消除对结果的长时间等待。
我目前的蛋糕文件:
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 秒的时间来编译?然后将报告发布到issue tracker。 -
这可能不是编译——也许是 node.js 开销?我正在加载 8 个左右的要求。测试本身似乎在大约 300 毫秒内执行。
-
你的意思是你在测试中加载了 8 个左右的
requires?您能否尝试对它们中的每一个进行计时,看看哪个花费的时间超过几毫秒?
标签: coffeescript