Code Coverage

To set up code coverage - You need to activate the code health feature for your account. Once done, follow the below-mentioned steps to get started with code coverage-

Navigate to the code coverage section to get your account token details.

1. Creating Coverage Reports

Before you can use Typo to show code coverage metrics for your project, you need to run tests and use tools to generate reports that show how much of your code is covered by tests. Consider these points when generating coverage reports:

  • There are various tools available for generating coverage reports, but you need to make sure that the reports are in a format that Typo can understand.

  • Ensure that your coverage reports include data for all the code files that were tested, not just the ones that were changed in each commit.

  • Below is a table of example coverage tools that produce reports in formats supported by Typo:

2. Uploading coverage data to Typo

Once you've configured coverage reports, it's essential to utilize the Typo Coverage Script to upload them to Typo. The best practice for this task is to employ a CI/CD platform that automatically executes tests, generates coverage reports, and then employs the Typo Coverage Script to upload the coverage information to Typo.

Step 1

Add Typo Access Token to your environment variable as TYPO_ACCESS_TOKEN

![](https://app.typoapp.io/images/copy-icon.png)export TYPO_ACCESS_TOKEN=affe54bd-xxxxx-4839-xxxx-8850553xxxxx

Step 2

Add Typo Client ID to your environment variable as TYPO_CLIENT_ID

![](https://app.typoapp.io/images/copy-icon.png)export TYPO_CLIENT_ID=xxxxx

3. Add the coverage step to your build process

To ensure that your code coverage metrics are collected and reported accurately, you need to add the coverage step to your build process. This step involves running the following bash command after your tests have been executed, during your build process to upload the coverage report:

![](https://app.typoapp.io/images/copy-icon.png)bash <(curl -Ls https://typo-website-static.s3.ap-south-1.amazonaws.com/typo-coverage.sh) REPORT_PATH

REPORT_PATH: This should be replaced with the actual path to your coverage report file.

You need to execute this command at two specific points in your development workflow:

  • During Production Builds: This ensures that coverage data is collected for the code being deployed to production.

  • During Pull Request (PR) Creation or Modification: This helps to track and verify coverage for changes introduced by the PR.

Last updated