Hi,
I’m using a Vue CLI-generated project structure and use Jest for unit testing (https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-jest). By default the Jest configuration offers two alternatives where Jest is looking for tests <rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))
- inside a dedicated structure
/tests/unit/**/*
- or inside any subdirectory
**/__tests__
I want to use the second approach as the test code is located closer to the production code. This leads to a directory structure like
- production code
/src/components/hello-world
- test code
/src/components/hello-world/__tests__
As Sonarqube supports the usage of wildcards in other analysis parameters (https://docs.sonarqube.org/latest/analysis/coverage/) I gave this configuration a try to mark these files as test code and to exclude them from analysis:
sonar.sources=src
sonar.tests=**/__tests__/*
The scan fails with
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project hello-world: The directory '/var/lib/tomcat8/data/jenkins/jobs/hello-world/jobs/sonar/workspace/gui/**/__tests__/*' does not exist for Maven module [...]. Please check the property sonar.tests -> [Help 1]
Regarding the SonarQube documentation, this seems to be the expected result. The parameter sonar.tests
is defined as “Comma-separated paths to directories containing test source files.”. No word about the option to use wildcards here.
But what would be the correct way to configure the scanner in this scenario?
Environment
sonar-maven-plugin: 3.7.0.1746
SonarQube version: 7.9.1