Search code examples
reactjstypescriptsonarcloud

Exclude the test files for React components in sonarcloud


I have a React application with the following folder structure

src
    components
        Component1
            Component1.tsx
            Component2.test.tsx
        Component2
            Component2.tsx
            Component2.test.tsx
    utils
    reducers
    pages

I would like to exclude the *.test.tsx files in the src folder from the sonar cloud coverage. I could move it to a test folder and then exclude the test folder from the coverage but that would be a very big change for the entire codebase.

I have a sonar-project.properties file that has a sonar.coverage.exclusions but I am not sure how to add it for this particular use-case.


Solution

  • I think, to exclude the *.test.tsx files in the src folder from the SonarCloud coverage, you can add the following line to your sonar-project.properties file:

    sonar.coverage.exclusions = src/**/*.test.tsx