Code Coverage for Karma/Angular/Browserify/ES6
If I thought it was painful getting code coverage working for a Node TypeScript project, then getting it working in Karma was even more painful. The worst thing is, there’s precious little (useful) documentation out there for it. After two days worth of experiments, I got it working.
The biggest issue is instrumenting the code correctly, so that the ES6 code is displayed in your tests AND the coverage reports on the ES6 code, not the compiled ES5 code.
Some of the tutorials I found would display the ES6 code, but perform the tests on the ES5 code. For example, when writing a class, the if/else statements generated during transpilation to ensure it was called with
newwere coming out as untested code.
We don’t want to test the
_classCallCheckfunction every time we use a class - that’s the transpiler’s responsibility.
The karma-coverage package requires a fork in GitHub and not the one hosted on npm. This is irritating and I’d like to do something about that. However, for the time being, install it like this…
If you want to run checks to ensure that the coverage meets a minimum threshold, then the instructions in my TypeScript post are the way to do it.
- Previous: Code coverage tests in ES6,...