How can I run code coverage for client side javascript code using grunt?
I have run the client side javascript code test using mocha-phantomjs to be tested using html page, and it works fine, but I couldn't find a way to run code coverage for it.
It will be great if there is some sample code.
I have found away to do it using mocha phantomjs istanbul and browserify through grun.
In the client JS source code, make sure to expose your public var(s) or function(s) though window object, to make it accessible after generating the instrumentation file by browserify. here is an example: https://github.com/shadiabuhilal/js-code-coverage-example/blob/master/src/example.js#L36
devDependencies:
"browserify-istanbul": "^0.2.1",
"chai": "^1.10.0",
"grunt": "^0.4.5",
"grunt-browserify": "^3.7.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-mocha-phantom-istanbul": "^0.2.1",
"mocha": "^2.1.0"
To see full example please check the following repo:
https://github.com/shadiabuhilal/js-code-coverage-example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With