Thanks to @mohsen1's post the following is the minimum recommended configuration to get accurate TypeScript coverage with mocha. With this configuration, the all: true and cache: true options should work.
You will also need to npm install --save-dev source-map-support, which will also require that you have sourcemaps configured in your tsconfig.json. Inline, or not, as long as one is enabled.
package.json{
"scripts": {
"test": "nyc mocha"
},
"nyc": {
"extension": [
".ts",
".tsx"
],
"exclude": [
"**/*.d.ts"
],
"reporter": [
"html"
],
"all": true
}
}
test/mocha.opts--require ts-node/register # replace with ts-node/register/transpile-only if you have custom types
--require source-map-support/register
--recursive
<glob for your test files>
If you're having trouble, try looking at the existing TypeScript issues for troubleshooting steps.