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

Implement an lcov coverage reporter for bun test #4015

Closed
Tracked by #1
Jarred-Sumner opened this issue Aug 6, 2023 · 15 comments · Fixed by #11883
Closed
Tracked by #1

Implement an lcov coverage reporter for bun test #4015

Jarred-Sumner opened this issue Aug 6, 2023 · 15 comments · Fixed by #11883
Labels
bun:test Something related to the `bun test` runner enhancement New feature or request

Comments

@Jarred-Sumner
Copy link
Collaborator

Format

The only thing we are missing for lcov to work well is function names. JSC doesn't include them.

Otherwise, I think we can just write the file

@hrgdavor
Copy link

I switched a small project to bun test because jsx just works, and I do not think nodejs will allow that in their native test runner anytime soon (or if added would be slow likely).

current output in console is usable, but lcov will be great, for integrating and generating pretty html reports.

@jbergstroem
Copy link
Contributor

current output in console is usable, but lcov will be great, for integrating and generating pretty html reports.

..and uploading reports to tools such as codecov and coveralls.

@Haratsu
Copy link

Haratsu commented Feb 24, 2024

Any progress on uploadable coverage reports?
Alternatively has anyone successfully integrated jest cli commands into bun as a work around already? So that we could call bun jest ... my inital attempt doing so failed complaining:

Test suite failed to run

    TypeError: undefined is not an object (evaluating '_global.hasOwnProperty("queueMicrotask")')
        at hasOwnProperty (native)

      at withGlobal (node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:183:23)
      at new FakeTimers (node_modules/@jest/fake-timers/build/modernFakeTimers.js:27:50)
      at processTicksAndRejections (:12:39)
      at processTicksAndRejections (:12:39)

Before digging into deep analysis I wanted to recheck

@nemanjamitric
Copy link

Any progress on uploadable coverage reports? Alternatively has anyone successfully integrated jest cli commands into bun as a work around already? So that we could call bun jest ... my inital attempt doing so failed complaining:

Test suite failed to run

    TypeError: undefined is not an object (evaluating '_global.hasOwnProperty("queueMicrotask")')
        at hasOwnProperty (native)

      at withGlobal (node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:183:23)
      at new FakeTimers (node_modules/@jest/fake-timers/build/modernFakeTimers.js:27:50)
      at processTicksAndRejections (:12:39)
      at processTicksAndRejections (:12:39)

Before digging into deep analysis I wanted to recheck

I'm having this same issue when using the gitlab pipeline to run tests. Any luck finding a fix?

@nigelnindodev
Copy link

Is anyone actively looking into this here? Interested in resolving this for some use cases, and might have some bandwidth in the next few days to look into it.

@jizusun
Copy link

jizusun commented Apr 23, 2024

Using bun run -b test can reproduce the issue on my local machine, and jest fail but exits with 0

(devbox) ➜  tdd-demo-for-dajia-talk git:(devbox) ✗ bun run -b  --filter="*" test
stack-with-jest test $ jest
│ [5 lines elided]
│
│       at withGlobal (../../node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:183:23)
│       at new FakeTimers (../../node_modules/@jest/fake-timers/build/modernFakeTimers.js:27:50)
│       at processTicksAndRejections (:12:39)
│
│ Test Suites: 1 failed, 1 total
│ Tests:       0 total
│ Snapshots:   0 total
│ Time:        0.043 s
│ Ran all test suites.
└─ Done in 576 ms
(devbox) ➜  tdd-demo-for-dajia-talk git:(devbox) ✗ echo $?
0

@jaredwray
Copy link

Any update on this or something we can help with?

@CraigglesO
Copy link

CraigglesO commented May 25, 2024

If you want a badge here is a basic gist I made to do that for you quickly. I have a bunfig.toml with coverage set to true. Save some of you the trouble. The svg code could be better though... I just run the script on prepublishOnly.

@qlaffont
Copy link

To be honest, the need is to integrate with other tools like CodeClimate (with lcov report) than display a badge in your repo.

@RobinTail
Copy link

I need lcov for coverage tracking tools (https://coveralls.io/ and similar), @CraigglesO

If bun could also make json report on coverage, the following tool could be used for making badges:
https://www.npmjs.com/package/make-coverage-badge

@CraigglesO
Copy link

@RobinTail

I need it really bad too! I just wanted some visual indicator for now of how far my testing was getting while I wait for lcov.

I recommend using shieldsIO for all the badges. the link here is for coveralls but the website does it all. Saves me a lot of pain to get working badges including github actions.

@renzp94
Copy link

renzp94 commented Jun 1, 2024

If you want a badge here is a basic gist I made to do that for you quickly. I have a bunfig.toml with coverage set to true. Save some of you the trouble. The svg code could be better though... I just run the script on prepublishOnly.

I solved the badge issue based on @CraigglesO's code. If you need to display the badge, perhaps this is a display solution. If you also want to solve it in this way, you can refer to: https://github.com/renzp94/utils/blob/main/scripts/common.ts#L86

@Jarred-Sumner
Copy link
Collaborator Author

This will ship as part of Bun v1.1.16, thanks to @exoego

@jakeboone02
Copy link
Contributor

@exoego This is awesome and a huge step towards being able to fully migrate from Jest to bun test for a lot of people.

@Jarred-Sumner There are only 22 open issues with the "jest" label that mention "coverage". Could that be a focus of an upcoming release? (Big ones for me are #7100, #4021, and #7662.)

@leddy231
Copy link

Amazing news!
Apart from the issues above the bug about missing coverage on implicit constructors would be nice to solve to get coverage reporting to be more accurate. #7025

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

Successfully merging a pull request may close this issue.