Angular 6 - Despite Sonarqube consistently reporting 0 coverage, karma is showing accurate coverage results

I've been working on setting up SonarQube for my Angular 6 project. I have successfully run 5 basic tests and the Karma coverage report is as follows:

Chrome 92.0.4515 (Windows 10.0.0): Executed 5 of 5 SUCCESS (0.807 secs / 0.868 secs)

=============================== Coverage summary ===============================
Statements   : 29.65% ( 282/951 )
Branches     : 23.37% ( 115/492 )
Functions    : 16.84% ( 32/190 )
Lines        : 28.2% ( 258/915 )
================================================================================

However, when I set up SonarQube locally to view the coverage report, it always shows 0% coverage.

Since Karma shows some coverage results, I expect Sonar's coverage to be at least somewhat similar.

Here is the content of the sonar-project.properties file:

sonar.host.url=http://localhost:9000
sonar.login=admin
sonar.password=admin123
sonar.projectKey=myproject:ui
sonar.projectName=Sample App
sonar.projectVersion=0.0.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/node_modules/**
sonar.tests=src
sonar.test.inclusions=**/*.spec.ts
sonar.typescript.lcov.reportPaths=coverage/myproject/lcov.info

And here is a snippet from the package.json file:

"scripts": {
    "sonar": "sonar-scanner"
  },
"devDependencies": {
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "sonar-scanner": "^3.1.0",
  }

The lcov.info file can be found under src/coverage/myproject/lcov.info.

After running npm run sonar, the coverage in SonarQube still shows 0.0%. Any assistance in resolving this issue would be greatly appreciated.

Answer №1

Opt for

sonar.javascript.lcov.reportPaths=coverage/myproject/lcov.info

instead of

sonar.typescript.lcov.reportPaths=coverage/myproject/lcov.info.

Proceed to execute sonar-scanner or npm run sonar. Everything should function smoothly.

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

What is the process for updating information once the user has verified their email address on Supabase using Next.js

After a user signs up using a magic link, I want to update the profiles table in my database. Below is the code snippet I am currently using: Login.tsx import { useState } from "react"; import { supabase } from "../lib/initSupabase"; c ...

New to React and struggling with updating the DOM

Upon receiving a React project, I am faced with the task of performing a complex state update on my DOM. Here is how my component looks: /** @jsx jsx */ import { jsx } from '@emotion/core'; import { Typography } from '@material-ui/core&ap ...

Trouble with child routes not properly directing to content page within Angular 5

I have developed multiple modules with internal components. Folder structure: --app --java --Introduction --Syntax Each component has its own routing module. When I add child routes to the main app.routing.ts file, everything work ...

Angular material table is failing to display the rows in the dataSource

I am having trouble using Angular Material table to display my dataSource, which is actually an Observable. Strangely enough, when I tried displaying it outside of the table, it worked perfectly fine. I even attempted using changeDetectorRefs.detectChanges ...

Angular has deprecated the use of `isObject` and `isNullOrUndefined` in TypeScript

Upon upgrading from Angular 7 to Angular 10 and implementing TypeScript 4 or higher, I began receiving deprecation warnings for the functions isObject() and isNullOrUndefined() when running ng lint warnings The function isNullOrUndefined has been depreca ...

Displaying Images in Bootstrap 4 Grid with Angular 7 Conditional Rendering

Currently, I have a display grid set up using Bootstrap 4's card feature. I am looking to iterate through an array of images and only display the images that match a specific status. When I include the *ngIf='image.status == sTab.status' c ...

Transfer websites to subfolders without altering the base URL

Previously, I had two staging/test servers each hosting an angular application on nginx, referred to as app1 and app2. The setup was straightforward: http://<ip for app1 server>/ => app1 http://<ip for app2 server>/ => app2 Now, my g ...

Issue with Typescript flow analysis when using a dictionary of functions with type dependency on the key

I am utilizing TypeScript version 4.6 Within my project, there exists a type named FooterFormElement, which contains a discriminant property labeled as type type FooterFormElement = {type:"number",...}|{type:"button",...}; To create instances of these el ...

Typescript declaration specifies the return type of function properties

I am currently working on fixing the Typescript declaration for youtube-dl-exec. This library has a default export that is a function with properties. Essentially, the default export returns a promise, but alternatively, you can use the exec() method which ...

If an error occurs during ng lifecycle hooks, router.navigate will not function correctly

I've developed an ErrorHandler specifically for logging exceptions and then redirecting the user to a generic error page. However, a recurring problem arises when the exception occurs within a lifecycle hook or constructor method. Take for example the ...

What is the best way to incorporate a module from an external 'include' folder in your code?

Within my project's tsconfig.json, I have specified the following: "include": [ "src/**/*", "generated**/*" ] In the directory, there exist two files named src/main.ts and generated/data.json. The task at hand is to be able to successfully ...

Is the child constantly updating due to a function call?

Having difficulty navigating the intricacies where a child keeps re-rendering due to passing a function from the parent, which in turn references an editor's value in draftjs. function Parent() { const [doSomethingValue, setDoSomethingValue] = Re ...

At what point should you unsubscribe from an observable within an Angular component?

As I integrate ngrx with Angular, suppose I retrieve data from a selector in a component and store it in a variable. In the ngOnDestroy lifecycle hook, should I manually unsubscribe using the unsubscribe method, or does the ngrx select method handle it a ...

Using ngIf to locate a substring

<ul class="list-group" *ngFor="let head of channelDisplayHeads"> <li class="list-group-item" *ngFor="let channel of channelList" ngIf="channel.channel.indexOf('head') === 1"> <strong>{{ head }}</strong> ...

Enhancing the session object with new properties

I am attempting to include extra properties in the session object req.session.confirmationCode = confirmationCode; However, I encounter an error stating that the property confirmationCode does not exist Property 'confirmationCode' does not exist ...

Building an Angular 2 Login feature with ASP.NET Identity Token Authentication

Currently, I am developing an Angular 2 application that communicates with an ASP.NET Web API 2 service through service calls. The CORS (Cross-Origin Resource Sharing) has been set up in the WebApiConfig as follows: public static class WebApiConfig { ...

When working with TypeScript for initial data, you have the choice between using interface types or class types. Which approach is the

When working with initial data in TypeScript, you have the option to use either an interface type or a class type. Which approach is preferable? export interface Item{ text: string, value: number } itemModel: ItemComboBox = { value:'valu ...

Tips for simulating child component in Angular 10 testing?

Encountering an issue while attempting to mock a child component within the component under test. Below, you will find the project's dependencies as well as the desired goal. dependencies: "@angular/animations": "^10.2.3", " ...

Using variables to replace 'placeholders' in Typescript with string interpolation

Seeking a definitive answer on this matter, I pose the question: In C#, an example of which would be as follows: var text = "blah blah"; var strTest = String.Format("This is a {0}", text); //output: 'This is a blah blah' How can I accomplish t ...

Unveiling the Mystery of Angular: Why are constructor parameters without access specifiers hidden from view outside the

When I explicitly set an access specifier for a constructor parameter, it becomes visible outside the constructor. For example: constructor(private employeResourceService:EmployeeResourceService ){ //code} ngOnInit(){ this.employeResourceService=unde ...