jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: v8 coverage lowers when more tests are executed

Open TWiStErRob opened this issue 1 year ago • 45 comments
trafficstars

Version

29.7.0

Steps to reproduce

  1. Clone https://github.com/TWiStErRob/repros/tree/main/jest/v8-flaky-coverage
  2. npm install
  3. npm test -- --runInBand wrapped.test.js -> tests pass, coverage 100%
  4. npm test -- --runInBand -> tests pass, coverage missing lines

Expected behavior

Everything passes and coverage is better or equivalent to when only a single test is executed.

image

Actual behavior

File that is covered by a single test file to 100% loses coverage when an additional test is executed. The additional test calls the original function.

image

Additional context

Anything relevant changed in the repro will make it work correctly. So:

  • v8 -> babel
  • changing the order of execution of tests (sorted.js < -> >) ✅ We used a testSequencer to consistently reproduce the issue, otherwise it was flaky!
  • changing the order via removing --runInBand ✅ We also used this to consistently reproduce the issue, otherwise it was flaky!

Environment

System:
    OS: macOS 14.1.2
    CPU: (12) arm64 Apple M2 Pro or (10) arm64 Apple M1 Pro
  Binaries:
    Node: 20.10.0 - /opt/homebrew/opt/node@20/bin/node
    npm: 10.2.3 - /opt/homebrew/opt/node@20/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0 

Also on github actions ubuntu-latest (so Ubuntu 22.04 and x64).

TWiStErRob avatar Dec 20 '23 17:12 TWiStErRob

Hi This seems to be the same problem as in my issue https://github.com/jestjs/jest/issues/14764 Have you tested this with Node 20.9.0?

kwmhp avatar Dec 21 '23 12:12 kwmhp

Yep, confirmed 20.9.0 -> 20.10.0 causes it.

Raised https://github.com/nodejs/node/issues/51251

TWiStErRob avatar Dec 21 '23 16:12 TWiStErRob

+1 also getting code coverage failure after updating to 20.10.0.

ritchieanesco avatar Jan 10 '24 00:01 ritchieanesco

I found that comment following two lines in node_modules/collect-v8-coverage/index.js will fix it.

    //await this.postSession('Profiler.stopPreciseCoverage');

    //await this.postSession('Profiler.disable');

image

cenfun avatar Jan 24 '24 14:01 cenfun

Verified that commenting out both lines fixes the issue.

ritchieanesco avatar Jan 29 '24 03:01 ritchieanesco

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Feb 28 '24 21:02 github-actions[bot]

Still an issue.

TWiStErRob avatar Feb 28 '24 21:02 TWiStErRob

still an issue

emiwidknowit avatar Mar 11 '24 10:03 emiwidknowit

Yep, confirmed 20.9.0 -> 20.10.0 causes it.

Raised nodejs/node#51251

Still a issue and same problem with the upgrade

jeroenzwart avatar Mar 18 '24 11:03 jeroenzwart

Seems it can be fixed with await this.postSession('Debugger.enable'); see https://github.com/SimenB/collect-v8-coverage/pull/235/files

cenfun avatar Mar 19 '24 15:03 cenfun

This is still an issue. Is there any progress?

TatyanaVl avatar Apr 12 '24 19:04 TatyanaVl

I posted this originally on: https://github.com/nodejs/node/issues/51251

Reposting here in case it's helpful...

I have been facing the same issue: my coverage report was 100% with 20.9.0, but as of 20.10.0, it now reports less than 100% coverage and somewhat randomly flags lines not covered.

I noticed that I get the same coverage reporting flakiness with 18.20.2 (I initially saw this issue when my GitHub actions started to fail). Coverage works fine with 18.19.1.

So there seems to be a change between 18.19.1 and 18.20.0 that causes the issue as well as between 20.9.0 to 20.10.0.

This is now causing my GitHub CI/CD actions to fail since GitHub is using 18.20.2.

kmccammon avatar Apr 17 '24 13:04 kmccammon

@kmccammon - we are facing exactly the same issue.

TatyanaVl avatar Apr 17 '24 20:04 TatyanaVl

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar May 17 '24 21:05 github-actions[bot]

Can't call it closed stale without a triage...

TWiStErRob avatar May 17 '24 21:05 TWiStErRob

Can't call it closed stale without a triage...

Agreed, I'm stuck on node version 18.19.1 until this coverage issue is resolved.

kmccammon avatar May 18 '24 19:05 kmccammon

I think we can safely say this project is abandoned: https://github.com/jestjs/jest/issues?q=is%3Aclosed+label%3A%22Needs+Triage%22+label%3AStale

A ton of them are auto-closed without a single comment.

TWiStErRob avatar May 19 '24 07:05 TWiStErRob

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jun 18 '24 08:06 github-actions[bot]

not stale

Vinnl avatar Jun 18 '24 08:06 Vinnl

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 18 '24 09:07 github-actions[bot]

.

Vinnl avatar Jul 18 '24 09:07 Vinnl

Also stuck on node version 18.19 or 20.9 until this coverage issue is resolved.

andreclemente avatar Aug 07 '24 10:08 andreclemente

Can confirm still happening; For those of you whom don't need to --runInBand, running with more than one worker thread fixed the particular problem for me.

npx jest -w 2 ...

aperez-sans avatar Aug 08 '24 00:08 aperez-sans

Running with more than one worker did not fix the problem for me.

andreclemente avatar Aug 08 '24 09:08 andreclemente

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Sep 07 '24 10:09 github-actions[bot]

.

TWiStErRob avatar Sep 07 '24 10:09 TWiStErRob

also hit this. certainly not stale !

Adding the comments worked for me

jmls avatar Sep 30 '24 19:09 jmls

@SimenB any chance to pick this up?

zargham-leanix avatar Oct 01 '24 11:10 zargham-leanix

not stale

Zacaria avatar Oct 24 '24 08:10 Zacaria

Hi, We have actually ~50 nodeJS services stuck on node 20.9.0 because of this issue. Is there any known workaround?

raphaelboukara avatar Nov 03 '24 12:11 raphaelboukara