2012-03-30 20 views
42

Makefile - Content: directory principaleImpossibile eseguire Mocha con CoffeeScript

REPORTER = dot 

all: build 

build: 
    @./node_modules/coffee-script/bin/coffee \ 
     -c \ 
     -o lib src 

clean: 
    rm -rf lib 
    mkdir lib 

watch: 
    @./node_modules/coffee-script/bin/coffee \ 
     -o lib \ 
     -cw src 

test: 
    @./node_modules/mocha/bin/mocha \ 
     --reporter $(REPORTER) \ 
     test/*.coffee 

.PHONY: build clean watch test 

Il progetto ha una cartella di prova con due file: mocha.opts e example.coffee

example.coffee - Content

describe "feature", -> 
    it "should add two numbers", -> 
     (2+2).should.equal 4 

In esecuzione make test, ottenendo il seguente errore:

cribe 'feature', 
     ^^^^^^^^^ 

node.js:201 
     throw e; // process.nextTick error, or 'error' event on first tick 
      ^
SyntaxError: Unexpected string 
    at Module._compile (module.js:429:25) 
    at Object..js (module.js:459:10) 
    at Module.load (module.js:348:31) 
    at Function._load (module.js:308:12) 
    at Module.require (module.js:354:17) 
    at require (module.js:370:17) 
    at /home/my_username/testcode/coffeepress/node_modules/mocha/bin/_mocha:261:27 
    at Array.forEach (native) 
    at load (/home/my_username/testcode/coffeepress/node_modules/mocha/bin/_mocha:258:9) 
    at Object.<anonymous> (/home/my_username/testcode/coffeepress/node_modules/mocha/bin/_mocha:249:1) 
    at Module._compile (module.js:441:26) 
    at Object..js (module.js:459:10) 
    at Module.load (module.js:348:31) 
    at Function._load (module.js:308:12) 
    at Array.0 (module.js:479:10) 
    at EventEmitter._tickCallback (node.js:192:40) 

L'esecuzione di Mocha con file js ha esito positivo, ma non è possibile eseguirla con CoffeeScript. Voglio davvero - per brevità del codice.

Guida.

risposta

89

Come di Mocha 1.0:

coffee-script is no longer supported out of the box. CS and similar transpilers may be used by mapping the file extensions (for use with --watch) and the module name. For example --compilers coffee:coffee-script with CoffeeScript 1.6- or --compilers coffee:coffee-script/register with CoffeeScript 1.7+.

(Citando http://visionmedia.github.io/mocha/#compilers-option) Quindi, è necessario aggiungere la riga

--compilers coffee:coffee-script/register 

o, per CS < = 1.6.x,

--compilers coffee:coffee-script 

nel tuo file mocha.opts.

28

Da CoffeeScript 1.7 in poi, l'opzione dovrebbe essere:

--compilers coffee:coffee-script/register 

Un issue è stata depositata sul sito GitHub di Mocha.

+0

Forse aggiornare questo per riflettere v2 in poi e quindi la mancanza di un trattino. 'coffee: coffeescript/register' ha funzionato per me – aaaaaa

0

avevo bisogno di due modifiche alle mie args moka per arrivare a questo lavoro:

--require coffee-script/register 
--compilers coffee:coffee-script/register