JavaScript code coverage
Code coverage provides information about whether, and optionally how often certain parts of an application have been executed. It’s commonly used to determine how thoroughly a test suite exercises a particular codebase.
Why is it useful?
As a JavaScript developer, you may often find yourself in a situation in which code coverage could be useful. For instance:
- Interested in the quality of your test suite? Refactoring a large legacy project? Code coverage can show you exactly which parts of your codebase is covered.
- Want to quickly know if a particular part of the codebase is reached? Instead of instrumenting with
console.log
forprintf
-style debugging or manually stepping through the code, code coverage can display live information about which parts of your applications have been executed. - Or maybe you’re optimizing for speed and would like to know which spots to focus on? Execution counts can point out hot functions and loops.