How to run Node.js and Ruby tests within one project on Travis CI
Asked Answered
G

1

6

I have a repo that contains multiple components, most of them in JavaScript (Node.js) and one written in Ruby (Ruby on Rails). I'd like to have one .travis.yml file that triggers one build that runs all the tests for each of the components. According to this Travis CI Google Group thread, there is no official support for this for now.

My directory structure looks like this:

. ├── buildserver ├── core ├── extensions ├── webapp ├── Vagrantfile ├── package.json ├── .travis.yml └── Makefile

I want to be able to run specific versions of Ruby (2.2.2) and Node.js (0.12.2). I already have a make target, so make test runs appropriate test suite in each subdirectory.

Goddaughter answered 5/7, 2015 at 21:26 Comment(0)
G
18

It turns out that every VM, that runs your isolated test suite on Travis CI, comes with Node.js and Ruby pre-installed. By default you get Ruby 1.9.3 and Node.js 0.12.2 (but that may change as Travis team updates their environment), so even though you can only specify one language (e.g. language: Ruby) in your .travis.yml file, you can still run both Ruby and Node.js programs on Travis CI VM.

I decided to go with Node.js language set-up and install appropriate Ruby version (but I could have done the opposite with the same effect).

Here is my .travis.yml config file:

language: node_js
node_js:
  - 0.12.2
addons:
  postgresql: "9.4"
before_install:
  - rvm install 2.2.2
install:
  # run whatever you have to do here. I have a Makefile that lets you install
  # all Node.js-related or Ruby-related dependencies as one step.
  - make npm
  - make bundler
before_script:
  # My Rails app lives in a subdirectory. I want to make sure that
  # my database is ready before I start running RSpec tests
  - psql -c 'create database test_db;' -U postgres
  # I use separate database.yml config for Travis CI
  - cp webapp/config/database.travis.yml webapp/config/database.yml
script:
  # `test` target executes `bundle exec rspec spec` and `npm run test`
  # in all appropriate subdirectories
  - make test
Goddaughter answered 12/7, 2015 at 23:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.