Test files included in coverage results on SonarCloud with Next.js and Jest

Hi everyone,

I’m working on a Next.js application and I’ve successfully set up unit testing using Jest, with coverage being reported to SonarCloud.

However, I’m running into an issue:
Test files themselves are being included in the coverage report, as if they were files that need to be tested. This is impacting the coverage percentage and the way the results are displayed in SonarCloud.

I’ve already configured collectCoverageFrom in my jest.config.js to include only relevant application files like app/** and components/**, and my test files follow the .test.tsx naming convention.

Is there a way to exclude test files from the coverage metrics or instruct SonarCloud to treat them correctly?

Any guidance would be appreciated!

Thanks in advance.

Hey there.

Just make sure that your test files are correctly categorized as test files (passing those files to sonar.tests) and they will no longer have executable lines calculated for them.

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