Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 835 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Add code coverage reporting

3:59 JavaScript lesson by

Now that we're keeping track of our coverage, let's upload our reports to a third party service so we can track our stats over time. In this lesson we'll show how easy it is to upload our stats to codecov.io.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

Now that we're keeping track of our coverage, let's upload our reports to a third party service so we can track our stats over time. In this lesson we'll show how easy it is to upload our stats to codecov.io.

Avatar
David

Something that's been kinda bothering me... If you create a GitHub issue, and then use "closes #ISSUE_NUMBER", it's closed before the build is even done on Travis CI.

Thoughts?

Avatar
Kent C.

That bothers me a bit too. Jira smart commits have similar issues. I generally just let it be. But if you want, you might simply put "#ISSUE_NUMBER" so it's linked, but not closed.

However, if your library has ghooks installed and you're basically running what Travis is running, you can feel fairly confident that what you're pushing up is going to work out. Just some thoughts :-)

In reply to David

Now that we have coverage reporting going in our project, we want to actually send these reports to a third party service so that we can have one of those cool badges on our project that says we have 100 percent coverage. We can also browse our coverage in our project.

We're going to use a service called Codecov. If we go to Codecov.io, you'll want to sign up for an account and log in. Then let's just go to codecov.io/github/kentcdodds/starwarsnames. This will indicate that we have no reports uploaded, but it will give us an upload token, which I will hide so you can't see.

You'll notice that this upload token is actually not required on Travis because there's an integration there. Adding this integration with Codecov will be really easy. All that we need to do is NPM install -d as a devDependency codecov.io. Then we'll go into our package, JSON.

We'll see that codecov.io has been added. We're going to take one of the coverage stats here, and we're going to pipe it into the Codecov binary. Let's look into our Node modules in the .bin. We have a Codecov binary that we can use in our NPM scripts.

Let's make a new script called, "Report coverage." We will simply cut our coverage/lcov.info. We'll pipe that into Codecov. We want this to run on Travis, After our success we'll run NPM run report coverage.

The test single will create the coverage. Then we'll check that our coverage is up to standard. Then we'll report the coverage to Codecov, that we can have that reporting and history of our coverage. If we look at our git status, we have these modified files. Let's add them and make sure that they're there.

Now we'll run our NPM run commit. We'll expand this. We'll say that this is a chore related to test add reporting to Codecov. We'll add a description. We don't have any issues on here. It's running our test, making sure our coverage is up to snuff. Then we'll get push those changes.

Let's go ahead and take a look at our Travis. Here in just a moment it will start our new build. It's starting our build. We'll follow the log. It fails, but the failure is from Symantec release. This is after the success of our build. It's just simply Symantec release saying, "There are no new changes that are necessary to be released because this was simply a chore."

Our build passed. Now if we look at Codecov and we refresh, we'll see that we have our reporting stats in here, which is really handy. One of the things that I really like about Codecov is they have a Chrome extension that you can install.

If we refresh we'll get our coverage reporting in here. We can toggle that reporting on. If we didn't have a 100 percent coverage, then we would see some red lines in here. It's integrated with GitHub, which is really nice. That's how you report coverage statistics to Codecov.

In review, you simply install Codecov as a devDependency. You add a report coverage script to your NPM scripts, which will cut the LCOV info file to Codecov. Then you add this report coverage to your, "After success," to actually report the coverage.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?