SonarQube keep showing me - unit test with Angular and Jest

Hello everyone, I come here because I have been working on setting up SonarQube with my Angular application for over a week.
I use jest to test my code.

Currently my problem is that my code is tested well, I obtain relevant results except on one aspect.
SonarQube does not display unit test quantity.

Below is my jest.config.js

module.exports = {
  verbose: false,
  maxWorkers: 10,
  transformIgnorePatterns: ['/node_modules/(?!(uuid|.*ol|.*quick-lru|.*akita|.*\\.mjs$))'],
  moduleFileExtensions: ['js', 'json', 'ts'],
  transform: {
    '^.+\\.tsx?$': 'ts-jest'
  },
  testMatch: ['(**/*.spec.ts)'],
  testRunner: 'jest-jasmine2',
  testEnvironment: 'jsdom',
  coverageDirectory: './coverage',
  coverageReporters: ["clover", "json", "lcov", "text", "text-summary"],
  collectCoverageFrom: [
    "src/**/*.ts"  // Adjust the pattern to match your project structure
  ],
  // exclude files from coverage
  coveragePathIgnorePatterns: [
    "/node_modules/",
    "/src/main.ts",
    "/src/polyfills.ts",
    "/src/environments/environment.ts",
    "/src/environments/environment.prod.ts",
    "/src/environments/environment.azure.ts",
    "/src/app/app-routing.module.ts",
    "/src/app/app.module.ts",
    ],
  collectCoverage: true,
  testResultsProcessor: "jest-sonar-reporter",
  clearMocks: true

}

and below is my sonar-project.properties

sonar.projectKey=*******
sonar.organization=*******
sonar.projectName=*******
sonar.projectVersion=1.3.2
sonar.cpd.exclusions=src/app/login/**, src/app/register/**, src/app/dashboard-all-support/**, src/app/dashboard-all-users/**
sonar.sources=src/
sonar.tests=src/app
sonar.test.inclusions=**/*.spec.ts
sonar.exclusions=**/node_modules/**, main.ts, src/app/app.module.ts, polyfills.ts, src/main.ts, src/app/app-routing.module.ts, src/environments/environment.ts, src/environments/environment.azure.ts
sonar.typescript.lcov.reportPaths=./coverage/lcov.info
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.testExecutionReportPaths=./test-report.xml
sonar.typescript.tsConfigPath=./tsconfig.json
sonar.host.url=*******

Hi,

Could you provide your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann

I don’t understand what file you need, the result when i launch sonar-scanner or the result of ng test ?

Hi,

As described by the link I provided, I’m looking for the logging done by the scanner when you run an analysis.

 
Ann


I only have this log when i run the test

Hi,

I’m not asking for the logging from when you run the test.

 
Ann

Can you provide the name of the file you want because i really dont understand what you want, i checked the docs you send but i dont have log like this.

Hi,

From the guide I linked:

The Scanner logs are the output of executing one of the scanners
The answer to the question "how was Sonar analysis enabled for this repository" should usually answer the question, “where do I find the scanner logs” ?

So… how are you triggering analysis?

 
Ann

name: SonarQube Scan

on:
  push:
    branches:
      - main

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '18'

      - name: Install dependencies
        run: npm install --legacy-peer-deps

      - name: Run tests and collect coverage
        run: npm test -- --coverage

      - name: Upload coverage reports
        uses: actions/upload-artifact@v2
        with:
          name: coverage
          path: coverage

      - name: Analyze with SonarQube
        uses: sonarsource/sonarqube-scan-action@master
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

The only time my analysis is executed is in this github action.

Hi,

What I’m asking for is the GHAction logs from this step:

 
Ann

INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /github/workspace/sonar-project.properties
INFO: SonarScanner 5.0.1.3006
INFO: Java 17.0.8 Alpine (64-bit)
INFO: Linux 6.2.0-1011-azure amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Analyzing on SonarQube server 10.1.0.73491
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=485ms
INFO: Server id: ***
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=221ms
INFO: Load/download plugins (done) | time=8438ms
INFO: Process project properties
INFO: Process project properties (done) | time=9ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: ***
INFO: Base dir: /github/workspace
INFO: Working dir: /github/workspace/.scannerwork
INFO: Load project settings for component key: ****
INFO: Load project settings for component key: **** (done) | time=123ms
INFO: Load project branches
INFO: Load project branches (done) | time=110ms
INFO: Load branch configuration
INFO: Auto detected BRANCH configuration with source main using com.github.mc1arke.sonarqube.plugin.scanner.autoconfiguration.GithubActionsAutoConfigurer
INFO: Load branch configuration (done) | time=3ms
INFO: Auto-configuring with CI 'Github Actions'
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=202ms
INFO: Load active rules
INFO: Load active rules (done) | time=4344ms
INFO: Load analysis cache
INFO: Load analysis cache | time=134ms
INFO: Branch name: main
INFO: Load project repositories
INFO: Load project repositories (done) | time=115ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: **/node_modules/**, main.ts, src/app/app.module.ts, polyfills.ts, src/main.ts, src/app/app-routing.module.ts, src/environments/environment.ts, src/environments/environment.azure.ts, **/*.spec.ts
INFO: Included tests: **/*.spec.ts
INFO: Excluded sources for duplication: src/app/login/**, src/app/register/**, src/app/dashboard-all-support/**, src/app/dashboard-all-users/**
INFO: 186 files indexed
INFO: 153 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for css: Sonar way
INFO: Quality profile for json: Sonar way
INFO: Quality profile for ts: Sonar way
INFO: Quality profile for web: Sonar way
INFO: ------------- Run sensors on module T Flow
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=118ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=4ms
INFO: Sensor IaC CloudFormation Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=25ms
INFO: Sensor IaC Kubernetes Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC Kubernetes Sensor [iac] (done) | time=7ms
INFO: Sensor JavaScript/TypeScript analysis [javascript]
INFO: 102 source files to be analyzed
INFO: Resolving TSConfig files using './tsconfig.json' from property sonar.typescript.tsconfigPaths
INFO: Found 1 TSConfig file(s): [/github/workspace/./tsconfig.json]
INFO: 102/102 source files have been analyzed
INFO: Hit the cache for 0 out of 102
INFO: Miss the cache for 102 out of 102: ANALYSIS_MODE_INELIGIBLE [102/102]
INFO: Sensor JavaScript/TypeScript analysis [javascript] (done) | time=13943ms
INFO: Sensor JavaScript inside HTML analysis [javascript]
INFO: 32 source files to be analyzed
INFO: 32/32 source files have been analyzed
INFO: Hit the cache for 0 out of 32
INFO: Miss the cache for 32 out of 32: ANALYSIS_MODE_INELIGIBLE [32/32]
INFO: Sensor JavaScript inside HTML analysis [javascript] (done) | time=207ms
INFO: Sensor CSS Rules [javascript]
INFO: 64 source files to be analyzed
INFO: 64/64 source files have been analyzed
INFO: Hit the cache for 0 out of 0
INFO: Miss the cache for 0 out of 0
INFO: Sensor CSS Rules [javascript] (done) | time=1311ms
INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: Merging coverage reports from sonar.javascript.lcov.reportPaths and sonar.typescript.lcov.reportPaths.
INFO: Analysing [/github/workspace/./coverage/lcov.info]
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=48ms
INFO: Sensor CSS Metrics [javascript]
INFO: Sensor CSS Metrics [javascript] (done) | time=177ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=2ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=14ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=1ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=165ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: 167 source files to be analyzed
INFO: 167/167 source files have been analyzed
INFO: Sensor TextAndSecretsSensor [text] (done) | time=241ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=14ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor
INFO: Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor (done) | time=1ms
INFO: Sensor IaC Docker Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC Docker Sensor [iac] (done) | time=70ms
INFO: Sensor Generic Test Executions Report
INFO: Parsing /github/workspace/test-report.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 42 unknown files, including:
/home/runner/work/t-flow/t-flow/src/services/jwt-token/jwt-token.service.spec.ts
/home/runner/work/t-flow/t-flow/src/services/httpClient/http-client.service.spec.ts
/home/runner/work/t-flow/t-flow/src/app/download/download.component.spec.ts
/home/runner/work/t-flow/t-flow/src/app/transfer-recap/transfer-recap.component.spec.ts
/home/runner/work/t-flow/t-flow/src/services/cookies/cookies.service.spec.ts
INFO: Sensor Generic Test Executions Report (done) | time=28ms
INFO: ------------- Run sensors on project
INFO: Sensor Analysis Warnings import [csharp]
INFO: Sensor Analysis Warnings import [csharp] (done) | time=1ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=1ms
INFO: CPD Executor 25 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 59 files
INFO: CPD Executor CPD calculation finished (done) | time=38ms
INFO: Load New Code definition
INFO: Load New Code definition (done) | time=104ms
INFO: Analysis report generated in 218ms, dir size=835.6 kB
INFO: Analysis report compressed in 251ms, zip size=461.0 kB
INFO: Analysis report uploaded in 625ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: ***/dashboard?id=***
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at ***/api/ce/task?id=****
INFO: Analysis total time: 31.817 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 44.891s
INFO: Final Memory: 21M/80M
INFO: ------------------------------------------------------------------------

I have this output

Hi,

Here you go:

The paths in the test execution report don’t match the paths analysis is seeing.

 
Ann

So what configuration i need to change to detect the good path ?
Because i really dont understand why i have this error but my sonarQube show me the coverage.

Hi,

I can’t know that. You need to look at how the report is generated.

 
Ann