Code Coverage in Codeac - How to Start

Code Coverage in Codeac - How to Start Code Coverage in Codeac - How to Start Code Coverage in Codeac - How to Start Code Coverage in Codeac - How to Start
Measuring how much of your code is covered by tests is a key part of maintaining code quality. Thanks to Codeac, you can now see the Code Coverage directly in our UI. In this blog post, we’ll guide you through the setting process.

Code coverage is a metric that shows what percentage of your codebase is executed when running tests. When your tests include meaningful assertions, you can be more confident that things work and that future changes won’t break anything unexpectedly. Code coverage also helps identify untested parts of your code, allowing you to improve test quality over time.

Step 1: Generate LCOV from Your Test Framework

Currently, we support code coverage for JavaScript and TypeScript only. Support for additional languages is coming soon. If there's a specific language you'd like us to prioritize, feel free to reach out at support@codeac.io.

Configuration for Jest

If you’re using Jest, collecting coverage is really simple. Just add a few lines to your jest.config.js:

jest.config.js

module.exports = {
	collectCoverage: true,
	coverageReporters: ['lcov'],
	coverageDirectory: '<yourCoverageOutputPath>',
}

Now, when you run your tests with npx jest, Jest will produce a nice little file at <pathWhereToStoreYourCoverageLogs>/lcov.info. This is the exact format Codeac understands, so no extra conversions or tooling is required.

Step 2: Generate a Token for Accessing the Repository from CI

Before we can get that LCOV file into Codeac, we need a way for your CI pipeline to talk to us securely.

In your repository settings on Codeac.io, generate a Token. This token allows your CI pipeline to securely upload the <pathWhereToStoreYourCoverageLogs>/lcov.info file to Codeac.

Generate Token in Codeac
Generate Token in Codeac.

Step 3: Set up Code Coverage Upload in CI

In your CI environment, store the token as a secret in your CI environment (e.g. TOKEN).

Once your tests are done and the lcov.info file is generated, it’s time to upload it.

Here’s a simple curl command you can drop into your CI script:

code-coverage-command.sh

curl -X POST -H "x-repository-token: $TOKEN" \
--data-binary @<yourCoverageOutputPath>/lcov.info \
"https://api.codeac.io/v1/coverage/$(git rev-parse HEAD)?branch=$(git rev-parse --abbrev-ref HEAD)&language=JavaScript" \
|| true

This pushes the coverage report to Codeac, tied to the commit and branch that triggered the pipeline.

Code Coverage in Codeac

Codeac and your CI pipeline run in parallel, so code quality and coverage results may appear in the UI at different times. It can take a few minutes for all results to show up.

Step 4: View Code Coverage in Codeac

Once the report is uploaded, you can view coverage results directly in Codeac in several places:

  • Dashboard - Check coverage for each commit and file.
  • Commit Detail - See overall coverage trends across your repositories
  • Thresholds - Set minimum coverage targets and get alerts if they drop.

This helps you maintain healthy testing habits as your codebase grows.

Step 5: Setting up the Thresholds

Sometimes it's not enough to just see coverage, you want to enforce a standard.

That’s where thresholds come in. Codeac already supports thresholds for issues. Now, you can combine those with Code Coverage thresholds to get a single, unified commit status.

Here's an example of .codeac.yml file to get you started:

.codeac.yml

version: '1'

thresholds:
    error: 10
    total: 50
    coveredBranches: 70
    coveredFunctions: 75
    coveredLines: 80

The result? Codeac will report a failed commit status if these thresholds aren't met, just like it does when your code has too many issues. It’s a great way to reinforce your testing and coding standards together.

These thresholds show up in your Git provider as part of the CI status. Clicking that status leads directly to the detailed Codeac analysis, where you can dig into both code issues and coverage insights in one place.

Conclusion

Adding Code Coverage to your Codeac workflow only takes a few minutes, but the visibility it gives you can be game-changing. You’ll quickly spot weak spots in your tests. By combining coverage with existing issue thresholds, you get a single, unified commit status that reflects both code quality and code coverage. It helps you enforce testing standards automatically, and keep your team confident in the code they ship.

If you have any feedback, questions, or suggestions on how we can improve this feature, please don’t hesitate to reach out at support@codeac.io. We’d love to hear from you. So go ahead and give it a try.

Ready to get started?

Use your favorite version control system to sign-up.

Sign up for free