I am going to talk about one very specific item in this article since it barely exists anywhere on the internet. How to run both your integration tests and unit tests in such a way that you can actually see the whole code coverage.
I am not going to tell you to download another plugin, I want you to see how this will actually work.
I am not going to tell you how to install jasmine-node, nor how to make jasmine assertions, nor how to install mocha, nor convince you that you need unit tests, nor convince you that you need grunt, nor anything else.
- Have jasmine-node installed either globally or locally. If locally you need to run it in this manner
- Have istanbul installed either globally or locally.
- Have your integration tests written in jasmine.
- Have your unit tests written in jasmine.
- Be able to run your jasmine unit and integration tests successfully on their own without istanbul in the picture. Running something like
./node_modules/jasmine-node/bin/jasmine-node tests/runner_spec.js --captureExceptions --verbose
You should get output like this:
- Start your node app using istanbul cover. For example if you usually do
node app.js you will now do
./node_modules/istanbul/lib/cli.js cover --report none app.js This will check the coverage of the integration tests on your node app and not write the reports right away (
- Run your tests using istanbul. If you normally run your jasmine tests by doing the following,
./node_modules/jasmine-node/bin/jasmine-node ./tests/runner_spec.js --verbose --captureExceptions you will instead run it like this
./node_modules/istanbul/lib/cli.js cover --report none --dir coverage/unit ./node_modules/jasmine-node/bin/jasmine-node -- ./tests/runner_spec.js --verbose --captureExceptions
Notice how I have picked an alternate directory for my unit tests with the '--dir' option. I want them to go into the
./coverage/unit folder. Also, any options that you want to pass to jasmine-node you will need to place after
- End those processes, you should see some coverage information as you do so.
- Once all your tests have run, type the following
- Go to your
./coverage/lcov-report/index.html and check out your coverage levels. Not bad!!!
NodeJS, iOS, Swift, MeteorJS, D3, 3D printing, salsa dancing, programming, and being critical of apps. Constantly learning by doing, developing apps on apps on apps.