Code coverage tests in ES6, TypeScript or CoffeeScript
Generally speaking, I like my projects to have a code coverage check to ensure it has above a certain level of coverage. I usually set this quite high (typically 100%) so it’s actually a challenge and it enforces a good level of rigour.
Yup. I still, use Grunt as it meets my needs well enough that I don’t yet need to move to Gulp. I keep my tasks lean, so there’s no appreciable speed difference. And I’ve been using Grunt for about 3 years, so have pretty much every task I’ll ever need in a repo somewhere which I’d need to write in Gulp if I were to switch. I’ve toyed with the idea, but I’ve never found enough benefit to justify the cost.
Enter Remap Istanbul. This rewrites your generated coverage files to look the same as your source code (to my mind, Istanbul should support this natively and hopefully they will one day). This, however, doesn’t help you with generating the coverage files or check that you’ve met the coverage thresholds.
How I Do It
As a workflow, this is the process I follow:
- Transpile my source code and unit test files
- Run the transpiled tests through Istanbul and generate the coverage files
- Rewrite the coverage files
- Check that the thresholds are met
And to illustrate, this is my
Gruntfile.js. You need to install these dependencies to run:
- Previous: Aaarrrggghhh!!! 'use strict' in TypeScript...
- Next: Code Coverage for Karma/Angular/Browserify/ES6