First I scaffolded out an angular project using the Yeoman generator-angular generator.
$ 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
...
The Karma tests with grunt test
don't work right out of the box, so you need to install some additional dependencies manually:
$ npm install karma-jasmine --save-dev
$ npm install karma-chrome-launcher --save-dev
After this though, the tests still fail. From the errors it appears as if the coffeescript files are being interpreted as 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
It appears that a new generator-angular CoffeeScript project requires the karma-coffee-preprocessor
dependency as well as a preprocessors configuration object.
I've opened a pull request for this to be fixed in the generator-karma generator but in the meantime you can fix it manually by first running the following on the command line:
npm install --save-dev karma-chrome-launcher karma-firefox-launcher karma-safari-launcher karma-opera-launcher karma-ie-launcher karma-jasmine karma-coffee-preprocessor
And then add this to karma.conf.js
:
preprocessors: {
'**/*.coffee': ['coffee']
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With