Problem with tested line coverage

When I push my code to Github, SonarCloud analysis tells me that my coverage is not big enough. However the untested lines are precisely into my test files… How can I fix this?

I attach my conf files:
YML file

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: '16.17.0'
      - name: Install
        run: npm install
      - name: Test
        run: npm test
      - name: Build
        run: npm run build
  quality:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
      - name: Quality SonarCloud
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Sonar properties

sonar.projectKey=guerin-jerome_front-gestinance
sonar.organization=guerin-jerome-1
sonar.javascript.lcov.reportPaths=./coverage/lcov.info


Hi,

Thanks for the screenshots. They help!

Analysis is seeing your test files as code files. Adding sonar.exclusions=**/*.test.js to your sonar-project.properties files will tell it they’re not. Telling analysis they’re actually tests is a bit harder, since they’re mixed in with your source files (the sonar.tests parameter expects a directory, rather than a pattern).

Does that help?

 
Ann

1 Like

Thank you !
sonar.exclusions=src/**/__tests__/**/* is the solution for me.

1 Like

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