Code coverage

Karma can also give you code coverage reports. Code coverage indicates how much of your code is tested. For example, if you have two functions, each 10 lines long, and you test one, you should have a code coverage of 50%. Code coverage is a little more sophisticated than that, as we will see in a moment.

Before we start, we will need to install the karma-coverage plugin:

npm install karma-coverage --save-dev

After that, we need to change our configuration, so Karma will run the coverage plugin. We will need to indicate the coverage preprocessor, the coverageReporter, and the type of reporter:

preprocessors: { '../scripts/*.js': ['coverage'] }, reporters: ['progress', 'coverage'], coverageReporter: { reporters: [ { type : 'html', ...

Get Continuous Integration, Delivery, and Deployment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.