Skip to content

Commit

Permalink
Document the use of /* istanbul ignore file */
Browse files Browse the repository at this point in the history
See gotwarlost#740 for more context.  I had to look explicitly for this functionality before I found it documented in the issue tracker.
  • Loading branch information
jrop authored Jun 13, 2018
1 parent bc84c31 commit be962bc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ignoring-code-for-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ facility by which coverage can be excluded for certain sections of code.
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
3. To skip an entire file, add `/* istanbul ignore file */` at the top of the file
4. 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
5. 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:
6. The "next" thing may be, among other things:
* A JS statement (including assignments, ifs, loops, switches, functions) in which case all of 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
7. 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!

### How it works
Expand Down

3 comments on commit be962bc

@ericsoco
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this hasn't been merged? I had to search open issues, trawl through gotwarlost#740, and click on the link to this PR to get here. This really should be in the docs.

@jrop
Copy link
Owner Author

@jrop jrop commented on be962bc Sep 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, the repo I am PR'ing against is deprecated:

gotwarlost#889 (comment)

@jrop
Copy link
Owner Author

@jrop jrop commented on be962bc Sep 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.