Last Updated: October 30, 2021
·
2.662K
· skeep

Enable Istanbul in Yeoman angular generator

Istanbul test coverage report is awesome. Good thing is it comes canned with Karma Test runner. If you are using angular generator for yeoman, it do not come pre-configured though. But enabling it is easy.

First you need to enable the reporter in karma.conf.js
Replace the below line

reporters = ['progress'];

with this

reporters = ['progress','coverage'];

//coverage reporter type
coverageReporter = {
    type : 'html'
}

This adds the coverage reporter. But we need tell which files it need to cover.

To do that add the below lines anywhere in your karma.conf.js file

//initiate istanbul code coverage report
preprocessors = {
    'app/scripts/**/*.js': 'coverage'
};

That's it. Every time you run test task, the coverage report should get generated in the root folder.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

Angular apps often share the page with analytics and payment scripts that are not Angular modules. Those scripts execute on the same origin as the framework.

Security insights from Cside