The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Adding code coverage checking

Adding code coverage checking

3:24
Now that we have code coverage being reported, let's make sure that nobody commits code which drops code coverage below our standard by adding a `check-coverage` script that utilizes istanbul's built-in `check-coverage` command.
Watch this lesson now
Avatar
egghead.io

Now that we have code coverage being reported, let's make sure that nobody commits code which drops code coverage below our standard by adding a check-coverage script that utilizes istanbul's built-in check-coverage command.

Avatar
David

Definitely like this topic, and it may be WAY out of scope for this, but 100% coverage is really REALLY difficult. Might be best to drop that to realistic expectations, but I don't know what "real world" should be. I've worked on legacy/inherited apps for years, so I'm not the best to provide information on this one.

In reply to egghead.io
Avatar
Kent C.

I agree with you for apps, but for libraries, getting 100% code coverage is not only possible, but I recommend it and do it for most of my more recent libraries. The difference is that the codebase is much smaller, and you're also exposing an API which should be what you're testing. If you can't get to all of your lines of code through just using the API the way a user of your library would, then do you really need that code?

Code coverage isn't the answer to all of our questions, but it certainly helps make sure that you're not shipping code that simply wont run :-)

In reply to David
Avatar
janppires

Hi Kent!

How can we integrate this coverage checking with webpack?

I have been searching but I haven't found anything. =(

Thanks!

Avatar
janppires

I got the answer myself.

In an webpack usage, we still need to install "istanbul" dependency, just to run the command "istanbul check-coverage build/reports/web-coverage/coverage-final.json --statements 100 --branches 100 --functions 100 --lines 100" agains the "coverage-final.json" produced by karma-coverage.
So it's important to have reporter type as "json" in the reporters array of coverageReporter karma.config file.

coverageReporter : {
          dir: 'build/reports/web-coverage',
          reporters: [
              {type: 'json', subdir: '.'},
          ]
      },

Cheers

In reply to janppires
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?