Template for a good new topic, formatted with Markdown:
ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI)
Scanner command used when applicable (private details masked)
Languages of the repository
Only if the SonarCloud project is public, the URL
And if you need help with pull request decoration, then the URL to the PR too
Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
We have a Typescript project with .test.ts and .test.tsx scattered around the app. SonarCloud is connected to our GitHub repo and we have a file in the root of the project called sonar-project.properties. The file contains this code:
Now, I think this would make it so that the quality gate doesn’t look for duplicated code in test files, but it still does. I also tried changing sonar.tests to sonar.exclusions but the results were the same. Is there something I’ve missed?
Steps to reproduce
Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!
The sonar.sources and sonar.tests properties are not expecting wildcards. They accept
Comma-separated paths to directories containing…
So your sonar.tests property isn’t having much effect.
It’s true that duplications should not be detected in test files. If they are, then that implies your tests are located somewhere under src. That means you’ll have to go a little further to make this work:
sonar.exclusions=**/*.test.ts,**/*.test.tsx` #yes, patterns work for _this_ property
# Define the same root directory for sources and tests
sonar.sources = src/
sonar.tests = src/
# Include test subdirectories in test scope
sonar.test.inclusions = src/**/test/**/*
# Exclude test subdirectories from source scope
sonar.exclusions = src/**/test/**/*
It’s true, our test files are in random folders in our src folder. I already tried using sonar.exclusions and it didn’t work either. Have I misunderstood where the sonar-project.properties file should be located or something?
Did you use it in combination with the other properties as I described above?
Good question. You left a lot of the initial topic template empty. (It is there for a reason, you know. )
Which scanner are you using / what’s your analysis command? If you’re using the Sonar Scanner CLI, then these properties would go in sonar-project.properties in your project root / the directory from which analysis is launched.
You can check your SonarScanner Context (Administration → Background Tasks → [analysis row vertical dots menu] → Show SonarScanner Context) to see what properties analysis ran with.