I have come across many examples of code that utilize
/* istanbul ignore next / / istanbul ignore start / / istanbul ignore end */
There are certain parts in the codebase that cannot be covered by unit tests, and it would be beneficial to employ these Istanbul directives to exclude them. Unfortunately, despite trying to install, reinstall, modify configuration files, etc., I haven't been able to make this functionality work.
The tools and plugins I am using include:
- IntelliJ IDEA 2021.2.4 (Ultimate Edition)
- JetBrains Karma Plugin (212.4746.57)
- Angular and AngularJS Plugin (212.5712.43)
- Javascript and Typescript Plugin (212.5712.43)
- Node Plugin (212.5712.43)
- node 14.15.5
- npm 6.14.11
- @angular-* 14.0.1
- jasmine 4.2.0
- jasmine-core 4.2.0
- jasmine-reporters 2.5.0
- karma 6.4.0
- karma-chrome-launcher 3.1.1
- karma-cli 2.0.0
- karma-coverage 2.2.0
- karma-jasmine 5.0.1
- source-map-support 0.5.21
- ts-helpers 1.12
- ts-node 10.8.1
- tslib 2.4.0
- typescript 4.7.3
Based on my research, it appears that Istanbul is included as part of karma-coverage, though there are other related Istanbul packages available.
My karma.conf.js file looks like this:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/2.0/config/configuration-file.html
// This is for running locally in intellij - the intellij plugin doesn't support the parallel options we use via jenkins
module.exports = function (config) {
config.set({
files: [
'src/**/*.js'
],
// coverage reporter generates the coverage
reporters: ['progress', 'coverage'],
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('karma-junit-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmine: {
verboseDeprecations: true
}
},
// you can define custom flags
customLaunchers: {
},
mime: {
'text/x-typescript': ['ts','tsx']
},
preprocessors: {
'src/**/*.js': ['coverage']
},
coverageReporter: {
dir: require('path').join(__dirname, 'coverage'),
fixWebpackSourcePaths: true,
reporters: [
{ type: 'lcov' /*, subdir: 'report-lcov' */ }
]
},
junitReporter: {
outputDir: 'test-results/unit/',
outputFile: 'test-results.xml'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage', 'junit']
: ['progress', 'kjhtml', 'junit'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
hostName: 'localhost',
autoWatch: true,
usePolling: true,
singleRun: true,
browsers: ['ChromeHeadless'],
captureTimeout: 180000,
browserNoActivityTimeout : 210000,
reportSlowerThan : 500,
retryLimit: 0,
browserDisconnectTimeout : 210000,
browserDisconnectTolerance : 1,
random: false
});
};
Upon inspecting the Karma Server window, I don't see any reference to "istanbul". There is no indication that istanbul is actually being utilized. Given the extensive usage of // istanbul directives in the code, this seems to be a common issue. Any advice or suggestions on how to resolve this and effectively implement istanbul would be greatly appreciated.