Sonarqube coverage 0% in react js - sonarqube

I have written some unit tests in jest. All of them are successful. Able to view test coverage report generated by jest
But my sonarqube dashboard always shows 0% on coverage but unit tests are being detected.
I am using jest-sonar-reporter for sonar consumable format generation of reports.
This is my sonar properties file
sonar.projectKey=skyflow-app
sonar.projectName=Skyflow App
sonar.host.url = http://localhost:9000
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/node_modules/**,**/*.spec.ts, **/*.stories.tsx
sonar.tests=src
sonar.test.inclusions=**/*.test.tsx,**/*.test.ts
sonar.test.exclusions=**/*.stories.tsx
sonar.ts.tslintconfigpath=tslint.json
sonar.testExecutionReportPaths=testResults/sonar-report.xml
# sonar.coverageReportPaths = coverage/lcov.info
sonar.javascript.lcov.reportPaths = coverage/lcov.info
Please let me know where i am going wrong.

A dumb mistake from myside.
Replacing sonar.javascript.lcov.reportPaths with
sonar.typescript.lcov.reportPaths solved the issue.

can you share console output of the jenkins job?
in my case, jenkins cannot find the coverage report and got log in console output like this :
15:26:37 [ERROR] Coverage report '/home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec' could not be read/imported. Error: {}
15:26:37 java.lang.IllegalStateException: Failed to parse JaCoCo XML report: /home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec

Related

Sonarqube shows Coverage percentage but no unit tests

I'm having a problem with the Sonarqube report. It is showing 42.5% for test coverage, but "-" Unit Tests.
I created the report with coverage.py and with the command
coverage run --branch --omit 'venv/*,tests/*' -m unittest.
I've set up my coverage path with the following line:
sonar.python.coverage.reportPaths=coverage.xml
I couldn't find a solution online and don't know if it's a problem while generating the report or importing it to Sonarqube. Here is a picture of the report:
Thanks in advance!

how to get coverage report as jacocoTestReport.xml in React project

I am using jenkins pipeline for my React project to with test, build and deploy steps.
I integrated sonarqube with my project. But sonar's jacoco doesn't assess my coverage report which is in generic coverage format(test-report.xml)
Is there a way to get my report as "jacocoTestReport.xml" in my React project without using maven or gradle. I couldn't find any document or 3rd party tools?
My related pipeline script:
sh '''
${scannerHome}/bin/sonar-scanner \
-Dsonar.projectKey=xxxxxxxxxxxxxx \
-Dsonar.sources=. \
-Dsonar.sources=. \
-Dsonar.coverage.jacoco.xmlReportPaths=test-report.xml \
-Dsonar.testExecutionReportPaths=test-report.xml \
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \
-Dsonar.coverageReportPaths=test-report.xml \
-Dsonar.host.url=https://xxxxxxxxxxxxxx \
-Dsonar.login=xxxxxxxxxx
'''
The related error is like:
: Sensor Generic Coverage Report
INFO: Parsing /var/jenkins_home/workspace/**********/test-report.xml
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 36.948s
INFO: Final Memory: 49M/690M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Error during parsing of the generic coverage report '/var/jenkins_home/workspace/*******/test-report.xml'. Look at SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unknown XML node, expected "coverage" but got "testExecutions" at line 2
I assume you are only building a react application, hence that it is just JavaScript/TypeScript and my answer is based on that assumption.
If that is the case you can simply ignore the sonar.coverage.jacoco.xmlReportPaths property. You are already providing that information via the lcov.info file. Sonarqube will be able to read the coverage information from this file.
Furthermore the test-report.xml normally only contains a list of the executed tests and their outcome. You will normally find no kind of coverage information in there. Therefore your build might also break on the sonar.coverageReportPaths property (my suggestion is also to remove that one).

TeamCity failing to import DotCover report

recently we upgraded teamcity to 2017.2, after that TC is failing to import the DotCover report file. I am trying to run XUNIT meta runner: https://raw.githubusercontent.com/JetBrains/meta-runner-power-pack/master/xUnit.net-dotCover/MRPP_xunit_dotcover.xml
and updated this parameter:
[string] $dotCoverExecutable = "%teamcity.tool.JetBrains.dotCover.CommandLineTools.bundled%"
command: write-host "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='$outputFile']"
Error Message:
No available .NET Coverage report generator for type 'dotcover'. Skipped files: [D:\TCW\563efb8648d3acf2\xunitcoverage.dcvr]
i also tried generating HTML report and passed the html file to ##teamcity[importData , and getting this error:
No available .NET Coverage report generator for type 'dotcover'. Skipped files: [D:\TCW\563efb8648d3acf2\dotCoverReport.html]
Any help please?
Thanks,
Urivinty
i am able to fix the issue by adding below line to MRPP Xunit meta runner. First we need to configure code coverage engine as documented here: https://confluence.jetbrains.com/display/TCD10/Manually+Configuring+Reporting+Coverage
Write-Host "##teamcity[dotNetCoverage dotcover_home='$dotCoverExecutable']"

Failed to publish TestNG Report in Jenkins

I have used Maven project with Selenium & TestNG to create automated scripts which I want to execute from Jenkins. In Jenkins I have added the TestNG plugin to publish the TestNG report. But it is not getting displayed. I'm getting the below mentioned error.
Error:
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: /target/surefire-reports/testng-results.xml
Did not find any matching files.
Finished: SUCCESS
Actual path of the TestNG report file:
E:\STUDY_MATERIAL\JAVA\WORKSPACE\SeleneniumFrameWork\target\surefire-reports\testng-results.xml
I have tried the following options but didn't work out for me.
Tried giving the full path of the TestNG report. Forward ans backward slash in the pattern.
I have tried different other options by changing the TestNG result file path but it's working for me.
Please share some inputs on how to resolve this issue.
"testng-results.xml" file is available in workspace. But it's failed to display the report. I have attached screenshot of Jenkins workspace and Console Output.
Note: I am using Jenkins 2.7.0 in Windows 10.
Jenkins Workspace
I have attached the Job configuration details of Jenkins.
Job Configuration Details
Few checkpoints :
1. Check if testng is producing this file at the specified location : /target/surefire-reports/testng-results.xml
2. TestNG needs to be configured to generate xml report
If this file is there, pass path in file locator as :
target/surefire-reports/testng-results.xml
Hopefully, you will get results on jenkins if everything mentioned above is correct.

JavaScript Unit Tests not working on SonarQube

I have below problems with SonarRunner.
SonarQube along with Sonar runner unable to pull junit format xml reports
Unit Tests or Test Coverage widget doesn't show up. It says No Data.
I am following instructions described here
I manually created report file in XML format as described, but still no luck.
Below is the XML file - TEST-Firefox_210_Mac_OS.com.company.BarTest.xml,
<testsuite name="Firefox_210_Mac_OS.com.company.BarTest" errors="0" failures="0" tests="3" time="0.0">
<testcase classname="Firefox_210_Mac_OS.com.company.BarTest" name="testfullName" time="0.0"/>
</testsuite>
To pull the Unit Test execution report to show on sonar dashboard. I have used sample git project from here
and below is my sonar-project.properties,
# project metadata (required)
sonar.projectKey=org.codehaus.sonar:javascript-sonar-runner-jstestdriver
sonar.projectName=JavaScript project with Sonar Runner reusing reports generated by JsTestDriver
sonar.projectVersion=1.0
# path to source directories (required)
sonar.sources=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources
# path to tests source directories (required)
sonar.tests=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests
sonar.javascript.jstestdriver.reportsPath=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/target/TEST-Firefox_210_Mac_OS.com.company.BarTest.xml
sonar.sourceEncoding=UTF-8
below is my jsTestDriver.conf
server: http://localhost:9876
load:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/com/company/*.js
test:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/com/company/*.js
plugin:
- name: "coverage"
jar: "coverage-1.3.5.jar"
module: "com.google.jstestdriver.coverage.CoverageModule"
My sonarqube is running on port : 9000 and below is the screen shot. As you see SonarRunner and jsTestDriver just doing a code analysis and not showing any unit tests.
SonarQube doc website says jsTestDriver will run the javascript unit
tests and copy the results in target folder in XML format
SonarQube doesnt run your Unit Tests, it just gathers the reports generated from your manuall run or other tools automatic run (like: Jenkins).
From SonarQube doc:
Prior to the SonarQube analysis, execute your unit tests in order to
generate XML report. The JUnit like XML format supported is the one
generated by js-test-driver
Then I manually created report file in XML format as described, but
still no luck.
If you created manually the report files and reports are still not showing, check your paths if ok.Check if sonar is really reading data from C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/ path

Resources