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

Jest 22 Coverage Fail on TS files #5428

Closed
WhiteTurbine opened this issue Jan 31, 2018 · 9 comments
Closed

Jest 22 Coverage Fail on TS files #5428

WhiteTurbine opened this issue Jan 31, 2018 · 9 comments

Comments

@WhiteTurbine
Copy link

Please re-open - bug still exists:

#5109

Issue remains in the newest version of Jest at a time (22.1.4). Last working version I found was 21.2.1. This issue can be reproduced only on Windows.

Jest is registering same file to Istanbul-lib-coverage twice with path that only differs in case (“c:/” vs “C:/”). This makes Istambul add file twice using “addFileCoverage” method. As a result coverage report shows 2 files instead of 1. In addition to showing 2 files, it is not able to find one of the paths in its internal array of coverage information (this.data) using “fileCoverageFor” method because file addresses there are case sensitive.

I have worked-around the issue by overriding “istanbul-lib-coverage” slightly using “override-require” node module. However, proper fix should probably be in Jest and this requires further investigation.

@SimenB
Copy link
Member

SimenB commented Feb 1, 2018

Would a realpath fix this, I wonder?

@WhiteTurbine
Copy link
Author

Don't think it would solve whole problem. If you are talking about npm realpath - if I pass c:/abc it spits out c:/abc. If I pass C:/abc, I get C:/abc. It does not seem to normalize drive letter case. Realpath is cool but need to match drive letter as well. I would maybe even do it manually since it looks like corner case for given Jest/Istanbul scenario.

@SimenB
Copy link
Member

SimenB commented Feb 1, 2018

Not the native realpath either? On node 9, do fs.realpathSync.native(filepath) (or process.binding('fs').realpath(filepath, 'utf8'); on older nodes)

@WhiteTurbine
Copy link
Author

WhiteTurbine commented Feb 1, 2018

`fs.realpathSync( 'C:\' )
'C:\'

fs.realpathSync( 'c:\' )
'c:\'`

Many default normalization functions ignore case letter because normally it should not matter whether drive letter is upper or lower case. Therefor maybe Jest could have custom normalization function which would combine something like realpath with something like this:

let normalized = path.replace( /^[a-zA-Z]:/, function( match, offset, input ) {
return match.toLowerCase()
} );

Basically goal is to make sure that all paths arriving from Jest to "Istanbul-lib-coverage" module would be standardized. Same path = same string.

One note though - I would only mess around with drive letter using above custom code - not the whole path. This is because on Linux paths are case-sensitive and I would not want someone to start using random-case paths on Windows and find them working only to fail when trying to launch on Linux.

PS.: maybe it is time for Istambul to update as well :/ Although I still believe Jest should normalize paths regardless.

@jamesrusso
Copy link

jamesrusso commented Feb 9, 2018

I ran into the same issue, but it was caused by doing an import using two different cases. Notice the t vs T

import { ESPayType } from './BasicTypes';

vs

import { ESPayType } from './Basictypes';

This caused tsc to generate both files in the output.

@SimenB
Copy link
Member

SimenB commented Feb 10, 2018

@WhiteTurbine see using native realpath:

image

@WhiteTurbine
Copy link
Author

Turns out process.binding('fs').realpath works differently from require( 'fs' ).realpath. Did not know that. This should help if added to Jest.

I regards to import paths - good point and might help others. However, in my case drive letter differs. I do not have drive letter in my imports - must be something else.

However, even in import situation desvribed by @jamesrusso - shouldn't Jest work well even if cases are mixed? Thing is - in Windows paths are not case sensitive.

@github-actions
Copy link

This issue was closed because it has been stalled for 7 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 Apr 27, 2022
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

3 participants