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

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

Open
TWiStErRob opened this issue Dec 20, 2023 · 37 comments
Open

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

TWiStErRob opened this issue Dec 20, 2023 · 37 comments

Comments

@TWiStErRob
Copy link

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 added a commit to TWiStErRob/repros that referenced this issue Dec 20, 2023
@kwmhp
Copy link

kwmhp commented Dec 21, 2023

Hi
This seems to be the same problem as in my issue #14764
Have you tested this with Node 20.9.0?

@TWiStErRob
Copy link
Author

Yep, confirmed 20.9.0 -> 20.10.0 causes it.

Raised nodejs/node#51251

@ritchieanesco
Copy link

ritchieanesco commented Jan 10, 2024

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

@cenfun
Copy link

cenfun commented Jan 24, 2024

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

@ritchieanesco
Copy link

ritchieanesco commented Jan 29, 2024

Verified that commenting out both lines fixes the issue.

Copy link

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 github-actions bot added the Stale label Feb 28, 2024
@TWiStErRob
Copy link
Author

Still an issue.

@github-actions github-actions bot removed the Stale label Feb 28, 2024
@emiwidknowit
Copy link

still an issue

@jeroenzwart
Copy link

jeroenzwart commented Mar 18, 2024

Yep, confirmed 20.9.0 -> 20.10.0 causes it.

Raised nodejs/node#51251

Still a issue and same problem with the upgrade

@cenfun
Copy link

cenfun commented Mar 19, 2024

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

@TatyanaVl
Copy link

This is still an issue. Is there any progress?

@kmccammon
Copy link

I posted this originally on: nodejs/node#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.

@TatyanaVl
Copy link

@kmccammon - we are facing exactly the same issue.

Copy link

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 github-actions bot added the Stale label May 17, 2024
@TWiStErRob
Copy link
Author

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

@github-actions github-actions bot removed the Stale label May 17, 2024
@kmccammon
Copy link

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.

@TWiStErRob
Copy link
Author

TWiStErRob commented May 19, 2024

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.

Copy link

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 github-actions bot added the Stale label Jul 18, 2024
@Vinnl
Copy link
Contributor

Vinnl commented Jul 18, 2024

.

@github-actions github-actions bot removed the Stale label Jul 18, 2024
@andreclemente
Copy link

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

@aperez-sans
Copy link

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

@andreclemente
Copy link

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

Copy link

github-actions bot commented Sep 7, 2024

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 github-actions bot added the Stale label Sep 7, 2024
@TWiStErRob
Copy link
Author

.

@github-actions github-actions bot removed the Stale label Sep 7, 2024
@jmls
Copy link

jmls commented Sep 30, 2024

also hit this. certainly not stale !

Adding the comments worked for me

@zargham-leanix
Copy link

@SimenB any chance to pick this up?

@Zacaria
Copy link

Zacaria commented Oct 24, 2024

not stale

@raphaelboukara
Copy link

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

Copy link

github-actions bot commented Dec 3, 2024

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 github-actions bot added the Stale label Dec 3, 2024
@Vinnl
Copy link
Contributor

Vinnl commented Dec 3, 2024

.

@github-actions github-actions bot removed the Stale label Dec 3, 2024
@SHANip9
Copy link

SHANip9 commented Dec 3, 2024

I think the render is overlaping
await this.postSession('Profiler.stopPreciseCoverage');
await this.postSession('Profiler.disable');

Copy link

github-actions bot commented Jan 2, 2025

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 github-actions bot added the Stale label Jan 2, 2025
@Vinnl
Copy link
Contributor

Vinnl commented Jan 2, 2025

🤷

@github-actions github-actions bot removed the Stale label Jan 2, 2025
@zargham-leanix
Copy link

do we have any workaround for this? This is blocking us heavily. @SimenB

@dmichon-msft
Copy link

See nodejs/node#51251 (comment) for an explanation of the behavior change in Node. Correct resolution may require work from the Node side, but the workaround is to, after starting a session with Profiler.startPreciseCoverage, intentionally leave it open for the lifetime of the process to prevent v8's optimizing compiler from kicking in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests