Skip to content

feat: exclude lines from processing#212

Open
baram104 wants to merge 1 commit intoistanbuljs:masterfrom
SuitestAutomation:feature/exclude-code-from-coverage
Open

feat: exclude lines from processing#212
baram104 wants to merge 1 commit intoistanbuljs:masterfrom
SuitestAutomation:feature/exclude-code-from-coverage

Conversation

@baram104
Copy link

@baram104 baram104 commented Apr 19, 2023

Sometimes you want to exclude part of the code from the code coverage.
For example, perhaps you have your unit tests inside of a file (because you don't want to export private functions hence,
we test them locally).

Comment on lines +80 to +87
## Excluding Lines

Sometimes you might find yourself wanting to exclude lines
in your application (for example, perhaps you have your unit tests inside of a file
you wish to check coverage of, but
you don't want to include the tests in the report).

To exclude lines, use the special comments `/* c8 exclude start */` and `/* c8 exclude stop */`.
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this different from /* c8 ignore start */ + /* c8 ignore end */? I guess the ignore marks lines as covered, but this exclude would not include them in the report at all - like istanbul instrumented code does?

Copy link
Author

Choose a reason for hiding this comment

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

Exactly. It excludes the lines from the report.

Copy link
Contributor

@AriPerkkio AriPerkkio Apr 25, 2023

Choose a reason for hiding this comment

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

Just my opinion but I think this will be complex for users. This would introduce a second set of ignore hint syntax where:

  • ignore would mark lines as covered even if they are not
  • exclude would remove lines from coverage report - exactly as istanbul instrumented coverage does for /* istanbul ignore ... */ hints

And this new exclude hint does not cover all the same cases as ignore does.

I'm not sure why exactly the ignore syntax has been implemented so that it works differently when compared to istanbul instrumented code. I would rather see it work like your exclude hint here works so that it would completely remove the ignored parts from coverage report.

Copy link
Author

Choose a reason for hiding this comment

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

I agree with you about the fact that ignore should work as exclude does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants