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

Coverage report include test files "__test__" and "*.test.js" #6668

Closed
retyui opened this issue Jul 10, 2018 · 11 comments
Closed

Coverage report include test files "__test__" and "*.test.js" #6668

retyui opened this issue Jul 10, 2018 · 11 comments

Comments

@retyui
Copy link

retyui commented Jul 10, 2018

🐛 Bug Report

When I run the tests on the local machine my tests coverage 85%, but when the tests pass to my CI testing coverage there is 83%
And the reason for this difference is that on the local machine in the calculation of coverage tests take part in test (*.test.js, __test__/*) files.

To Reproduce

  1. save your project with jest to hidden folder /home/USER_NAME/.work/project-z
  2. run command in yarn test --coverage
    Result:
 PASS  ./test.js
  ✓ should anything (3ms)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |    81.82 |       50 |    33.33 |    81.82 |                   |
 index.js |    71.43 |       50 |       50 |    71.43 |               3,8 |
 test.js  |      100 |      100 |       25 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.674s, estimated 1s
Ran all test suites.
Done in 1.42s.

Expected behavior

Test coverage should not contain test files

Link to repl or repo (highly encouraged)

https://github.com/retyui/jest-invalid-coverage

npx envinfo --preset jest Results:

  System:
    OS: Linux 4.15 Linux Mint 18.3 (Sylvia)
    CPU: x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  Binaries:
    Node: 8.11.3 - /usr/bin/node
    Yarn: 1.7.0 - /usr/bin/yarn
    npm: 5.6.0 - /usr/bin/npm
  npmPackages:
    jest: ^23.1.0 => 23.1.0 
@SimenB
Copy link
Member

SimenB commented Jul 10, 2018

You can use https://jestjs.io/docs/en/configuration#coveragepathignorepatterns-array-string to remove then.

@rickhanlonii @thymikee what do you think about excluding files that are run as tests from coverage automatically? Seems reasonable to me

@thymikee
Copy link
Collaborator

I'm in 👍

@retyui
Copy link
Author

retyui commented Jul 10, 2018

I created fix:
https://github.com/retyui/jest-invalid-coverage/blob/bb872d7df83ba3d6aab5d3de1d04a9c06c613074/jest.config.js#L30-L33
And tested ,here result:

 PASS  ./index.test.js
  ✓ should anything (4ms)

---------------|----------|----------|----------|----------|-------------------|
File           |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files      |    81.82 |       50 |    33.33 |    81.82 |                   |
 index.js      |    71.43 |       50 |       50 |    71.43 |               3,8 |
 index.test.js |      100 |      100 |       25 |      100 |                   |
---------------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.669s, estimated 1s
Ran all test suites.
Done in 1.41s.

@SimenB
As you can see the problem did not disappear

@SimenB
Copy link
Member

SimenB commented Jul 10, 2018

It works correctly on my machine.

$ y jest --coverage
yarn run v1.7.0
$ /Users/simbekkh/repos/jest-invalid-coverage/node_modules/.bin/jest --coverage
 PASS  ./test.js
  ✓ should anything (4ms)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |    71.43 |       50 |       50 |    71.43 |                   |
 index.js |    71.43 |       50 |       50 |    71.43 |               3,8 |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.938s, estimated 1s
Ran all test suites.
✨  Done in 1.56s.

I'm on a mac, but that shouldn't matter(?)

@retyui
Copy link
Author

retyui commented Jul 10, 2018

@SimenB
I also ran on the macbook, the problem remained
https://gist.github.com/retyui/38014a1e68c09e9ac9f73d6c58b0b935

@SimenB
Copy link
Member

SimenB commented Jul 10, 2018

I'm unable to reproduce, then...

I doubt it matters, but does it still happen if you put your project outside of a dotdir? I noticed this in your config: .all-work/

@retyui
Copy link
Author

retyui commented Jul 10, 2018

@SimenB Yes it helped)
When I moved the folder mv .all-work all-work and then tested again, everything worked as it should

@SimenB
Copy link
Member

SimenB commented Jul 10, 2018

Oh, so not having a . in the path fixed the issue? That's interesting, and feels like a bug...

@thymikee
Copy link
Collaborator

When I was working on one micromatch PR I noticed that not all calls have {dots: true} option set. It's probably this.

@retyui
Copy link
Author

retyui commented Aug 8, 2018

Good work!

@retyui retyui closed this as completed Aug 8, 2018
@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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants