Coverage Cypress tests


I’m trying to setup Sonar for an Angular app. Here is a part of my bitbucket-pipelines.yml:

image: bitbucket-pipeline:3.2

  depth: full              # SonarCloud scanner needs the full history to assign issues properly

    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
      memory: 6144
    - step: &build-test-sonarcloud
        size: 2x
        name: Build, test and analyze on SonarCloud
          - docker
          - npm install --quiet
          - npm run test -- --code-coverage --no-watch --no-progress -browsers=ChromeHeadlessNoSandbox  
          - pipe: sonarsource/sonarcloud-scan:1.4.0
              SONAR_TOKEN: ${SONAR_TOKEN}
              EXTRA_ARGS: '-Dsonar.sources=src
          # 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.

Thank’s a lot.

Hey there.

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/ you’ve passed to sonar.typescript.lcov.reportPaths?

You might find it useful to run a cat coverage/ 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.

For example:

INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: Analysing [/home/vsts/work/1/s/test-results/coverage/]
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=48ms

You only need to use this if you want to fail the pipeline on the Quality Gate.

Hi Colin,

I don’t have such file coverage/ The generated coverage folder reports looks like the following:


Here is my karm.conf.js:

// Karma configuration file, see link for more information
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    coverageIstanbulReporter: {
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    angularCli: {
      environment: 'dev'
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadlessNoSandbox'],
    singleRun: false,
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: "ChromeHeadless",
        flags: ["--no-sandbox"]
    check: {
      global: {
        statements: 80,
        branches: 80,
        functions: 80,
        lines: 80

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 file is generated, so that you can properly pass it to the right test coverage parameter

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.