2011-11-03 3 views
7

coffeescript 프로젝트 내에서 작동하는 nodeunit 모듈을 얻으려고하고 있지만 기본 테스트를 실행할 수없는 것으로 보입니다. 가 여기 내 예제 커피 스크립트 은 'nodeunit'불행하게도node.it 모듈을 coffeescript 파일과 함께 사용하는 방법

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 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

사람이 나를 그냥 단순화를 얻을 수 있도록 할 수 있습니다 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하는 것을 고려하십시오. 우리는 스택 오버 플로우에 대한 cred를 위해 작업합니다. :) –

0

커피 스크립트 버전이 1.7 이상인 경우 bug #247이 표시 될 수도 있습니다. 그 중 patch을 제출했습니다.

관련 문제