Sonarcloud on React using ViTest has snapshot test failures

Using Sonarcloud with our Bitbucket repo and a Jenkins build pipeline

Some background:

We’ve recently switched from Jest to Vitest for testing in our React app, and we’ve been running into issues with snapshot tests failing during our Jenkins builds. Even though we’ve manually updated the snapshots locally, SonarCloud is still flagging them as failed in the pipeline. What’s odd is that despite the snapshots being regenerated, Jenkins seems to find discrepancies between the old and new ones.

Additionally, even though Vitest is generating the coverage report, SonarCloud isn’t receiving it when the tests fail. My understanding is that SonarCloud should still be able to process coverage data regardless of some test failures. We’ve excluded the snapshot files from coverage and duplication checks in SonarCloud, but that alone doesn’t seem to resolve the issue since the tests are still failing outright.

Any thoughts on why this might be happening or what we can do to ensure both the tests and coverage reporting work smoothly?

Hey there.

I don’t think there’s any advice this Community can offer about your tests failing.

As far as test coverage goes, SonarCloud relies on the reports passed to it at analysis time – so your coverage reporting will rely on your coverage tool of choice. SonarCloud just reads the report it is given, whether or not the tests are failed.