Coverage exclusion for test files not working

Hi,

I was following this guide to set up my coverage reports: Narrowing the Focus | SonarQube Docs

My repo uses a modern style where test files are intermingled with source files, so I ended up with something like the suggestion from the guide:

# 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/**/*

However, sonar keeps asking for coverage for my .spec.ts files.

I have tried several configurations, including sonar.coverage.exclusions but it is always asking me to cover my spec files.

example folder structure
- libs
  - some_lib
    - __test__
         - index.spec.ts
    - index.ts
## Define the same directory for sources and tests
sonar.sources=apps/,libs/
sonar.tests=apps/,libs/
## Include in test scope: test+mock files/subdirectories
sonar.test.inclusions=[apps,libs]/**/__test__/**/*
## Exclude from source scope: test+mock files/subdirectories, generated libs
sonar.exclusions=[apps,libs]/**/__test__/**/*,./libs/api-migrations/**,./libs/api-client/**,
## Exclude from coverage: test+mock files/subdirectories
sonar.coverage.exclusions=[apps,libs]/**/__test__/**/*

Hi,

Welcome to the community!

This isn’t a recognized pattern. You’ll need to actually spell this out, comma-delimited:

sonar.test.inclusions=apps/**/__test__/**/*,libs...

 
HTH,
Ann

Thanks, this works.

I thought I confirmed glob patterns to be working. It would be great if the docs could be more clear on this, i.e. where and which patterns work.

Hi,

This page is pretty specific:

The patterns are defined using the following wildcards:

  • * - Match zero or more characters
  • ** - Match zero or more directories
  • ? - Match a single character

Were you looking some place else?

 
Ann

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.