Hi team,
We are using Jest unit results publishing Cobetura.xml, which shows the Azure pipeline extension, This code coverage needs to show Sonar Cloud, but sonar does not pick it. Please help
YMAL
-
task: Npm@1
displayName: npm install
inputs:
command: “custom”
customCommand: “install --force”
enabled: true -
task: Npm@1
displayName: Unit Test
inputs:
command: ‘custom’
customCommand: ‘run test:unitcoverage’ -
task: PublishTestResults@2
displayName: ‘Publish Test Results’
inputs:
testRunner: JUnit
testResultsFiles: ‘**/junit.xml’ -
task: PublishCodeCoverageResults@1
displayName: Publish coverage
inputs:
codeCoverageTool: ‘Cobertura’
summaryFileLocation: ‘$(System.DefaultWorkingDirectory)**/coverage/cobertura-coverage.xml’
pathToSources: ‘$(System.DefaultWorkingDirectory)/src’
reportDirectory: ‘$(System.DefaultWorkingDirectory)/coverage/cobertura’
enabled: true -
task: SonarCloudPrepare@1
inputs:
SonarCloud: ‘xx’
organization: ‘xx’
scannerMode: ‘CLI’
configMode: ‘file’
configFile: ‘$(Build.SourcesDirectory)/sonar-project.properties’
enabled: true -
task: SonarCloudAnalyze@1
displayName: Run Sonar analysis
enabled: true -
task: SonarCloudPublish@1
displayName: Publish quality gate
inputs:
pollingTimeoutSec: ‘300’
enabled: true
sonar-project.properties
sonar.projectKey=xx
sonar.projectName=xx
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=/index.js,//index.js,/*.test.js
sonar.token=xxxx
sonar.cobertura.reportPaths=./coverage-cobertura.xml
sonar.javascript.lcov.reportPaths=./coverage/cobertura/lcov.info
Package.json
},
“scripts”: {
“start”: “react-scripts start”,
“build”: “react-scripts build”,
“test”: “react-scripts test”,
“test:unitcoverage”: “react-scripts test --env=jsdom --watch --coverage --watchAll=false --coverageReporters=cobertura --coverageReporters=html --reporters=default --reporters=jest-junit”,
“eject”: “react-scripts eject”,
“coverage”: “jest --coverage --coverageReporters=cobertura”
},
Please suggest any configuration changes or any other changes need.