monounity / karma-typescript

Simplifying running unit tests with coverage for Typescript projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coverage report not showing files with zero coverage

masterqwerty opened this issue · comments

I don't know if this is a bug in this library or my configuration, but when I run a coverage report using the karma-typescript reporter, it only reports on files that have unit tests for them. In other words, I'm seeing something like this:

-------------------------------------------|---------|----------|---------|---------|-------------------
File                                       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------------------|---------|----------|---------|---------|-------------------
All files                                  |     100 |      100 |     100 |     100 |
 src                                       |     100 |      100 |     100 |     100 |
  test.ts                                  |     100 |      100 |     100 |     100 |

Instead of something like this:

-------------------------------------------|---------|----------|---------|---------|-------------------
File                                       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------------------|---------|----------|---------|---------|-------------------
All files                                  |      50 |       50 |      50 |      50 |
 src                                       |     100 |      100 |     100 |     100 |
  test.ts                                  |     100 |      100 |     100 |     100 |
  uncovered.ts                             |       0 |        0 |       0 |       0 | 1-25

The test command is ng test my-application --watch=false --browsers=ChromeHeadlessNoSandbox --code-coverage.

This is my karma.conf.js:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular', 'karma-typescript'],
    plugins: [
      'karma-jasmine',
      'karma-chrome-launcher',
      'karma-jasmine-html-reporter',
      'karma-coverage',
      'karma-typescript',
      '@angular-devkit/build-angular/plugins/karma'
    ],
    client: {
      clearContext: false
    },
    preprocessors: {
      '**/*.ts': ['karma-typescript']
    },
    karmaTypescriptConfig: {
      reports: {
        'text': null,
        'text-summary': {
          'directory': 'coverage',
          'subdirectory': '.',
          'filename': 'summary.txt'
        },
        'json-summary': {
          'directory': 'coverage',
          'subdirectory': '.',
          'filename': 'summary.json'
        }
      },
      tsconfig: 'tsconfig.lib.json'
    },
    reporters: ['progress', 'kjhtml', 'karma-typescript'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome', 'ChromeHeadless'],
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    },

    singleRun: false
  });
};

And this is my tsconfig.lib.json:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../../out-tsc/lib",
    "declarationMap": true,
    "target": "es2015",
    "module": "es2015",
    "moduleResolution": "node",
    "declaration": true,
    "sourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "types": ["webgl2"],
    "lib": [
      "dom",
      "es2015"
    ]
  },
  "angularCompilerOptions": {
    "skipTemplateCodegen": true,
    "strictMetadataEmit": true,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableResourceInlining": true
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

Any help would be appreciated. Thanks!