When checking analysis from Azure DevOps builds (.NET + Typescript) I got that message at top right corner saying there are warnings in last analysis:
Specifying module-relative paths at project level in the property ‘sonar.exclusions’ is deprecated. To continue matching files like ‘web-client/src/app/s/p.service.spec.ts’, update this property so that patterns refer to project-relative paths.
However, such file only matches patterns provided in sonar.test.inclusions
and sonar.coverage.exclusions
;
In task Prepare Analysis Configuration, sonar.coverage.exclusions
is set using extra properties, along others, this is the output from the build:
sonar.coverage.exclusions=**/*Migrations/**,**/*Test/**,**/*Tests/**,**/environments/environment*.ts,**/*.conf.js,**/src/main.ts,**/lib/h/*.s.ts,**/src/polyfills.ts,**/src/test.ts,**/lib/h/*.s.ts,**/lib/e/*.e.ts,**/lib/m/*.m.ts,**/e2e/src/app.e2e-spec.ts,**/e2e/src/app.po.ts,**/*.spec.ts,**/app-config.ts,**/*.interface.ts,**/a/*.s*.ts,**/C.cs,**/S.cs,**/*.t.ts
sonar.coverageReportPaths=d:\a\_temp\CodeCoverage\Merged\SonarQube.xml
sonar.exclusions=**/coverage-include-all.spec.ts,**/TestResultJunit/*.xml,no_extra_exclusion_but_a_value_is_needed_after_comma
sonar.tsql.file.suffixes=.sql,.tsql
sonar.plsql.file.suffixes=.plsql,.pkb
The .csproj containing the file mentioned in the warning is at d:\a\753\s\web-client
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DefaultItemExcludes>**/*.*</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<None Include="d:\a\753\s\web-client\**" Exclude="d:\a\753\s\**\node_modules\**;d:\a\753\s\**\.*\**;d:\a\753\s\web-client\dist\**;d:\a\753\s\web-client\coverage\**;d:\a\753\s\web-client\TestResultJunit\**" />
<SonarQubeSetting Include="sonar.test.inclusions">
<Value>**/*.spec.ts,**/*.spec.js,**/*.mock.ts,**/*.mock.js,**\\web-client\\src\\app\\test-helper\\*.*</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.tests">
<Value>d:\a\753\s\web-client</Value>
</SonarQubeSetting>
</ItemGroup>
</Project>
MSBuild goes fine, project is correctly categorized as MAIN. It contains an angular website.
In Run Code Analysis task, I can see the warning at the beginning already:
The warning also appears in this output, but at the begining:
INFO: Organization key: orgkey
INFO: Branch name: aa, type: short-lived
INFO: Preprocessing files...
WARN: Specifying module-relative paths at project level in the property 'sonar.exclusions' is deprecated. To continue matching files like 'web-client/src/app/s/p.service.spec.ts', update this property so that patterns refer to project-relative paths.
INFO:
INFO: 9 languages detected in 99 preprocessed files
INFO: 999 files ignored because of inclusion/exclusion patterns
And later I can then see project related output:
INFO: Indexing files of module 'WebClient'
INFO: Base dir: D:\a\753\s\web-client
INFO: Source paths: .editorconfig, .gitignore, .npmrc, angular.json, WebClient...
INFO: Test paths: .
INFO: Excluded sources: **/build-wrapper-dump.json, **/coverage-include-all.spec.ts, **/TestResultJunit/*.xml, no_extra_exclusion_but_a_value_is_needed_after_comma, **/*.spec.ts, **/*.spec.js, **/*.mock.ts, **/*.mock.js, **\\web-client\\src\\app\\test-helper\\*.*
INFO: Included tests: **/*.spec.ts, **/*.spec.js, **/*.mock.ts, **/*.mock.js, **\\web-client\\src\\app\\test-helper\\*.*
INFO: Excluded sources for coverage: **/*Migrations/**, **/*Test/**, **/*Tests/**, **/environments/environment*.ts, **/*.conf.js, **/src/main.ts, **/lib/h/*.s.ts, **/src/polyfills.ts, **/src/test.ts, **/lib/h/*.s.ts, **/lib/e/*.e.ts, **/lib/m/*.m.ts, **/e2e/src/app.e2e-spec.ts, **/e2e/src/app.po.ts, **/*.spec.ts, **/app-config.ts, **/*.interface.ts, **/a/*.s*.ts, **/C.cs, **/S.cs, **/*.t.ts
In it I can see test inclusions were also taken as excluded sources, what seems to trigger the warning, so such warning would not be caused by something I’m directly doing.
At the same time, the pattern matching that file is **/*.spec.ts
what perfectly describes what I really want, any file with extension .spec.ts is a test file doesn’t matter where it is.
According to the warning, I should change such pattern to be project-relative, but I’m not sure what that really means, tried following but none worked completely:
*/**/*.spec.ts
- still got warningsrc/**/*.spec.ts
- still got warning./**/*.spec.ts
- no warnings, but file was not considered a test file, so the pattern didn’t workd:/a/753/s/web-client/**/*.spec.ts
- no warnings, but file was not considered a test file, so the pattern didn’t work- despite not really the pattern involved in warning, I changed
**\\web-client\\src\\app\\test-helper\\*.*
tosrc/app/test-helper/*.*
Is this warning really correct in this scenario? If so what should I use as a pattern to get my test files taken as tests and no warnings?