Hi, I’m testing the exclusion logic using a Sonarqube 10.5.1 community Docker image. The Sonar Scanner version is 5.0.1. Our test files are located in the same folders as the source file and we’d like to exclude them from the scans. Below are some examples how the source and test files are named:
I tried setting sonar.exclusions to **/*test.ts, **/*test.js and **/*.test.ts, **/*.test.js, but in both cases, I can still see the test files shown in the scan results page.
What is the proper way to exclude the test files from the scan? Any suggestion will be greatly appreciated. Thanks for your time.
Thanks. Are these files being indexed as test files (which would seem expected)? In that case, sonar.test.exclusions would need to be used (but if your test files are being indexed as test, there’s nothing wrong with that, and they aren’t even counting towards your license).
You can see how individual files are indexed by turning on DEBUG analysis logs (sonar-scanner -X or setting -Dsonar.verbose=true as an analysis parameter)
Thanks, Colin.
I specify the exclusion options as below: "sonar.exclusions": "*/*.test.ts, **/*.test.js", "sonar.test.exclusions": "*/*.test.ts, **/*.test.js", "sonar.verbose": "true"
I captured some of the log messages below:
...
20:26:22.598 DEBUG: 'packages/alchemy-theme/src/helpers/breakpoint.test.ts' indexed as test with language 'ts'
20:26:22.600 DEBUG: 'packages/alchemy-theme/src/helpers/color.test.ts' generated metadata as test with charset 'UTF-8'**
20:26:22.600 DEBUG: 'packages/alchemy-theme/src/helpers/color.test.ts' indexed as test with language 'ts'
...
20:27:42.593 DEBUG: Cache entry created for key
20:27:42.593 DEBUG: Cache strategy set to 'WRITE_ONLY' for file 'packages/alchemy-theme/src/helpers/color.test.ts' as current analysis requires all files to be analyzed**
20:27:42.593 DEBUG: Analyzing file: file:///home/jenkins/alchemy/packages/alchemy-theme/src/helpers/color.test.ts****
20:27:42.596 DEBUG: Analyzing file "/home/jenkins/alchemy/packages/alchemy-theme/src/helpers/color.test.ts" with linterId "default" 20:27:42.609 DEBUG: Parsing /home/jenkins/alchemy/packages/alchemy-theme/src/helpers/color.test.ts with @typescript-eslint/parser**
20:27:42.612 DEBUG: Cache entry created for key 'jssecurity:ucfgs:SEQ:10.13.2.25981:com.medallia.alchemy:packages/alchemy-theme/src/helpers/color.test.ts' containing 0 file(s)**
20:27:42.613 DEBUG: Cache entry created for key 'jssecurity:ucfgs:JSON:10.13.2.25981:com.medallia.alchemy:packages/alchemy-theme/src/helpers/color.test.ts'**
20:27:42.614 DEBUG: Cache entry created for key 'js:filemetadata:10.13.2.25981:com.medallia.alchemy:packages/alchemy-theme/src/helpers/color.test.ts'**
...
20:28:24.290 DEBUG: File already analyzed: '/home/jenkins/alchemy/packages/alchemy-theme/src/helpers/color.test.ts'. Check your project configuration to avoid files being part of multiple projects.
...
From the message, it appears the test files are still analyzed as sources?