Testing Multiple Versions of Node

We often get requests on how to test with multiple versions of Node.JS, it is actually quite simple.

For instance, if we wanted to run tests on 0.10, 0.12, and 4.0 you would add something like this to your circle.yml file.

test:
  override:
    - nvm use 0.10 && ./runtest
    - nvm use 0.12 && ./runtest 
    - nvm use 4.0 && ./runtest 
4 Likes

How does this work with parallelism? How can I run a different version of node in each parallel container?

1 Like

You should be able to specify in circle.yml which node should run which command as shown here[1].

[1] https://circleci.com/docs/1.0/parallel-manual-setup/

it’s not safe to assume your app is tested by only doing nvm use across versions, that’s not enough isolation.
at least you should also use the right version of npm matching the node version, and for each, rm -rf node_modules && npm install again.
and that’s assuming any custom hooks on your package.json aren’t doing anything that contaminates the following tests.
I guess the only completely safe way would be to use separate containers.

1 Like

If you’re prepared to test in parallel as suggested by Lev above you can get better isolation by adding the following to circle.yml:

dependencies:
  pre:
    - case $CIRCLE_NODE_INDEX in 0) NODE_VERSION=4 ;; 1) NODE_VERSION=5 ;; 2) NODE_VERSION=6 ;; esac; nvm install $NODE_VERSION && nvm alias default $NODE_VERSION

test:
  override:
    - ./<your-test-command>

This example assumes that parallelism is set to 3x.