getting nyc/istanbul coverage report to work with typescript
Recently I found a satisfiable solution by using "target": "es6"
instead of es5
in tsconfig.json
's compilerOptions
. While changing target
directly in tsconfig.json
may not be an option as it affects build, the other tip is to use TS_NODE_COMPILER_OPTIONS='{"target":"es6"}
which can be added directly in package.json
scripts
as i.e. :
"test:coverage": "TS_NODE_COMPILER_OPTIONS='{\"target\":\"es6\"}' nyc npm run test:unit",
where test:unit
is whatever way being used to run actual tests (in my case just gulp mocha
.
NOTE: I've also updated nyc
to latest 11.1.0 and ts-node
to 3.3.0
as suggested on https://github.com/istanbuljs/nyc/issues/618 thread
I'm not sure this is the same problem but I'll put this here in case it helps future developers...
I wasn't getting any coverage data until I added exclude-after-remap=false
to the nyc section of my package.json
.
This is listed in the documentation but not in a very prominent way (IMO).