jest: Inconsistent output with --coverage

๐Ÿ› Bug Report

When code-covered files exist in the root directory, the --coverage output will include the name of the directory. This is not desirable in CI scenarios where the working directory will vary.

Actual

https://github.com/azz/jest-istanbul-issue/tree/master

When a file exists at root (above), the output is:

$ jest --coverage
 PASS  ./index.test.js
 PASS  src/file.test.js
-------------------------|----------|----------|----------|----------|-------------------|
File                     |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-------------------------|----------|----------|----------|----------|-------------------|
All files                |      100 |      100 |      100 |      100 |                   |
 jest-istanbul-issue     |      100 |      100 |      100 |      100 |                   |
  index.js               |      100 |      100 |      100 |      100 |                   |
 jest-istanbul-issue/src |      100 |      100 |      100 |      100 |                   |
  file.js                |      100 |      100 |      100 |      100 |                   |
-------------------------|----------|----------|----------|----------|-------------------|

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        1.983s
Ran all test suites.
Done in 2.98s.

Note the jest-istanbul-issue above.

Expected

https://github.com/azz/jest-istanbul-issue/tree/good-case

When it doesnโ€™t:

$ jest --coverage
 PASS  src/file.test.js
  โˆš it works (1ms)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |      100 |      100 |      100 |                   |
 file.js  |      100 |      100 |      100 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.708s
Ran all test suites.
Done in 2.76s.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 16 (15 by maintainers)

Most upvoted comments

IMO the second case should include /src as well. So everything is always relative to the root of the project rootDir.

Awesome! Yeah, or at least if passed some sort of root option. Would you mind filing an issue in the istanbul repo? Then whenever thatโ€™s fixed, we can use that option (or update the version if itโ€™s made the default) and close this issue here ๐Ÿ™‚

probably not, not exactly minimal. Just updating the one in the OP to latest Jest should be enough tho (unless @bcoe wants a version without Jest at all)

I agree itโ€™s not a bug in that it behaves as intended - I do think the behavior is not ideal, though.

I think we should be able to set a root, and that all paths should be relative to that regardless of what istanbul considers โ€œtop of the treeโ€. If I do jest some-deep-test --coverage that only covers a subtree of files, check html coverage, run some other test that makes the tree different, a refresh of the html report should not show me the old file just because istanbul found a file higher up in the FS (or 404 if we had a cleanup between runs).

I can open up an issue tomorrow ๐Ÿ‘