How to publish the test coverage report in your React application
In this post we are going to see how to publish the test coverage report in your React application. For this we will use:
A Perfect "alternative" for SonarQube for a small projects.
It is not common or necessary to publish your test report of your application, there will even be those who think that it is somewhat imprudent because You can expose sensitive information from your application. But the main idea of this is that if you have an open source project and you want so that people can contribute, it's a good idea that they can see the test report so they know how well your project is covered or because you want to teach people how to test an application.
However, to have extra security, it is as simple as having it in a protected path with a username and password.
PD: This example is developed in a web application made with Nextjs but it works for any web application that uses jest.
1. Path for the report
The first thing we need to do is assign the jest outputDirectory to a public folder
2. Script to modify the report
What this script does is modify the path of the static files that the report needs to function as images, css, javascript, etc. In addition, some report texts are customized.
The alternative if you use class is to use the class CustomReporter and implement the onRunComplete method.
3. Command to generate the report when the build is generated
In order for the report to be generated in the public folder when the build is finished, we need to add the following commands in the package.json
4. Create a redirect on the server/cloud platform
In my case I use Vercel but whatever platform you use, you must create a redirect so that any
Here you can see an example of what the test report of this blog looks like xabierlameiro.com/coverage