getting nyc/istanbul coverage report to work with typescript : <p>I'm struggling to get proper coverage with nyc/istanbul for my typescript/mocha/gulp project. I've tried a number of approaches, some of them seem to be unable to use source maps and other fails due to <code>ts-node</code>/<code>tsc</code> errors. My current setup is:</p>

<p><code>nyc</code> relevant config in <code>package.json</code></p>

<pre><code>"scripts": {
    "test:coverage": "nyc npm run test:unit",
    "test:unit": "gulp mocha"
}
"nyc": {
    "check-coverage": true,
    "all": true,
    "extension": [
      ".js",
      ".jsx",
      ".ts",
      ".tsx"
    ],
    "include": [
      "src/**/!(*.test.*).[tj]s?(x)"
    ],
    "reporter": [
      "html",
      "lcov",
      "text",
      "text-summary"
    ],
    "report-dir": "docs/reports/coverage"
  }
</code></pre>

<p><code>gulpfile.js</code> <code>mocha</code> relevant part</p>

<pre><code>const SRC_DIR = path.join(__dirname, 'src');
const SRC_FILES = path.join(SRC_DIR, '**', '*.[jt]s?(x)');
const TEST_FILES = path.join(SRC_DIR, '**', '*.test.[jt]s?(x)');
const MOCHA_CONFIG = {
    src: [
        TEST_FILES
    ],
    watchSrc: [
        SRC_FILES,
        TEST_FILES
    ],
    mocha: {
        // compilers: [
        //     'ts:ts-node/register',
        //     'tsx:ts-node/register'
        // ],
        require: [
            './tests/setup.js',
            'ignore-styles',
            'source-map-support/register'
        ]
    }
};
gulp.task('mocha', mocha(MOCHA_CONFIG));
</code></pre>

<p><code>tsconfig.json</code></p>

<pre><code>{
  "compilerOptions": {
    "baseUrl": "./",
    "rootDir": "./src",
    "outDir": "./build",
    "allowJs": true,
    "module": "commonjs",
    "target": "es5",
    "lib": ["es5", "es6", "dom"],
    "sourceMap": true,
    "inlineSourceMap": false,
    "inlineSources": false,
    "experimentalDecorators": true,
    "noUnusedParameters": true,
    "noUnusedLocals": true,
    "jsx": "react",
    "moduleResolution": "node"
  },
  "exclude": [
    "docs",
    "tests",
    "**/*.test.js",
    "**/*.test.jsx",
    "**/*.test.ts",
    "**/*.test.tsx",
    "tools",
    "gulpfile.js",
    "node_modules",
    "build",
    "typings/main",
    "typings/main.d.ts"
  ],
  "awesomeTypescriptLoaderOptions": {
    "useCache": true,
    "useBabel": true
  }
}
</code></pre>

<p>With the above setup coverage produces results for all the files but they are incorrect for TS files most probably due to source maps not being used (i.e. report shows no coverage for lines which are comments and the numbers seems to be wrong as well).</p>

<p>With a number of variant approaches tried with no success one of the most commonly suggested is to add <code>"require": ["ts-node/register"]</code> to <code>nyc</code> configuration yet then I'm getting errors complaining about i.e. <code>gulpfile.js</code>, <code>docs/reports/coverage/lcov-report/prettify.js</code> and number of other JS files to be <code>not under 'rootDir'</code> which is correct yet it is not clear why <code>ts-node</code> tries to process all the files out of <code>src</code> even if they are excluded in <code>tsconfig.json</code> (still the configuration gets really complex).</p>

<p>I'll appreciate any suggestion which way to go to get proper coverage report for TS files.</p>
