Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage - provide a way to exclude lines or branches from coverage #7662

Open
Tracked by #1 ...
keverw opened this issue Dec 14, 2023 · 11 comments
Open
Tracked by #1 ...

Coverage - provide a way to exclude lines or branches from coverage #7662

keverw opened this issue Dec 14, 2023 · 11 comments
Labels
bun:test Something related to the `bun test` runner enhancement New feature or request

Comments

@keverw
Copy link

keverw commented Dec 14, 2023

What is the problem this feature would solve?

Sometimes might be edge cases or rare that you might want to exclude or delegated to helper functions. For example I'm making a little CLI tool and made a very minimalist logger utility, process.exit I'd never actually call. So in my tests I just overwrote the .exit() method.

Screenshot 2023-12-14 at 1 14 37 PM
bun test v1.0.17 (5e60861c)

logger.test.ts:
✓ Logger should log an error in red [1.36ms]
✓ Logger should log info in white [0.07ms]
✓ Logger should log a warning in yellow [0.05ms]
✓ Logger should log success in green [0.05ms]
✓ Logger should log a note in blue [0.06ms]
✓ Logger should log correctly and handle exit [0.12ms]
-----------|---------|---------|-------------------
File       | % Funcs | % Lines | Uncovered Line #s
-----------|---------|---------|-------------------
All files  |   71.43 |   92.86 |
 index.ts  |   71.43 |   92.86 | 5
-----------|---------|---------|-------------------

What is the feature you are proposing to solve the problem?

A way to add a comment similar to Istanbul.

For example:

/* istanbul ignore if /: ignores the next if statement.
/
istanbul ignore else /: ignores the else portion of an if statement.
/
istanbul ignore next /: ignores the next thing in the source-code ( functions, if statements, classes, you name it). So for example it can ignore the entire tree possibly.
/
istanbul ignore file /: ignores an entire source-file (this should be placed at the top of the file).
/
istanbul ignore else|if */: Ignores a “else if” - but it has to be at the top of the tree:

What alternatives have you considered?

Not really any ideas, my plan is to just keep working on my project and if there's a better way to do this, it'd be great otherwise something I can live with.

@keverw keverw added the enhancement New feature or request label Dec 14, 2023
@elringus
Copy link

This is actually an essential feature for a production-ready test/coverage system, and one of the blockers (others being #4015, #7100) stopping me from switching to bun test.

Other popular test frameworks have this from v1, eg in vitest: https://vitest.dev/guide/coverage.html#ignoring-code (similar works in jest).

Hopefully this could be added to the roadmap. @Electroid

@Electroid Electroid added the bun:test Something related to the `bun test` runner label Dec 19, 2023
@jtenner
Copy link

jtenner commented Apr 21, 2024

I just hit this problem too. For now, I have to reduce test coverage size, because what I'm testing dynamically creates modules using a BunPlugin.

It would be nice to be able to skip an entire module.

@roninjin10
Copy link

I'm migrating https://github.com/evmts/tevm-monorepo to vitest in future because of this issue

@Jarred-Sumner
Copy link
Collaborator

we can add a way to do this, particularly if the first implementation is just the next line

@MKRhere
Copy link

MKRhere commented Jul 28, 2024

@Jarred-Sumner That won't do, I can't do an ignore for each line in a const enum that's bringing down coverage...

I would prefer to have something like /* coverage ignore start */ and /* coverage ignore end */.

image

@seahindeniz
Copy link

This is also a blocker to use coverageThreshold = 1 in bunfig. A specific part of the code must be ignored, not covered and due to that, Bun marks the file in red
Image

@Luks3110
Copy link

Luks3110 commented Nov 19, 2024

It would be nice to be able to ignore certain files via bunfig. For example, I don't want to count repositories in my coverage.

@K-Mistele
Copy link

+1
for example I don't want my logger code that's implemented in winston to have to have unit tests to pass coverage

@abenjaminov
Copy link

Opened a PR to take care of this

#15840

@seahindeniz
Copy link

@abenjaminov the issue related to ignoring specific lines, blocks, etc. What I understand from the PR description, it is related to filtering files

@KAnggara75
Copy link

I just hit this problem too. For now, I have to reduce test coverage size, because what I'm testing dynamically creates modules using a BunPlugin.

It would be nice to be able to skip an entire module.

i also experienced the same thing, finally I was forced to add some configurations to bunfig.toml

[test]

coverage = true
coverageSkipTestFiles = true
coverageThreshold = { lines = 0.6, functions = 0.0 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bun:test Something related to the `bun test` runner enhancement New feature or request
Projects
None yet
Development

No branches or pull requests