45

I have a rails project and am running tests for my JavaScript test (Jasmine) through Karma

.travis.yml file

language: ruby
rvm:
  - 2.0.0
script:
  - RAILS_ENV=test bundle exec rake --trace db:migrate test
  - karma start --single-run --browsers PhantomJS test/karma/config/unit.js

Travis fails saying it does not find karma. is there a way to define node_js as another language and install karma on the build VM?

K-Yo
  • 1,250
  • 10
  • 14

3 Answers3

52

It is not possible yet to have several languages on travis configuration file.

On the other hand, all environments run node.js. The following script does the trick:

language: ruby
rvm:
  - 2.0.0
before_script:
  - npm install karma
script:
  - RAILS_ENV=test bundle exec rake --trace db:migrate test
  - karma start --single-run --browsers PhantomJS test/karma/config/unit.js

Help found on an old thread in a google group

0xcaff
  • 13,085
  • 5
  • 47
  • 55
K-Yo
  • 1,250
  • 10
  • 14
  • 1
    My [.travis.yml](https://github.com/OrangeTux/Goppetto/blob/develop/.travis.yml) with config to run both Go and Javascript tests. – OrangeTux Nov 12 '14 at 22:29
  • 2
    Here's [how I run an **updated nodejs**](http://entulho.fiatjaf.alhur.es/guias/how-to-use-node-along-with-other-language-on-travis-ci/) installation along with any other language. – fiatjaf Dec 10 '15 at 20:14
5

K-Yo's answer got me moving in the right direction, but far short of success. Here is what I needed:

First in my .travis.yml:

language: ruby

rvm:
  - 2.1.1

before_script:
  - psql -c 'create database spokenvote_test;' -U postgres
  - cp config/database.travis.yml config/database.yml
  - rake db:test_prep
  - npm install karma
  - npm install karma-jasmine
  - npm install karma-coverage
  - npm install karma-phantomjs-launcher
  - npm install karma-coffee-preprocessor

script:
  - bundle exec rspec spec # basic for ruby
  - node_modules/karma/bin/karma start config/karma.conf.js --single-run --browsers PhantomJS

Then I also placed this code in my package.json, though I'm not sure if it was needed:

"devDependencies": {
    "karma": "~0.12",
    "karma-jasmine": "~0.2",
    "karma-coverage": "~0.2.6",
    "karma-phantomjs-launcher": "~0.1.4",
    "karma-coffee-preprocessor": "~0.2.1"
},

Finally, I learned that Travis is case sensitive, so:

'bower_components/jquery/dist/jquery.min.js',

in my karma.conf.js needed to be:

'bower_components/jQuery/dist/jquery.min.js',
Kim Miller
  • 886
  • 8
  • 11
2

When the language key in .travis.yml is set to node, Travis will run nvm install 0.12 at the beginning of the build. Similarly, for a Ruby project, Travis will run rvm use 2.2.2 --install --binary --fuzzy at the beginning of the build.

I've had success running both commands in a Bash build

Vinson Chuong
  • 347
  • 2
  • 4