jest: Coverage broken, reports everything undefined
Do you want to request a feature or report a bug? Reporting a Bug
What is the current behavior? After upgrading from Jest 15 to 16 (I also upgraded node from 4 to 6) and getting everything running again (no changes were required to make Jest tests run again) I noticed coverage reports undefined.
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
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
.
What is the expected behavior? Coverage gets reported like normal:
------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
------------|----------|----------|----------|----------|----------------|
All files | 88.37 | 82.26 | 96.3 | 90.98 | |
core | 90.2 | 81.82 | 100 | 97.73 | |
env.js | 90.91 | 78.57 | 100 | 100 | |
logger.js | 88.89 | 87.5 | 100 | 94.12 | 22 |
tv/events | 87.18 | 82.5 | 92.86 | 87.18 | |
events.js | 87.18 | 82.5 | 92.86 | 87.18 |... ,92,103,136 |
------------|----------|----------|----------|----------|----------------|
Run Jest again with --debug
and provide the full configuration it prints. Please mention your node and npm version and operating system.
I did a bunch of debugging since no one else has reported this issue.
(note, this still occurs when using jest installed globally and ran globally)
Here is my command:
npm run test
cd …/node_modules/.bin/ && jest --no-cache --config “…/…/frameworks/jest.json”
I have sub packages inside a parent package, with the parent package having everything installed, hence the directory difference. I did try switching to global jest, updated all my paths, same issue. It seems to be a bug thats exposed with windows and node 6 possibly.
I tracked down the source of the issue to babel-plugin-istanbul but I do not believe the bug is on their side (maybe it is) as it was working previously.
Issue is here:
babel-plugin-istanbul/index.js
exclude = testExclude(Object.keys(opts).length > 0 ? opts : {
cwd: process.env.NYC_CWD || getRealpath(process.cwd()),
configKey: 'nyc',
configPath: (0, _path.dirname)(findUp.sync('package.json'))
});
cwd NEVER aligns with the file path, and ALWAYS reports as node_modules/.bin as the path. Even when ran globally.
Heres some examples outputs of filename compared to cwd:
C:\Users\[NAME]\Documents\nodejs\projects\wichita\frameworks\base\sdk\tv\events\events.js
C:\Users\[NAME]\Documents\nodejs\projects\wichita\node_modules\.bin
C:\Users\[NAME]\Documents\nodejs\projects\wichita\frameworks\base\sdk\core\logger.js
C:\Users\[NAME]\Documents\nodejs\projects\wichita\node_modules\.bin
C:\Users\[NAME]\Documents\nodejs\projects\wichita\frameworks\base\sdk\core\env.js
C:\Users\[NAME]\Documents\nodejs\projects\wichita\node_modules\.bin
Test exclude flags everything as exclude due to this rule:
// Don't instrument files that are outside of the current working directory.
if (/^\.\./.test(path.relative(this.cwd, filename))) return false
I dont see how this could work, or did work before for me honestly.
If its determined not to be Jest, I have no issues reporting this to the proper project.
Edit: It is NOT windows specific, and also occurs on node 5.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 5
- Comments: 15 (10 by maintainers)
I fixed this with the following config: