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]: Path coverage thresholds include unexpected files with similar paths #12703

Closed
j3tan opened this issue Apr 20, 2022 · 4 comments · Fixed by #12714
Closed

[Bug]: Path coverage thresholds include unexpected files with similar paths #12703

j3tan opened this issue Apr 20, 2022 · 4 comments · Fixed by #12714

Comments

@j3tan
Copy link

j3tan commented Apr 20, 2022

Version

27.5.1

Steps to reproduce

  1. Clone my repro repo: https://github.com/j3tan/jest-coverage-path-issue
  2. npm install
  3. npm test
  4. Observe failure

Expected behavior

I expect to see src/Foo/ to pass with 100% coverage when using this configuration:

coverageThreshold: {
    'src/Foo/': {
        statements: 100,
        branches: 100,
        functions: 100,
        lines: 100,
    }
}

The ending / in the path group should be respected

Actual behavior

I see src/Foo/ failed with 50% coverage because src/Foobar/ is also aggregated.

--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------|---------|----------|---------|---------|-------------------
All files     |      50 |      100 |      50 |      50 |                   
 Foo          |     100 |      100 |     100 |     100 |                   
  add.js      |     100 |      100 |     100 |     100 |                   
 Foobar       |       0 |      100 |       0 |       0 |                   
  subtract.js |       0 |      100 |       0 |       0 | 2                 
--------------|---------|----------|---------|---------|-------------------
Jest: "src/Foo/" coverage threshold for statements (100%) not met: 50%
Jest: "src/Foo/" coverage threshold for lines (100%) not met: 50%
Jest: "src/Foo/" coverage threshold for functions (100%) not met: 50%

Additional context

The ending / is ignored due to these lines:

https://github.com/facebook/jest/blob/fdc74af37235354e077edeeee8aa2d1a4a863032/packages/jest-reporters/src/CoverageReporter.ts#L281-L289

The path.resolve removes the ending slash.

Using glob matcher is not an option here since that checks per-file coverage thresholds instead of the aggregate path style.

Environment

System:
    OS: macOS 12.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
  npmPackages:
    jest: ^27.5.1 => 27.5.1
@j3tan j3tan changed the title [Bug]: Coverage Thresholds for Path incorrectly include additional paths [Bug]: Coverage Thresholds for paths incorrectly include additional paths Apr 20, 2022
@j3tan j3tan changed the title [Bug]: Coverage Thresholds for paths incorrectly include additional paths [Bug]: Path coverage thresholds include unexpected files with similar paths Apr 20, 2022
@SimenB
Copy link
Member

SimenB commented Apr 21, 2022

Happy to take a PR fixing this 👍

@j3tan
Copy link
Author

j3tan commented Apr 27, 2022

Thanks @wespickett for this fix!

@SimenB
Copy link
Member

SimenB commented Apr 29, 2022

https://github.com/facebook/jest/releases/tag/v28.0.3

@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 May 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants