NFO: Sensor Zero Coverage Sensor (done)

Hi,
In my project I have .ts files, I changed the settings in typescript under administration in SonarQube. I am using gitlab-ci.yml file following is the code

sonarqube:

  stage: sonarqube

  interruptible: true

  allow_failure: true

  image:

    name: sonarsource/sonar-scanner-cli:latest

  needs: ['install']

  

  variables:

    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"

    GIT_DEPTH: 0

  cache:

    key: ${CI_JOB_NAME}

    paths:

      - .sonar/cache

  script:

      - options="-Dsonar.qualitygate.wait=false -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.sources=$CI_PROJECT_DIR -Dsonar.projectKey=sift-api -Dsonar.projectVersion=$CI_BUILD_ID" 

      - echo "Scanning with $options"

      - NODE_PATH=$NODE_PATH:/usr/lib/node_modules sonar-scanner -X $options

Even though SonarQube stage is success. My code coverage is zero (INFO: Sensor Zero Coverage Sensor)



Please let me know if you need more info.
Thanks.

Hello Jay,

Thank you for your message, and welcome to the SonarSource community!

Your GitLab CI/CD setup needs to run your unit tests, generate the coverage report, and tell the scanner where to find that report with the sonar.javascript.lcov.reportPaths property to import that information to SonarQube. Neither SonarQube nor SonarScanner will do that for you.

As you can guess from the property name, the JavaScript/TypeScript analyzer supports the LCOV format for coverage reports, which is generally materialized as a lcov.info file by JavaScript/TypeScript testing frameworks.

For your reference, here is SonarQube Documentation about Test Coverage & Execution.

Hope this helps,
Yassin

@Yassin Thanks for your response.
I am having following statges
stages:

  • install
  • quality
  • test
  • sonarqube
  • review
  • build
    In test I am generating cobertura.xml and after test I have sonarqube stage. Following is the stage
test:
  stage: test
  interruptible: true
  image: node:${NODE_VERSION}-alpine
  <<: *use_npm
  needs: ['install']
  script:
    - *use_environment
    - *pretest
    - unset APOLLO_KEY
    - unset APOLLO_GRAPH
    - unset APOLLO_GRAPH_VARIANT
    - JEST_CI=1 npx nx affected:test --parallel --base=$BASE --codeCoverage --ci
  after_script:
    - test -d coverage && find coverage -name cobertura-coverage.xml -exec sh -c 'echo $(dirname "{}" | sed "s=coverage/\(apps\|libs\)/==i" | sed "s=/=-=gi")={}' \; | xargs npx cobertura-merge -o .cobertura-coverage.merged.xml
    - cat .cobertura-coverage.merged.xml
  artifacts:
    name: test-artifacts
    untracked: false
    expire_in: 14 days
    paths:
      - coverage
      - junit
    reports:
      cobertura: .cobertura-coverage.merged.xml
      junit: junit/**/junit*.xml

sonarqube:
  stage: sonarqube
  dependencies:
    - test
  interruptible: true
  allow_failure: true

  image:
    name: sonarsource/sonar-scanner-cli:latest
  
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
    GIT_DEPTH: 0

  cache:
    key: ${CI_JOB_NAME}
    paths:
      - .sonar/cache

  script:
      - options="-Dsonar.qualitygate.wait=false -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.flex.cobertura.reportPath=.cobertura-coverage.merged.xml
        -Dsonar.projectKey=sift-api -Dsonar.projectVersion=$CI_BUILD_ID" 

      - echo "Scanning with $options"
      - NODE_PATH=$NODE_PATH:/usr/lib/node_modules sonar-scanner -X $options  

Still code coverage is zero. :slightly_frowning_face:
Thanks.

Hello again,

Looking at your updated stages, I see that you are using the Covertura XML format and you are trying to import your report using a property from the Flex analyzer. As I mentioned in my previous message, our JavaScript/TypeScript analyzer only supports LCOV format for importing code coverage. Please give it another try with this format and use the appropriate JS/TS property of the scanner to import your coverage report.

Regards,
Yassin