S
S
sanex33392016-06-18 12:25:26
Software testing
sanex3339, 2016-06-18 12:25:26

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

I end up with a message
No coverage information was collected, exit without writing coverage information

Has anyone already set up such a bundle?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2016-06-18
@sanex3339

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 question

Ask a Question

731 491 924 answers to any question