Jest: Duplicate coverage on Windows

Created on 1 Sep 2016  路  8Comments  路  Source: facebook/jest

Do you want to request a _feature_ or report a _bug_?
_bug_

What is the current behavior?
When running coverage and picking up untested files getting 2 entries for every file that is tested. One with the test results and one that looks like an untested file.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test.
Looks like jest-util is using process.cwd() resulting in c:\ on Windows https://github.com/facebook/jest/blob/master/packages/jest-util/src/index.js#L60
While the existing coverageMap has an entry for the path with C:\ on Windows https://github.com/facebook/jest/blob/master/packages/jest-cli/src/reporters/CoverageReporter.js#L105
The path needs to be normalized to have the same casing in both cases. So when checking for untested files the 2 paths match and we don't create duplicate entries.

What is the expected behavior?
There should only be one entry per file in the coverage report.

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.
node v6.0.0
jest 15.0.2
Windows 10

Most helpful comment

I am seeing the same problem in Jenkins build jobs with Node v8.9.4 and Jest 22. On a local PC it works fine. The problem goes away when I downgrade to Jest 21.3.0-beta.

All 8 comments

Thank you! Do you think you can send a pull request with a fix and a test? :)

I would have but I wasn't really sure how to fix this issue. I found where one of the paths was built in jest-util but wasn't sure where the path for the coverageMaps was built.

Looks like NodeJS 6.4 has resolved the issue with differences in path queries. https://github.com/nodejs/node/issues/6624#issuecomment-243124145 I'm not 100% sure if this will make sure that both getPackageRoot and the Coverage will both work the same way (because I'm not sure how coverage determines path). But at least I think this resolves the issue I was seeing.

Cool, thanks for the update. It seems like Node.js has a lot of edge cases in environments that are case insensitive (Windows, and Mac OS by default)

I am seeing the same problem in Jenkins build jobs with Node v8.9.4 and Jest 22. On a local PC it works fine. The problem goes away when I downgrade to Jest 21.3.0-beta.

this issue always happening on jenkins build job(tested against v6 v8), But woking fine on local pc.

I figured out the Jenkins issue which happens when it is hosted on Windows. The global Workspace Root Directory and Build Record Root Directory in Jenkins should be the same letter case as folder names on the disk. Also, the drive letter in the paths should be capitalized. If you have no access to global settings, the workspace path can be overridden in the job's Advanced/Use Custom Workspace setting.

The issue is the "this._coverageMap.data" hash in the code linked below is case sensitive. Some paths added to the hash are based on paths defined in Jenkins and some are read from the current directory which cause duplicates if the letter case does not match.

https://github.com/facebook/jest/blob/ed95b36bb139aa5d0fea35780ab5043eccf3cdee/packages/jest-cli/src/reporters/coverage_reporter.js#L171

I don't understand, was this issue fixed? If so, what version?

Was this page helpful?
0 / 5 - 0 ratings