Trying to use Codecov with your Javascript project? Start here.
To start you will need the following:
For easy reference here is our JavaScript Example repo that we will reference throughout the walk-through.
We will be taking advantage of the jest package to run our tests. We will need to create a package.json file.
To run your tests, run npm install && npm run test in a terminal window.
To get coverage results, we will need to update our jest settings. Create a file jest.config.js with the following contents:
Install the dependencies and run the tests to view code coverage:
Note that we are showing 80% code coverage.
Now that you have collected coverage locally, let’s learn how to upload these reports to Codecov. Codecov is often used in conjunction with continuous integration (CI) systems to ensure that new code changes are adequately covered by tests.
We will be using GitHub Actions as the Ci and the Codecov Action to upload coverage reports.
Create a file called .github/workflows/ci.yml
It is recommended that you install the Codecov app for this repository to prevent rate-limiting issues. Save your code and push up to GitHub.
In GitHub, open the pull request and wait for CI and Codecov to finish running and analyzing. You should see the following pull request commit:
You should also see four status checks, two of which come from Codecov:
Our status checks page contains more information on the meaning of each status check. When you are ready, merge the pull request.
Now that we can get coverage data in our pull request. Let’s take a look at how to increase coverage.
Let’s take a look at the coverage report from Codecov. Navigate to your repository from the Codecov UI. You should see a dashboard like this.
Notice that there are only 4 covered lines in the Code tree. If we click on app, and calculator.js, we’ll come to the file view:
From this view, we can tell that we haven’t written a test for our subtract function
Create a new branch in your terminal
and replace the test file app/calculator.test.js with the following code.
Save the code and open a new pull request.
Notice the Codecov comment shows the coverage increasing from 80.00% to 100.00%.
Now that you have uploaded your first Javascript coverage reports successfully to Codecov, you can check out some of our other features including
Updated 7 months ago