Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma JS -- How to Include all All Sources?

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?

like image 240
Hugo Avatar asked Sep 28 '15 20:09

Hugo


People also ask

How do I generate a coverage report on karma?

To activate the coverage reporter add this to your configuration file. reporters = ['coverage']; This will create a coverage report for every browser that the tests are run in. In addition, it will create a JSON file that outputs the intermediate data.

Is Karma coverage Istanbul reporter deprecated?

If you upgraded to Angular 11 recently, you might have noticed that karma-coverage-istanbul-reporter has been deprecated. It can simply be replaced with karma-coverage and by changing some things in karma. conf. js .

What are Preprocessors in karma?

Preprocessors in Karma allow you to do some work with your files before they get served to the browser. These are configured in the preprocessors block of the configuration file: preprocessors: { '**/*. coffee': ['coffee'], '**/*.

What is the command used for karma configuration used for using CLI?

The configuration file can be generated using karma init : $ karma init my. conf.


1 Answers

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)'
  ]
},
like image 97
Ihor Avatar answered Oct 11 '22 02:10

Ihor