Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Allow parts of code to be skipped for the purposes of coverage reporting
Browse files Browse the repository at this point in the history
1. Coverage can be explicitly skipped using comments. There is no automatic pattern match of expressions to determine if they should be skipped for coverage.
2. A coverage skip hint looks like `/* istanbul ignore <word>[non-word] [optional-docs] */`
3. For `if` conditions you can say `/* istanbul ignore if */` or `/* istanbul ignore else */` and that will end up ignoring whichever path was required to be ignored.
4. For all other cases, the Swiss army knife `/* istanbul ignore next */` may be used which skips the "next thing" in the source code
5. The "next" thing may be, among other things:
  * A JS statement (including assignments, ifs, loops, switches, functions) in which case all of the the statement is ignored for all forms of coverage.
  * A switch case statement, in which case the particular case is ignored for branch coverage and its contents ignored for all forms
  * A conditional inside a ternary expression in which case the branch is ignored
  * A part of a logical expression in which case that part of the expression is ignored for branch coverage
6. It is up to the caller to scope this as narrowly as possible. For example, if you have a source file that is wrapped in a function expression, adding `/* istanbul ignore next */` at the top of the file will ignore the whole file!

When some part of the JS is considered skipped, nothing actually happens in terms of changes to the instrumentation. Everything is calculated as though nothing was skipped - all that changes is that there is a `skip` attribute added to the metadata of the statement, function or branch as applicable.

Coverage reporting however takes the `skip` attribute into account and artificially increments counts, when 0 and skipped to pretend that the thing in question was covered. The HTML report shows the coverage after taking skips into account but at the same time colors the skipped statements with a gray color for easy visual scan.

The HTML and text summary reports shows ignore counts for completeness.
  • Loading branch information
gotwarlost committed Dec 19, 2013
1 parent 3c92b79 commit bc59131
Show file tree
Hide file tree
Showing 13 changed files with 717 additions and 93 deletions.
6 changes: 3 additions & 3 deletions lib/command/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Command.prototype = {
type: function () {
return this.constructor.TYPE;
},
synopsis: function () {
synopsis: /* istanbul ignore next: base method */ function () {
return "the developer has not written a one-line summary of the " + this.type() + " command";
},
usage: function () {
usage: /* istanbul ignore next: base method */ function () {
console.error("the developer has not provided a usage for the " + this.type() + " command");
},
run: function (args, callback) {
run: /* istanbul ignore next: abstract method */ function (args, callback) {
return callback(new Error("run: must be overridden for the " + this.type() + " command"));
}
};
Expand Down
Loading

0 comments on commit bc59131

Please sign in to comment.