Ignoring lines in code coverage using Istanbul is not an option that can be overlooked

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.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Service for language translation in Angular

I attempted to use an angular translation service to translate English words to Chinese using a key-value mapping approach, but unfortunately, I was unsuccessful. Does anyone have any suggestions? Here is the JSON mapping: "At most {{ number }} wrods ...

Step-by-step guide on invoking an asynchronous method in canActivate for Ionic and Angular

My objective is to acquire a token for authenticating users. I am utilizing the import { Storage } from '@ionic/storage-angular'; to store the data, but I am encountering an issue where the Storage methods only function in asynchronous mode. Her ...

The variable 'HttpEvent<name[]>' cannot be assigned to the variable 'name[]' because their types are not compatible

This is the code I have written: export interface act { id: number; name: string; } public list!: act[]; getAll(token:any): void{ this.http.get<act[]>('http://localhost:4200/test', token) .subscribe( (val) => this. ...

Using Vue.js 2 on multiple HTML pages with Typescript and ASP.Net Core

My ASP.Net Core MVC project utilizes VueJs2 for more complex tasks, with each view having its own corresponding js file. The directory structure is as follows: ├ Controllers\HomeController.cs (with actions Index & Details) ├ Scripts\Hom ...

Are optional parameters in TypeScript distinct from parameters that have the ability to be undefined?

Is there a distinction between the following two code snippets? function sayHello(name?: string) { if (name) { return 'Hello ' + name; } return 'Hello!'; } and function sayHello(name: string | undefined) { if (name) { return &apo ...

Error: Unable to access the 'invalid' property of a null object - Issue with Angular Reactive Forms

In my Angular application, I have implemented a reactive form to allow users to input IP address ranges. This form utilizes a FormBuilder to create a FormArray with two text input form controls. The code for setting up the form and managing its elements is ...

Angular Routing: Dynamically loading modules as children within lazy loaded modules

I am working on a complex application where I need to load a module as a child of lazy loaded modules. For instance, I want the URL path to look like this: https://localhost:8080/ui/examplemodule/new The examplemodule and new are separate modules with t ...

When a block reaches a certain height, the mat-chip-list in Angular Material is automatically shortened to fit. This feature is exclusive to

<div fxFlex="100" fxFlex.gt-sm="80" fxFlex.sm="100"> <div *ngFor="let permission of arrayOfObjectPermissions; let index = z" class="permissions-list"> <mat-card [title]=&qu ...

Strip away the HTML tags and remove any text formatting

How can I effectively remove HTML tags and replace newlines with spaces within text? The current pattern I am using is not ideal as it adds extra space between words. Any suggestions on how to improve this pattern? replace(/(&nbsp;|<([^>]+)> ...

Designing the presentation of two overflowing text containers positioned next to each other

Hey there, I'm currently working on styling something that shows both the user's username and the title of an item on the same line, similar to how it's done on GitHub: username / title I want to make sure that if the combined width of the ...

Is there a way to manipulate my csv values so that they all appear in a single column?

I've been using the ngx-papaparse library to convert an array into a CSV file. However, after downloading the CSV file and opening it with Excel, I noticed that my values are not appearing in the correct columns. This is the function I am using: dow ...

Simplify a function by lowering its cyclomatic complexity

This particular function is designed to determine whether a specific cell on a scrabble board qualifies as a double letter bonus spot. With a cyclomatic complexity of 23, it exceeds the recommended threshold of 20. Despite this, I am unsure of an alterna ...

Global variables are not maintaining their values during page refresh or browser reload

When my page is loaded from a menu, the global variables are initialized in ngOnInit to populate the country list in a select control, which works correctly. However, I noticed that when the page is refreshed in the browser, the global values become empty ...

Create dynamic web pages using Angular's capability to render HTML, CSS, and

I've encountered an issue while trying to integrate a code snippet received from a post API response into an Angular HTML file. The code works perfectly fine when pasted in the HTML section of Codepen, as shown in the screenshot here. However, when at ...

Changing tabs does not automatically refresh the content | Angular

I have implemented a tab system using Bootstrap where each tab contains a form. However, I am facing an issue where the form data from the first tab persists even when I switch to another tab. How can I resolve this? .HTML component: <ul ngbNav #na ...

Guide on initializing a Redux toolkit state with an array of objects or local storage using TypeScript

Currently, I am attempting to set an initial state (items) to an array of objects or retrieve the same from localStorage. However, I am encountering the following error. Type 'number' is not assignable to type '{ id: string; price: number; ...

Automating the process of sending emails to users upon registration with Firebase Auth in Angular 2

Is there a way to automatically send email verification to users after they create an account? The current code I have looks like this. export class addContentComponent { add: FormGroup; constructor(public fb: FormBuilder) { this.add = t ...

Discovering all images in Angular

I have a function that stores image data, including the name. Using *ngFor, I am able to fetch this data from the database and display it in boxes. HTML <div class="row tab-pane Galeria"> <div *ngFor="let product of products" (click)="Im ...

Angular 2 encountered a fatal error: Issues with parsing the template:

Here is the code snippet I am currently working with: <div class="container"> <div [hidden]="loggedIn"> <md-grid-list cols="6" [style.margin-top]="'20px'"> <md-grid-tile [colspan]="1"></md-grid-tile> I have already ...

What is the best way to set a timeout for an Angular 2+ HTTP request?

Just a typical query appears as follows: this.people = http.get('http://localhost:3000/users') .map(response => response.json()); Is there a method to delay or timeout this? ...