Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage not reflected in the dashboard #152

Open
patolax opened this issue Sep 30, 2021 · 3 comments
Open

Code coverage not reflected in the dashboard #152

patolax opened this issue Sep 30, 2021 · 3 comments

Comments

@patolax
Copy link

patolax commented Sep 30, 2021

My project is angular 12. We moved to this library from "karma-sonarqube-unit-reporter": "^0.0.23".
The problem I am reporting exists regardless of the library we use.
Major issue is even though sonar scanner executes successfully, the sonar dashboard for my project shows 0 code coverage.

What am I doing wrong and how can I resolve this.

Here are the

  • sonar-project.properties
  • karma.conf.js
  • logs after running sonar

sonar-project.properties

sonar.projectKey=Client
sonar.projectName=WebClient
sonar.host.url=http://tfs07:9000
sonar.login=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
sonar.password=
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.tests=src
sonar.exclusions=/node_modules/
sonar.test.inclusions=**/*.spec.ts
sonar.typescript.lcov.reportPaths=coverage/report-lcov/lcov.info
sonar.testExecutionReportPaths=reports/ut_report.xml
sonar.dependencyCheck.htmlReportPath=../TestResults/dependency-check/dependency-check-report.html

karma.conf.js
// Karma configuration file, see link for more information
// http://karma-runner.github.io/3.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
// NOTE: 'parallel' must be the first framework in the list
frameworks: ['parallel', 'jasmine', '@angular-devkit/build-angular'],
parallelOptions: {
executors: 1, // Defaults to cpu-count - 1
},
plugins: [
require('karma-parallel'),
require('karma-jasmine'),
require('karma-chrome-launcher'),
// require("karma-firefox-launcher"),
require('karma-jasmine-html-reporter'),
require('karma-trx-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-sonarqube-reporter')
],
files: [
// Include material theme to avoid warnings in unit tests.
{ pattern: './node_modules/@angular/material/prebuilt-themes/indigo-pink.css', included: true, watched: false },
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageReporter: {
dir: require('path').join(__dirname, 'coverage'),
subdir: '.',
reporters: [
// reporters not supporting the file property
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' },
// reporters supporting the file property, use subdir to directly
// output them in the dir directory
{ type: 'cobertura', subdir: '.', file: 'cobertura.xml' },
{ type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' },
{ type: 'teamcity', subdir: '.', file: 'teamcity.txt' },
{ type: 'text', subdir: '.', file: 'text.txt' },
{ type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
]
},
sonarqubeReporter: {
basePath: './src', // test files folder
filePattern: '*/spec.ts', // test files glob pattern
encoding: 'utf-8', // test files encoding
outputFolder: 'reports', // report destination
legacyMode: false, // report for Sonarqube < 6.2 (disabled)
reportName: (metadata) => { // report name callback, but accepts also a
// string (file name) to generate a single file
/

* Report metadata array:
* - metadata[0] = browser name
* - metadata[1] = browser version
* - metadata[2] = plataform name
* - metadata[3] = plataform version
*/
return metadata.concat('xml').join('.');
}
},
trxReporter: { outputFile: './testresults/test-results.trx', shortTestName: false },
reporters: ['progress', 'kjhtml', 'trx', 'sonarqube'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
//browsers: ['Chrome'],
browsers: ['ChromeHeadless'], // Chrome times out on build server, hopefully headless works karma-runner/karma-chrome-launcher#234
// browsers: ['Firefox'],
singleRun: false,
browserSocketTimeout: 30000, // in ms for connection to the test browser, default 20k
processKillTimeout: 10000, // in ms for how long to wait after asking browser to shut down
captureTimeout: 60000, // time in ms before it retries to start the browser
browserNoActivityTimeout: 30000, // time in ms before giving up on browser instance
browserDisconnectTimeout: 5000 // "flaky connection" adaptation in ms
});
};

logs after running sonar

PS C:\Users\source\repos\WebClient> yarn sonar
yarn run v1.22.11
$ sonar-scanner
[16:49:11] Starting analysis...
[16:49:11] Checking if executable exists: C:\Users.sonar\native-sonar-scanner\sonar-scanner-4.5.0.2216-windows\bin\sonar-scanner.bat
[16:49:11] Platform binaries for SonarScanner found. Using it.
INFO: Scanner configuration file: C:\Users.sonar\native-sonar-scanner\sonar-scanner-4.5.0.2216-windows\bin..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\Users\source\repos\WebClient\sonar-project.properties
INFO: SonarScanner 4.5.0.2216
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User cache: C:\Users.sonar\cache
INFO: Scanner configuration file: C:\Users.sonar\native-sonar-scanner\sonar-scanner-4.5.0.2216-windows\bin..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\Users\source\repos\WebClient\sonar-project.properties
INFO: Analyzing on SonarQube server 9.1.0
INFO: Default locale: "en_AU", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=1103ms
INFO: Server id: 079D80A9-AXeBAUv-jw9u9K_vBr9X
INFO: User cache: C:\Users.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=378ms
INFO: Load/download plugins (done) | time=252518ms
INFO: Process project properties
INFO: Process project properties (done) | time=6ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: WebClient
INFO: Base dir: C:\Users\source\repos\WebClient
INFO: Working dir: C:\Users\source\repos\WebClient.scannerwork
INFO: Load project settings for component key: 'WebClient'
INFO: Load project settings for component key: 'WebClient' (done) | time=348ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=383ms
INFO: Load active rules
INFO: Load active rules (done) | time=9310ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: /node_modules/, **/.spec.ts
INFO: Included tests: **/
.spec.ts
INFO: Load project repositories
INFO: Load project repositories (done) | time=760ms
INFO: 876 files indexed
INFO: 877 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 ts: Tharindu way
INFO: Quality profile for web: Sonar way
INFO: ------------- Run sensors on module Web
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=359ms
INFO: Sensor CSS Metrics [cssfamily]
INFO: Sensor CSS Metrics [cssfamily] (done) | time=424ms
INFO: Sensor CSS Rules [cssfamily]
INFO: 188 source files to be analyzed
INFO: 188/188 source files have been analyzed
INFO: Sensor CSS Rules [cssfamily] (done) | time=7677ms
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=7ms
INFO: Sensor TypeScript analysis [javascript]
INFO: Found 1 tsconfig.json file(s): [C:\Users\source\repos\WebClient\tsconfig.json]
INFO: Analyzing 458 files using tsconfig: C:\Users\source\repos\WebClient\tsconfig.json
INFO: 458 source files to be analyzed
INFO: 15/458 files analyzed, current file: src/app/app-routing.module.ts
INFO: 297/458 files analyzed, current file: src/app/features/map-management/layer-addedit/layer-addedit.component.ts
INFO: 458/458 source files have been analyzed
INFO: Sensor TypeScript analysis [javascript] (done) | time=40638ms
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=12ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=1ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=4ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=690ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=3ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=17ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: Sensor Generic Test Executions Report
INFO: Parsing C:\Users\source\repos\WebClient\reports\ut_report.xml
INFO: Imported test execution data for 191 files
INFO: Sensor Generic Test Executions Report (done) | time=89ms
INFO: ------------- Run sensors on project
INFO: Sensor Dependency-Check [dependencycheck] pendency-check-report.jsonCheck report k-report.htmlreport.xmlipped/aborted due to missing report file
INFO: HTML-Dependency-Check report does not exist.report fileeck property sonar.dependencyCheck.jsonReportPath:C:\Users\source\repos\WebClient${WORKSPACE}\depINFO: Process Dependency-Check report (done) | time=5msase check property sonar.dependencyCheck.htmlReportPath:C:\Users\source\repos\TestResults\dependency-check\dependency-checkINFO: Sensor Dependency-Check [dependencycheck] (done) | time=6ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=271ms
INFO: CPD Executor 142 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 406 files
INFO: CPD Executor CPD calculation finished (done) | time=406ms
INFO: Analysis report generated in 1802ms, dir size=3.4 MB
INFO: Analysis report compressed in 18958ms, zip size=1.8 MB
INFO: Analysis report uploaded in 14634ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://tfs07:9000/dashboard?id=WebClient
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 http://tfs07:9000/api/ce/task?id=AXw1fT9GuCzZIAW_ksYD
INFO: Analysis total time: 2:04.704 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 7:14.605s
INFO: Final Memory: 13M/57M
INFO: CPD Executor 142 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 406 files
INFO: CPD Executor CPD calculation finished (done) | time=406ms
INFO: Analysis report generated in 1802ms, dir size=3.4 MB
INFO: Analysis report compressed in 18958ms, zip size=1.8 MB
INFO: Analysis report uploaded in 14634ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://tfs07:9000/dashboard?id=WebClient
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 http://tfs07:9000/api/ce/task?id=AXw1fT9GuCzZIAW_ksYD
INFO: Analysis total time: 2:04.704 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 7:14.605s
INFO: Final Memory: 13M/57M
INFO: ------------------------------------------------------------------------
[16:56:27] Analysis finished.
Done in 436.48s.

@fadc80
Copy link
Owner

fadc80 commented Oct 18, 2021

Hello @patolax, I'm not sure, but I dare to say it isn't a problem with either library. Did you verify coverage report is being generated? I noticed you're using karma-coverage. Is that right? I took a look at your karma configuration and it seems you didn't add 'coverage' to the list of reporters. I would also check the command you're using to run your tests. For example, using Angular-CLI, if code coverage isn't enabled by default, you should use something like ng test --no-watch --code-coverage. I hope these insights help you to find what is wrong.

References:

https://github.com/karma-runner/karma-coverage
https://angular.io/guide/testing-code-coverage

@patolax
Copy link
Author

patolax commented Oct 19, 2021

I added the 'coverage' to the reporters.
And
"test": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test --watch=false --code-coverage",.

Also lcov.info file is generated 'coverage\report-lcov' folder.

But still no converge shown on Sonar Dashboard.

@fadc80
Copy link
Owner

fadc80 commented Oct 20, 2021

Hi @patolax. First of all, it is important to say this project doesn't genarate code coverage reports. It generates only test result reports. Therefore, this issue is a kind of out of scope :)

However, if I were you I would check again your sonar-project.properties. In my Angular projects, I usually define the property

sonar.javascript.lcov.reportPaths

I noticed you're using

sonar.typescript.lcov.reportPaths

I think this explain why code coverage is being ignored. At least, I think it is worth giving a try.

Reference:

https://community.sonarsource.com/t/sonar-typescript-coverage-failing/21791

@fadc80 fadc80 closed this as completed Oct 20, 2021
@fadc80 fadc80 reopened this Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants