首先,我使用Yeoman发电机角度发生器搭建了一个角度项目。
$ mkdir project && cd project
$ yo angular --coffee
...
[?] Would you like to use Sass (with Compass)? Yes
[?] Would you like to include Twitter Bootstrap? Yes
[?] Would you like to use the Sass version of Twitter Bootstrap? Yes
[?] Which modules would you like to include? angular-resource.js, angular-route.js
...
Karma使用grunt test
don't work right out of the box进行测试,因此您需要手动安装一些其他依赖项:
$ npm install karma-jasmine --save-dev
$ npm install karma-chrome-launcher --save-dev
在此之后,测试仍然失败。从错误看,好像coffeescript文件被解释为JavaScript。
$ grunt test
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.1 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
WARN [watcher]: Pattern "/Users/karl/projects/resources/test/mock/**/*.coffee" does not match any file.
INFO [Chrome 33.0.1750 (Mac OS X 10.9.2)]: Connected on socket W35K_wuKKVx2BweeP-F2 with id 48564140
Chrome 33.0.1750 (Mac OS X 10.9.2) ERROR
Uncaught SyntaxError: Unexpected token >
at /Users/karl/projects/resources/app/scripts/app.coffee:7
Chrome 33.0.1750 (Mac OS X 10.9.2) ERROR
Uncaught SyntaxError: Unexpected string
at /Users/karl/projects/resources/app/scripts/controllers/header.coffee:4
Chrome 33.0.1750 (Mac OS X 10.9.2) ERROR
Uncaught SyntaxError: Unexpected string
at /Users/karl/projects/resources/app/scripts/controllers/main.coffee:4
Chrome 33.0.1750 (Mac OS X 10.9.2) ERROR
Uncaught SyntaxError: Unexpected string
at /Users/karl/projects/resources/test/spec/controllers/main.coffee:3
答案 0 :(得分:10)
新的生成器角度CoffeeScript项目似乎需要karma-coffee-preprocessor
依赖项以及预处理程序配置对象。
我已经打开a pull request以便在生成器 - 业力生成器中修复此问题,但在此期间您可以通过首先在命令行上运行以下命令来手动修复它:
npm install --save-dev karma-chrome-launcher karma-firefox-launcher karma-safari-launcher karma-opera-launcher karma-ie-launcher karma-jasmine karma-coffee-preprocessor
然后将其添加到karma.conf.js
:
preprocessors: {
'**/*.coffee': ['coffee']
},