Answer the question
In order to leave comments, you need to log in
Istanbul + Typescript + Mocha - how to set up code coverage correctly?
I set up a bunch of Typescript + Mocha, the tests work, everything is ok.
Now I want to shove Istanbul here, and here is the problem:
All tests are written in TypeScript. The code under test is written in TS, collected by Webpack into 1 file.
Istanbul is started with the command:
istanbul cover _mocha -- -R spec --require ts-node/register test/**/*.ts
No coverage information was collected, exit without writing coverage information
Answer the question
In order to leave comments, you need to log in
As a result, I did this:
For tests, all .ts files (including tests) are compiled into a tmp directory, without bundling into 1 file.
In this directory, we run test specs that hook the compiled .js files.
After running the tmp tests, we delete the directory.
In the end, everything is ok, Istabul version 1.0.0-alpha.2 is able to source-map, so it eventually shows everything based on the original .ts files.
"test:compile": "tsc -p tsconfig-test.json",
"test:full": "npm run test:compile && istanbul cover _mocha -- test-tmp/test/**/**.spec.js && npm run test:removeTestTmpDir",
"test:mocha": "npm run test:compile && mocha -- test-tmp/test/**/**.spec.js && npm run test:removeTestTmpDir",
"test:removeTestTmpDir": "rm -rf test-tmp",
"test": "npm run test:full",
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question