We have a project in bit bucket and the sonar cloud is integrated with the bitbucket pipeline. We have microservices architecture and each service has its separate tests and coverage reports. (Coverage generated through the nyc)
folder structure
bitbucket pipeline
options:
max-time: 40
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
services:
mongo:
image: mongo_replset
dynamodb:
image: amazon/dynamodb-local
redis:
image: redis
docker:
memory: 4096
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &sonarcloud-analysis
name: SonarCloud analysis
caches:
- sonar
size: 2x
services:
- docker
script:
- pipe: sonarsource/sonarcloud-scan:1.4.0
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
DEBUG: ${DEBUG_MODE}
XTRA_ARGS: '-Dsonar.javascript.lcov.reportPaths=/src/**/lcov.info'
pipelines:
branches:
'{develop}':
- step:
name: Check MongoDB
size: 2x
image: mongo_replset
script:
- mongo mongodb --eval 'rs.status()'
services:
- mongo
- step:
name: Build
size: 2x
image: node:16
script:
- ./test_runner.sh dev10 us-east-2 --service all test-unit || true
- ./test_runner.sh dev10 us-east-2 print_test_report
services:
- dynamodb
- mongo
- redis
artifacts: # defining the artifacts to be passed to each future step.
- temp.txt
- message.txt
- step: *sonarcloud-analysis
pull-requests:
'**':
- step: *sonarcloud-analysis
sonar-project.properties file
sonar.projectKey=<project-key>
sonar.projectName=<project-name>
sonar.projectVersion=1.0
sonar.host.url=https://sonarcloud.io
sonar.organization=<orgnization-name>
sonar.language=js
sonar.sources=src
sonar.sourceEncoding=UTF-8
sonar.exclusions=db/**/*,src/test-utils/**/*, src/test_functions/**/*, src/**/test-manual/*, src/**/package-lock.json
sonar.cpd.exclusions=**/EnumServiceImpl.ts, **/solutions/**, **/src/admin/index.tsx, **/src/index.tsx
sonar.tests=src
sonar.test.inclusions=**/*.spec.ts
sonar.test.exclusions=**/*.stories.tsx
sonar.ts.tslintconfigpath=tslint.json
sonar.junit.reportPaths=reports/junit.xml
sonar.javascript.lcov.reportPaths=src/**/lcov.info
sonar.typescript.tsconfigPath=src/**/tsconfig.json
sonar.coverage.inclusions=src
sonar.scm.exclusions.disabled=true
sonar.coverage.exclusions=src/api/**/*.ts
- Do we need to upload the lcov.info file to our bit bucket repo? ( If we write some new code segment and test cases for that code segment and push the changes with the lcov.info file to the branch then we can see the coverage)
- When we are merging a PR we run all the test cases. What we tried was to check the coverage at this point without pushing the lcov.info file to the repo. But we’re not getting coverage with this method.
08:52:42.816 DEBUG: Property sonar.javascript.lcov.reportPaths is used.
08:52:42.816 DEBUG: Using 'src/**/lcov.info' to resolve LCOV files
08:52:43.005 INFO: No LCOV files were found using src/**/lcov.info
08:52:43.005 WARN: No coverage information will be saved because all LCOV files cannot be found.
08:52:43.005 INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=189ms