我试图让nodeunit模块在coffeescript项目中工作,但似乎连一个基本的测试都无法运行。下面是我的例子-- Coffeescript require 'nodeunit‘
test = true
test2 = false
exports.testSomething = (test) ->
test.expect(1)
test.ok(true, "this should pass")
test.done()
exports.testSomethingElse = (test2) ->
test2.expect(1)
test2.ok(false, "this should fail")
test2.done()不幸的是,当我运行'$ nodeunit example.coffee‘时,我得到了错误输出:
example.coffee:4 exports.testSomething = (test) -> ^ module.js:296投掷错误;^ SyntaxError:意外令牌>在Module._compile (module.js:397:25) at Object..js (module.js:408:10) at Module.load (module.js:334:31) at Function._load (module.js:293:12) at require (module.js:346:19) at /usr at /usr/local/lib/node/nodeunit/deps/异步c.js:508:13在/usr/local/lib/node/nodeunit/deps/async.js:118:13 at /usr/local/lib/node/nodeunit/deps/async.js:134:9 at /usr/local/lib/node/nodeunit/deps/async.js:507:9
有人能帮我使用Node.js在Coffeescript中运行一个简单的测试吗?
提前感谢
发布于 2011-11-03 20:09:47
你的例子对我来说很好。可能是在nodeunit有CoffeeScript支持之前,您正在使用它的旧版本;
npm install -g nodeunit要更新到最新版本,请执行以下操作。
如果失败,那么我怀疑这是路径问题,所以当nodeunit尝试执行require 'coffee-script'时,它就失败了。
先做
npm install -g coffee-script并注意输出的最后一行,它应该如下所示
coffee-script@1.1.2 /usr/local/lib/node_modules/coffee-script现在快跑
echo $NODE_PATH在我的例子中是/usr/local/lib/node_modules。您需要将NODE_PATH设置为npm创建的coffee-script目录的父目录,方法是添加如下一行
export NODE_PATH=/usr/local/lib/node_modules对于~/.profile或~/.bashrc或其他任何东西,您的shell在它启动时运行,并重新启动您的shell。然后,每当您从机器上的任何节点应用程序执行require 'coffee-script'时,它都会找到CoffeeScript库。
https://stackoverflow.com/questions/8000912
复制相似问题