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]: Strange uncovered branches after upgrade jest #14066

Closed
xpol opened this issue Apr 13, 2023 · 5 comments
Closed

[Bug]: Strange uncovered branches after upgrade jest #14066

xpol opened this issue Apr 13, 2023 · 5 comments

Comments

@xpol
Copy link

xpol commented Apr 13, 2023

Version

29.5.0

Steps to reproduce

I have tests with all statements branches function and line covered with jest 29.3.1.

❯ npm outdated
Package     Current  Wanted  Latest  Location                 Depended by
jest         29.3.1  29.5.0  29.5.0  node_modules/jest        hilton-dk-edge
ts-jest      29.0.3  29.1.0  29.1.0  node_modules/ts-jest     hilton-dk-edge
ts-morph     17.0.1  17.0.1  18.0.0  node_modules/ts-morph    hilton-dk-edge
typescript    4.9.5   4.9.5   5.0.4  node_modules/typescript  hilton-dk-edge

Result of the coverage:

--------------------------------------------|---------|----------|---------|---------|-------------------
File                                        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------------------------------|---------|----------|---------|---------|-------------------
All files                                   |     100 |      100 |     100 |     100 |                   

Then npm i -D jest to install the 29.5.0 version of jest, the the branches coverage dropped:

--------------------------------------------|---------|----------|---------|---------|-------------------
File                                        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------------------------------|---------|----------|---------|---------|-------------------
All files                                   |     100 |    78.12 |     100 |     100 |                   

And got strange uncovered branches:

Screenshot 2023-04-13 at 12 49 26

Screenshot 2023-04-13 at 12 50 07

Screenshot 2023-04-13 at 13 02 26

Screenshot 2023-04-13 at 13 06 06

The funny thing is that When I downgrade to jest 29.3.1, the branches coverage did not recovered to 100%, still 78.12.

Expected behavior

The branches coverage should be still 100% after upgrade jest library from 29.3.1 to 29.5.0.

It should not report the strange uncovered branches as attached above.

Even there is a bug in 29.5.0, while I downgrade it to 29.3.1 as before, the branches coverage should back to 100%.

Actual behavior

After upgrade from 29.3.1 to 29.5.0, the branches coverage drops and reports strange uncovered branches in the HTML report as attached in the steps.

And it does not help fix the issue when I downgrade to 29.3.1.

Additional context

coverageProvider: 'babel',

Changes made to package-lock.json after upgrade and downgrade:

diff.patch

My guess:
As it does not help when downgrade back to 29.3.1, so I think the bug is introduced by one of the jest dependencies.
And the downgrade of dependencies does not downgrade the dependencies.

Environment

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
  npmPackages:
    jest: ^29.3.1 => 29.3.1
@fredrivett
Copy link

fredrivett commented May 11, 2023

I'm also seeing a similar issue since updating from 29.3.1 to 29.5.0. I'm also seeing sporadic uncovered lines through files, and when I check the line mentioned it's just a line from a top-level comment. For example:

29.3.1:

File                                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------------------------|---------|----------|---------|---------|-------------------
  test-utils.tsx                       |     100 |      100 |     100 |     100 |

29.5.0:

File                                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------------------------|---------|----------|---------|---------|-------------------
  test-utils.tsx                       |   99.25 |    81.81 |     100 |   99.25 | 16

test-utils.tsx:

15 | // This type interface extends the default options for render from RTL, as well
16 | // as allows the user to specify other things such as initialState, store.
17 | interface ExtendedRenderOptions extends Omit<RenderOptions, "queries"> {
18 |  preloadedState?: PreloadedState<RootState>;
19 |  store?: AppStore;
20 | }

If I revert to the old version (29.3.1) by checking out the previous package-lock.json and running npm install again, the issue disappears.

I'd offer up a reproducible repo but I'm not sure how easy this will be to reproduce as it's quite odd behaviour.

My assumption is that this commit is behind the issue, as it seems the most fitting from the release notes, but I might be wrong.

My jest.config.js for reference:

const { defaults } = require("jest-config");

module.exports = {
  testEnvironment: "jsdom",
  setupFilesAfterEnv: ["./tests/jest.setupAfterEnv.ts"],
  setupFiles: ["./tests/jest.setup.ts"],
  clearMocks: true,
  collectCoverageFrom: [
    "**/*.{js,jsx,ts,tsx}",
    "!**/constants/**",
    "!**/jest-report/**",
    "!**/node_modules/**",
    "!**/pages/_*.tsx",
    "!**/tests/**",
    "!**/types/**",
    "!**/.next/**",
    "!.*",
    "!**.d.ts",
    "!*.config.js",
    "!eslint-local-rules.js",
  ],
  coverageDirectory: "jest-report/coverage_html_report",
  coverageProvider: "v8",
  coverageReporters: [...defaults.coverageReporters, "html", "cobertura"],
  coverageThreshold: {
    global: {
      branches: 97,
      functions: 97,
      lines: 97,
      statements: 97,
    },
  },
  reporters: [
    "default",
    [
      "jest-junit",
      {
        suiteName: "jest tests",
        outputDirectory: "jest-report",
        outputName: "jest-tests.xml",
        uniqueOutputName: "false",
        classNameTemplate: "{classname}-{title}",
        titleTemplate: "{classname}-{title}",
        ancestorSeparator: " › ",
        usePathForSuiteName: "true",
      },
    ],
  ],
  rootDir: "./",
  moduleNameMapper: {
    // enable absolute links to root files (e.g. `~/rootfile.ext`)
    "~/(.*)": "<rootDir>/$1",
  },
  modulePaths: ["<rootDir>"],
};

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

@github-actions github-actions bot added the Stale label Jun 10, 2023
@github-actions
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 Jul 10, 2023
@github-actions
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
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 Aug 10, 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