Setting up test coverage using Mocha, Istanbul, NYC with TypeScript
It’s a pleasure to work with a project that uses TypeScript for your source code and tests, although setting up test coverage can be a bit tricky. I recently started a project that uses TypeScript for source as well as the tests.
I used Mocha to run the test and nyc
for generating test coverage. You will also need to npm install --save-dev source-map-support
.
It tooks many hours to figure out a solution that works end-to-end so I wanted to share the end result.
Here is what the npm script section is looking like:
Mocha configuration is located in test/mocha.opts
:
That’s it! Now you can run npm test
to run your tests and get coverage report.
Now all test coverage reports are mapped using sourcemaps.