2011-11-03 6 views
7

coffeescriptプロジェクト内でnodeunitモジュールを動作させようとしていますが、基本的なテストを実行することさえできません。node.itモジュールを 'coffeescript'ファイルで使用する方法

example.coffee:4 exports.testSomething = (test) -> ^

module.js:296 throw err; ^SyntaxError: Unexpected token > at 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/local/lib/node/nodeunit/lib/nodeunit.js:75:37 at /usr/local/lib/node/nodeunit/deps/async.js:508:13 at /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

誰も私だけの簡略化を得るのを助けることができます:ここに は、私が実行したときのCoffeeScript が、私はエラー出力を取得する '$ nodeunit example.coffee'、 '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() 

を必要と私の例ですNode.jsを使用してCoffeescriptでテストして実行しますか?

ありがとうございます事前にありがとうございます

答えて

14

あなたの例は私にとってうまく動作します。 CoffeeScriptをサポートする前に、古いバージョンのnodeunitを使用している可能性があります。お試しください。

npm install -g nodeunit 

最新バージョンに更新してください。

これが失敗すると、ノードのユニットがrequire 'coffee-script'を実行しようとすると失敗するため、パスの問題と思われます。

まず今私の場合です

echo $NODE_PATH 

を実行

npm install -g coffee-script 

を行うと、

[email protected] /usr/local/lib/node_modules/coffee-script 

ようになりべき、出力の最後の行に注意してください/usr/local/lib/node_modules。あなたは~/.profileまたは~/.bashrcまたは任意の他、起動時に、それはあなたのシェルの実行であるに

export NODE_PATH=/usr/local/lib/node_modules 

のような行を追加することで、作成したNPM coffee-scriptディレクトリの親ディレクトリにNODE_PATHを設定し、シェルを再起動する必要があります。そして、マシン上の任意のノードアプリケーションからrequire 'coffee-script'を実行するたびに、CoffeeScriptライブラリが見つかります。

+0

現象的な探偵研究。 My $ NODE_PATHは空ですが、私の他のモジュールは気にしませんでした。どうもありがとうございました。 –

+0

@ user1028416あなたは彼の答えを正しいものとしてマークする必要があります。あなたがそれにいる間は、答えを+1することを検討してください。私たちは、Stack Overflowに関するcredについて働いています。 :) –

0

あなたのコーヒースクリプトがバージョン1.7以降の場合は、bug #247に苦しんでいる可能性があります。これはpatchです。

関連する問題