Search code examples
reactjscypresspipelinesonarcloudcypress-code-coverage

SonarCloud Code Coverage doesn't work with Github Action


I tried to pass my code coverage report generated by cypress tests with Github Action, but it arrives at SonarCloud with 0% coverage. In my pipeline, i get the following warn:

WARN: Could not resolve 7 file paths in [/github/workspace/coverage/lcov.info]

WARN: First unresolved path: C:\Users\ferso\OneDrive\Documentos\Faculdade\cypress-test\src\App.jsx (Run in DEBUG mode to get full list of unresolved paths)

I Already tried to use sed ci utility to correct file paths and use sonar.javascript.lcov.reportPaths=coverage/lcov.info, but it didn't works

This is my sonar-project.propertie:

sonar.projectKey=fsoupimenta_cypress-test
sonar.organization=fsoupimenta
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.javascript.file.suffixes=.js,.jsx

and this is my SonarCloud workflow:

      - name: fix code coverage paths
        working-directory: ./coverage
        run: |
          sed -i 's/\/home\/runner\/work\/cypress-test\/cypress-test\//\/github\/workspace\//g' lcov.info
          sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' lcov.info
          sed -i 's/\/home\/runner\/work\/cypress-test\/cypress-test\//\/github\/workspace\//g' sonar-cloud-reporter.xml
          
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Solution

  • Update: I fixed this error by adding two properties in sonar.project-properties, staying like this:

    sonar.projectKey=fsoupimenta_cypress-test
    sonar.organization=fsoupimenta
    sonar.sources=src
    sonar.tests=cypress/e2e/spec.cy.js
    sonar.typescript.lcov.reportPaths=coverage/lcov.info
    

    You can see this repository for more information