bun icon indicating copy to clipboard operation
bun copied to clipboard

Implement an `lcov` coverage reporter for `bun test`

Open Jarred-Sumner opened this issue 1 year ago • 7 comments

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

Jarred-Sumner avatar Aug 06 '23 12:08 Jarred-Sumner

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.

hrgdavor avatar Jan 21 '24 11:01 hrgdavor

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.

jbergstroem avatar Feb 01 '24 15:02 jbergstroem

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

Haratsu avatar Feb 24 '24 16:02 Haratsu

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?

nemanjamitric avatar Feb 26 '24 07:02 nemanjamitric

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.

nigelnindodev avatar Mar 22 '24 17:03 nigelnindodev

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

jizusun avatar Apr 23 '24 07:04 jizusun

Any update on this or something we can help with?

jaredwray avatar May 15 '24 19:05 jaredwray

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.

CraigglesO avatar May 25 '24 15:05 CraigglesO

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

qlaffont avatar May 26 '24 07:05 qlaffont

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 avatar May 26 '24 11:05 RobinTail

@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.

CraigglesO avatar May 26 '24 15:05 CraigglesO

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

renzp94 avatar Jun 01 '24 07:06 renzp94

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

Jarred-Sumner avatar Jun 22 '24 09:06 Jarred-Sumner

@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.)

jakeboone02 avatar Jun 22 '24 09:06 jakeboone02

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

leddy231 avatar Jun 22 '24 10:06 leddy231