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]: Coverage calculation is off when a React.lazy line spans multiple lines #14561

Closed
chulinguy opened this issue Sep 22, 2023 · 6 comments
Closed

Comments

@chulinguy
Copy link

Version

27.4.3

Steps to reproduce

I have an SPA written in React v17.2.
Formatting of code in this codebase is done by Prettier v3.
Bundling of the app is done by Create-React-App v5

Throughout the app, there are various instances of lazy import:

const PageA = React.lazy(() => import('./PATH_TO_FOLDER/PageA'))
const ComponentB = React.lazy(() => import('./PATH_TO_FOLDER/ComponentB'))

Most of these lazy importing lines get ignored by Jest in the coverage report.
However, Jest will mark a line as "uncovered" in the Jest coverage report if that line is formatted to be multiple lines by Prettier:

// Shows up as uncoverage in Jest coverage report !!!
const ComponentWithLongNameOrPath = React.lazy(() =>
  import('./PATH_TO_FOLDER/ComponentWithLongNameOrPath')
) 

Expected behavior

Multi-line lazy import should be ignored in the same way single-line lazy import is.

Actual behavior

Multi-line lazy import get marked as "uncovered"

Additional context

No response

Environment

System:
    OS: macOS 13.5
    CPU: (12) x64 Apple M2 Pro
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.17.1/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.17.1/bin/npm
@SimenB
Copy link
Member

SimenB commented Sep 23, 2023

Does this happen with the latest version of Jest?

@chulinguy
Copy link
Author

chulinguy commented Sep 25, 2023

@SimenB I am not able to quickly update my codebase to Jest v29 (since Create-React-App is not longer maintained)

My understanding is that coverage information actually come from packages outside of Jest.
Therefore, I would guess this issue is still present in Jest v29, since the relevant dependencies have not changed that much

jest-reporters v29.7 dependencies:

  • collect-v8-coverage: "^1.0.0"
  • istanbul-lib-coverage: "^3.0.0"
  • istanbul-lib-instrument: "^6.0.0"
  • istanbul-lib-report: "^3.0.0"
  • istanbul-lib-source-maps: "^4.0.0"
  • istanbul-reports: "^3.1.3"

jest-reporters v27.5 has the same dependencies except for istanbul-lib-instrument, which was at v5.1. I tried to update just istanbul-lib-instrument to v6, but the coverage report still has the same bug

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

Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

1 similar comment
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2023
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants