不能与CoffeeScript的运行摩卡
问题描述:
的Makefile - 内容:不能与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
项目根目录下有两个文件,一个测试文件夹:mocha.opts和example.coffee
example.coffee - 内容
describe "feature", ->
it "should add two numbers", ->
(2+2).should.equal 4
在运行make test
,得到以下错误:
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)
使用js文件运行Mocha成功,但无法使其与CoffeeScript一起运行。我真的想 - 为了代码简洁。
请指导。
答
至于摩卡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+.
(报价http://visionmedia.github.io/mocha/#compilers-option)所以,你需要添加行
--compilers coffee:coffee-script/register
,或者对于CS < = 1.6.x版,
--compilers coffee:coffee-script
到您的mocha.opts
文件。
答
我需要两个改变我的摩卡args设置为得到这个工作:
--require coffee-script/register
--compilers coffee:coffee-script/register
也许更新这起进而体现V2缺乏一个破折号。 '咖啡:coffeescript/register'为我工作 – aaaaaa 2018-01-23 19:52:37