- It’s C component that needs to be (sort of manually) installed
- It requires you to implement a mechanism within your modules exports to be able to switch between the the instrumented code and the original code (usually done with a runtime variable i.e.
Before starting it’s worth understanding a little bit about how it integrates with your code. It works by having hooks hooks into where your code includes it’s libs. The two hooks are:
If your tests don’t include your lib files via this mechanism then the instrumentation won’t work. It’s therefore worth noting that your codebase must conform to CommonJS i.e. the lib files must do
module.export = Lib or
exports.Lib = Lib etc. I’m still looking for a way of doing the instrumentation when require is not used and if I find something I’ll write an update.
Getting it working
istanbul cover _mocha -- -R spec test/spec– the key here is to note that
_mochais being used. This is due to the way that the process is being spawned see here
cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js– this takes the coverage report generated by the previous command and pushes it to coveralls
There are basically a few files you need to modify:
|before_script: 'npm install -g istanbul && npm install -g mocha'|
|script: 'make test-cov'|
|after_success: 'make coveralls'|
|istanbul cover _mocha — -R spec test/spec|
|cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js|
- I’m using mocha as a test framework but any other can be used.
- I’m assuming you’re already familiar with travis and coveralls and haven’t covered any setup information here.
- I’m using Make but it’s not required. The commands are the same though.