I’m trying to setup Sonar for an Angular app. Here is a part of my bitbucket-pipelines.yml:
image: bitbucket-pipeline:3.2
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
services:
docker:
memory: 6144
steps:
- step: &build-test-sonarcloud
size: 2x
name: Build, test and analyze on SonarCloud
services:
- docker
script:
- npm install --quiet
- npm run test -- --code-coverage --no-watch --no-progress -browsers=ChromeHeadlessNoSandbox
- pipe: sonarsource/sonarcloud-scan:1.4.0
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src
-Dsonar.tests=src/app
-Dsonar.test.inclusions="**/testing/**,**/*.spec.ts"
-Dsonar.coverage.exclusions="**/node_modules/**,**/*.spec.ts"
-Dsonar.typescript.lcov.reportPaths=coverage/lcov.info'
# Use the following pipe if we want the pipeline to fail when quality gate fails
# - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
I’m using unit tests (Jasmine/Karma) and e2e tests (Cypress, folder /cypress). Is it possible to scan Cypress tests too ?
The coverage is all the time 0%. While I don’t have a lot of tests yet, it sounds like the coverage isn’t working fine. Am I missing something ?
Do I need to include pipe sonarsource/sonarcloud-quality-gate:0.1.6 ? I want the code to be analyze but I don’t want the pipeline to fail when the quality gate fails.
SonarCloud relies completely on the coverage reports you specify to understand what code has been covered by tests. Is there actually coverage from your tests in the coverage/lcov.info you’ve passed to sonar.typescript.lcov.reportPaths?
You might find it useful to run a cat coverage/lcov.info in your pipeline prior to running the analysis.
There will also be logs from the sonarsource/sonarcloud-scan pipe that describe what’s happening during coverage import.
Well you… specified it in your analysis configuration.
SonarCloud only reads coverage reports, it isn’t involved in their generation. I would suggest going back to your coverage tool and making sure an lcov.info file is generated, so that you can properly pass it to the right test coverage parameter