Wednesday, April 27, 2016

browserify, jasmine, karma, istanbul

Browserify lets you require('modules') in the javascript by bundling up all of your dependencies.
Jasmine is used to do the javascript unit test.
Karma is the javascript unit test runner.
Istanbul is used for javascript coverage.

I have my javascript using browserify. Then I created jasmine to test my javascript. Then I configured Karma to run my jasmine. The last step I want to get Istanbul coverage report to see how many code is not covered by unit test.

It is all good until I try to integrate Istanbul. Karma supports Istanbul out of box by Karma coverage. But the problem is that it does not with js in Browserify style.

After did a lot of try and reading a lot of posts from internet, I found a workaround. Here is the my karma.conf.js The tricky is that in "preprocessors" only put in "browserify", without "coverage". The karma tutorial let you put in "coverage" here if you want to have Istanbul coverage report. But I found it did not work with browserify. In "Browserify", we weave in Istanbul. Here is the dependencies needed. My project is a java maven project. I also want the javascript unit test is executed every time the build happens. In my pom.xml, I need add plugin The last execution is running karma.

No comments:

Post a Comment