Execute a Tests With Certain Version of Node.JS

Wondering how to use n to execute mocha tests with certain version of Node.JS?

Consider following Makefile:

REPORTER = dot

test:
@NODE_ENV=test $(ENGINE) ./node_modules/.bin/mocha \
    --reporter $(REPORTER)

.PHONY: test

then command to execute tests with certain version of node.js will looks like:

ENGINE=`n bin 0.4.7` make test

normal command still works seamlessy, i.e.:

make test

Conclusion

The secret is in optional ENGINE variable dynamically set by the n bin <version> command which returns full path to certain version of node.js, e.g. ~/.local/n/versions/0.4.7/bin/node, so, finally command will looks like this:

NODE_ENV=test ~/.local/n/versions/0.4.7/bin/node ./node_modules/.bin/mocha \
    --reporter dot

Comments