Typescript execution report ignored during scanning the project

Hello,

I am trying to configure a dotnet-sonarscanner to analyze multiple ASP.NET core 7 project, having React application under ClientApp directory. I have generated a unit test execution report in generic xml format in an earlier job of my gitlab pipeline.
When the scanner tries to import the generic execution report it says the tests are not known.
It seems the scanner does not recognise my *.test.tsx files as unit tests.

05:42:38.655 INFO: Sensor Generic Test Executions Report
05:42:38.656 INFO: Parsing /builds/repos/digitalprod/business-process-tracking-tool/src/AB.EON.DIN.Web/ClientApp/reports/sonar-generic.xml
05:42:38.689 INFO: Imported test execution data for 0 files
05:42:38.689 INFO: Test execution data ignored for 20 unknown files, including:
ClientApp/src/components/Profile.test.tsx
ClientApp/src/components/common/controls/Subtask.test.tsx
ClientApp/src/components/common/controls/AddComment.test.tsx
ClientApp/src/components/CaseDistributor.test.tsx
ClientApp/src/components/common/layouts/ProfileDetail.test.tsx
05:42:38.689 INFO: Sensor Generic Test Executions Report (done) | time=34ms

The parameters I have provided:

- dotnet sonarscanner begin 
    /k:"$SONAR_KEY"
    /d:sonar.login="$SONAR_TOKEN" 
    /d:sonar.host.url="$SONAR_HOST_URL" 
    /d:sonar.scm.provider=git
    /d:sonar.sources="src/"
    /d:sonar.exclusions="$SONAR_EXCLUSIONS"
    /d:sonar.tests="src/"
    /d:sonar.test.inclusions="AB.EON.DIN.Web/**/*test.tsx, AB.EON.DIN.BusinessLogic.Test/**/*,"
    /d:sonar.dotnet.excludeTestProjects=true 
    /d:sonar.sourceEncoding=UTF-8
    /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
    /d:sonar.javascript.lcov.reportPaths=**/coverage/lcov.info
    /d:sonar.cs.vstest.reportsPaths="$VSTEST_REPORTS"
    /d:sonar.cpd.exclusions="$SONAR_CPD_EXCLUSIONS"
    /d:sonar.testExecutionReportPaths=AB.EON.DIN.Web/ClientApp/reports/sonar-generic.xml

The variables above:
SONAR_EXCLUSIONS: “/ClientApp/public/chatbot//, /ClientApp/config//, /ClientApp/scripts/, **/ClientApp/src/services/generated-client.ts, **/ClientApp/aspnetcore-.js, src/AB.EON.DIN.Web.Admin//.test.tsx"
SONAR_CPD_EXCLUSIONS: "AB.EON.DIN.Web.Admin/ClientApp/src/components/common/**/
”

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!
complete_verbose_20230428.txt (1.3 MB)

Hi,

If you’re using SonarScanner for .NET, then you shouldn’t need to explicitly define sonar.sources or sonar.tests. Did you add those parameters to fix a problem or because you thought you needed to?

Regarding your test execution data, do the paths in your report match the paths analysis sees? Explicitly,

05:42:38.689 INFO: Test execution data ignored for 20 unknown files, including:
ClientApp/src/components/Profile.test.tsx
ClientApp/src/components/common/controls/Subtask.test.tsx
ClientApp/src/components/common/controls/AddComment.test.tsx
ClientApp/src/components/CaseDistributor.test.tsx
ClientApp/src/components/common/layouts/ProfileDetail.test.tsx

Does analysis see those files in ClientApp/src/components or is the path longer? One way to know is to find the files under the Code tab in SonarQube and see what paths the UI displays for them.

 
HTH,
Ann

Hi,
these test.tsx files do not appear on sonar UI (" … find the files under the Code tab in SonarQube and see what paths the UI displays for them")

It seems the sonar does not think these files are tests, or any other way are parts of the files.

Thanks,
Istvan

Hi Istvan,

We’ve gotten to the root problem: The files aren’t recognized during parsing of the generic test data report because they’re not recognized as tests or imported at all during analysis.

Could you try reanalyzing without all the extra parameters to see if that helps?

 
Ann

Hi Ann,

I tried reanalyzing the branch having the sonar.sources, and sonar.tests removed.
But everything remains the same:

  • the generic execution report ignored:
" INFO: Sensor Generic Test Executions Report

[2223]INFO: Parsing /builds/repos/digitalprod/business-process-tracking-tool/src/AB.EON.DIN.Web/ClientApp/reports/sonar-generic.xml

[2224]INFO: Imported test execution data for 0 files

[2225]INFO: Test execution data ignored for 20 unknown files, including:

[2226]ClientApp/src/components/Profile.test.tsx

[2227]ClientApp/src/components/common/controls/Subtask.test.tsx

[2228]ClientApp/src/components/common/controls/AddComment.test.tsx

[2229]ClientApp/src/components/CaseDistributor.test.tsx

[2230]ClientApp/src/components/common/layouts/ProfileDetail.test.tsx

[2231]INFO: Sensor Generic Test Executions Report (done) | time=32ms"

And the *.test.tsx files remain excluded from the code (not showing on the UI)

BR,
Istvan

Hi Istvan,

I’ve just looked up the .tsx file extension & see that it’s an old one related to TypeScript.

At this point I’m wondering if this is about the SonarScanner for .NET not picking up the files or about the file extension not being recognized. Are you using .NET Core, .NET 5 or later? If not the docs, tell you how to make sure those files are picked up.

 
Ann

Hi Ann,

I am using .NET 7. Is it possible on the sonarqube site, that “*test.tsx” files are exluded? (I do not have access to the project config in Snoarqube server)

BR,
Istvan

Hi Istvan,

While writing my answer, I dug in and found that .tsx is in the default list of file extensions for TypeScript, so that shouldn’t be it - unless your list has been overridden. Do you have access to Project Settings → Background Tasks → [ row cog menu ] → Show Scanner Context? I believe it would show up there if it’s set to a non-default value (altho I’m not 100% on that).

 
Ann

Hi Ann,

Actually in general the code includes the *.tsx files. For example on the UI of Sonarcube there is the ClientApp/src/components/Profile.tsx file, but the test file belonging to that file (Profile.test.tsx is missing)

This file is not showhn in the Code tab of the Sonarqube.

I do not have access to the project settings menu. I have to ask the admin to share that with me…

BR,
Istvan

1 Like

Hi Istvan,

Knowing that some .tsx files get included is enough for now. I’m going to flag this for more expert eyes.

 
Ann

@ilaki2016 currently your test inclusions are set as follows:

sonar.test.inclusions=AB.EON.DIN.Web/**/*test.tsx, AB.EON.DIN.BusinessLogic.Test/**/*

What happens if you change them to the following?

sonar.test.inclusions=**/AB.EON.DIN.Web/**/*test.tsx, **/AB.EON.DIN.BusinessLogic.Test/**/*