Skip to content

A Karma plugin. Adds untested files to coverage statistic

License

Notifications You must be signed in to change notification settings

Lalem001/karma-sabarivka-reporter

 
 

Repository files navigation

Code coverrage badge Travis CI badge Snyk Vulnerabilities badge

NPM badge

⭐️ Please, star me on GitHub — it helps!

karma-sabarivka-reporter – is a Karma plugin which adds untested files to istanbul coverage statistic

screenshot before

screenshot after

🧬 Table of Contents

❓ Why? 🔝

If your project has single entry point for your test files (e.g. test.(ts|js) file which gathers all *.spec.(ts|js))) - you're probably facing an issue with "fake" test coverage. To have a real picture of test coverage all files with source code should be imported directly into *.spec.(ts|js)) files. Files with source code, which were not imported in any *.spec.(ts|js)) files will not be shown in coverage report at all, which creates higher coverage result than it is in reality.

This plugin will be at least useful for all Angular 2-8 projects generated using angular-cli.

This karma plugin attempts to fix described issue by going through all of the source files and including them explicitly into coverage result.

Plugin works with both: TypeScript (*.ts) and JavaScript (*.js) files

✨ Features 🔝

  • Both JavaScript *.js and TypeScript *.ts files support
  • Multiple patterns
  • Negated patterns: ['foo*', '!foobar']

💾 Install 🔝

With npm installed, run

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

👽 API 🔝

@param {string[] | string} coverageReporter.include - Glob pattern, string or array of strings. Files which should be included into the coverage result.

🔨 Usage 🔝

Update karma.conf.js

include as array of strings 🔝

reporters: [
  // ...
  'sabarivka'
  // ...
],
coverageReporter: {
  include: [
      // Specify include pattern(s) first
      'src/**/*.(ts|js)',
      // Then specify "do not include" 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)'
  ]
},

Same result may be achieved with more complex one line glob pattern

include as string 🔝

reporters: [
  // ...
  'sabarivka'
  // ...
],
coverageReporter: {
    include: 'src/**/!(*.spec|*.module|environment*|main).(ts|js)',
},

karma plugins section 🔝

If your karma config has plugins section, add also karma-sabarivka-reporter there. Otherwise — no action is required.

Karma's documentation:

By default, Karma loads all sibling NPM modules which have a name starting with karma-*.
You can also explicitly list plugins you want to load via the plugins configuration setting. The configuration value can either be a string (module name), which will be required by Karma, or an object (inlined plugin).

See here more info on how karma plugins loading works

plugins: [
  // ...
  require('karma-sabarivka-reporter'),
  // ...
],

📄 License 🔝

This software is licensed under the MIT

About

A Karma plugin. Adds untested files to coverage statistic

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 90.6%
  • JavaScript 9.4%