6

I have a +10K lines Backbone Marionette app and we are running tests and coverage through Karma.

I would like to include all the sources so that we can have a better idea of what it is not covered by our tests.

I have been passing the includeAllSources option in the karma configuration but I still don't see karma showing the results for all files (the report only show +3K lines cover, more or less the amount of lines that we know we have test for).

Am I doing something wrong? Is there another way to include all sources?

There use to be a Karma plugin that was able to handle this but the plugin is not longer working (modified to make it run, but the results are still the same).

Is there are way to pass the --include-all-sources option to Istanbul while running it from Karma?

Hugo
  • 6,244
  • 8
  • 37
  • 43

3 Answers3

1

Try this plugin: https://github.com/kopach/karma-sabarivka-reporter. It includes files specified by pattern to coverage statistic. So, you can be sure, that you have all your source files under coverage statistic control.

Install npm install --save-dev karma-sabarivka-reporter

And update karma.conf.js similar to this:

reporters: [
  // ...
  'sabarivka'
  // 'coverage-istanbul' or 'coverage' (reporters order is important for 'coverage' reporter)
  // ...
],
coverageReporter: {
  include: [
      // Specify include pattern(s) first
      'src/**/*.(ts|js)',
      // Then specify "do not touch" patterns (note `!` sign on the beginning of each statement)
      '!src/main.(ts|js)',
      '!src/**/*.spec.(ts|js)',
      '!src/**/*.module.(ts|js)',
      '!src/**/environment*.(ts|js)'
  ]
},
Ihor
  • 3,219
  • 2
  • 18
  • 20
0

This github issue seems to be addressing your issue and this pull request seems to fix it in version 0.5.2 of the karma-coverage plugin.

I hope you're using an earlier version and just upgrading solves your problem!

4lejandrito
  • 182
  • 1
  • 6
-2

You just need to add includeAllSources: true to your coverageReporter, the Reporter Options.

Like this:

coverageReporter: {
  includeAllSources: true
  ...
 }
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177