How to import the jasmine report to sonarqube for analysis

4.6k Views Asked by At

We are using SonarQube version 5.2 and it is set up with jenkins to report the code coverage on SonarQube server currently only java code coverage is in place on sonarQube and now we are aiming to Fail the jenkins build if the project fails the quality gate and also Is it possible to integrate the jasmine test for javascript with SonarQube and how to acheive it

1

There are 1 best solutions below

2
Royalsmed On

To make build success depend on quality measures, you can add a threshold into your jasmine karma testing.

  1. In you karma.conf.js you may add:

    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly', 'text-summary', 'cobertura' ],
      fixWebpackSourcePaths: true,
      thresholds: {
        statements: 100,
        lines: 100,
        branches: 100,
        functions: 100
      }
    },
    

This makes ng test --watch=false --code-coverage fail if the coverage is less than 100% you can of course change the threshold to your team needs.

  1. Code style can be checked with ng lint using tslint

  2. Make SonarQube check your source code by adding sonar-project.properties to the root folder

    sonar.projectKey=YOUR_PROJECT_KEY
    sonar.projectName=YOUR_PROJECT_NAME
    sonar.projectVersion=YOUR_VERSION
    
    sonar.sources=src
    sonar.exclusions=**/node_modules/**
    sonar.tests=src/app
    sonar.test.inclusions=**/*.spec.ts
    sonar.sourceEncoding=UTF-8
    sonar.ts.tslintconfigpath=tslint.json
    sonar.typescript.lcov.reportPaths=coverage/lcov.info
    

In your CI config you need to ensure that you are executing ng test --code-coverage, tslint and you need to activate SonarQube.

happy coding