Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 487
matb Avatar asked Jul 05 '15 21:07

matb


People also ask

Is Ruby faster than node JS?

Node. js is faster than Ruby in many cases due to its JavaScript engine, even though it has some issues. Ruby is easy to learn as it has numerous tutorials and courses are there for learning in online. It has the most active developer community by which we can learn easily if we stuck anywhere while learning.

Is Ruby on Rails easier than node?

4. Development Time Ruby on Rails also wins when it comes to development times. The web app development framework consists of an integrated webserver. Moreover, it consists of a large library of scripts and generators. As a result, website development is much easier with Ruby on Rails as compared to Node.

Does Ruby use node?

Contrary to Node. js, Ruby on Rails is a framework created to make the development process faster and easier without bottlenecks within the processes. The framework is written in Ruby, which is a multi-purpose language.


1 Answers

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
like image 189
matb Avatar answered Oct 02 '22 15:10

matb