bun
bun copied to clipboard
Implement an `lcov` coverage reporter for `bun test`
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
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.
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.
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
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?
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.
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
Any update on this or something we can help with?
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
.
To be honest, the need is to integrate with other tools like CodeClimate (with lcov report) than display a badge in your repo.
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
@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.
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 onprepublishOnly
.
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
This will ship as part of Bun v1.1.16, thanks to @exoego
@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 "bun:test" label that mention "coverage". Could that be a focus of an upcoming release? (Big ones for me are #7100, #4021, and #7662.)
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. https://github.com/oven-sh/bun/issues/7025