Jest coverage shows grey 0% for files exporting plain objects.
See original GitHub issueDo you want to request a feature or report a bug? bug
What is the current behavior? Before running an app, I generate some files that export plain objects (e.g. environment variables).
Here’s one such example.
export default {
someKey: "someValue"
}
These are tested with Jest snapshots to check they haven’t changed against expectations. In the past, such files would be included in tests and reported as green after running a simple snapshot test.
Now, Jest appears to show 0% for all columns in these files, but the row is not red, but rather grey. I wonder if this is a new behaviour? The tests still run and snapshots get generated.
What is the expected behavior? Row should be green with 100% coverage.
Please provide your exact Jest configuration
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
"coveragePathIgnorePatterns": [
"storybook.(js|jsx)"
],
"setupFiles": [
"<rootDir>/config/polyfills.js",
"<rootDir>/config/jest/setup.js"
],
"testMatch": [
"<rootDir>/**/__tests__/**/*.js?(x)",
"<rootDir>/src/**/?(*.)(spec|test).js?(x)"
],
"testEnvironment": "node",
"testURL": "https://localhost",
"transform": {
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web",
"^.+\\.css$": "identity-obj-proxy"
},
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx"
]
},
Run npx envinfo --preset jest
in your project directory and paste the
results here
System:
OS: macOS High Sierra 10.13.4
CPU: x64 Intel(R) Core(TM) i7-2720QM CPU @ 2.20GHz
Binaries:
Node: 9.8.0
Yarn: 1.5.1
npm: 5.6.0
npmPackages:
jest:
wanted: 22.4.3
installed: 22.4.3
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top GitHub Comments
I don’t think this is something Jest has changed, this should be reported to Istanbul.
I think it says
0%
since there is no executable code there.Mind opening up an issue with istanbul and linking back here? Happy to reopen if the issue is in Jest
Hello! I know this issue is kinda old but I had the same issue and fixed it like so: old env.js:
old test:
NEW AND WORKING: env.js:
new test with coverage working:
Tl;dr SimenB was right, its because the code was not executed. Funny enough that lack of coverage started appearing after I updated jest to the latest version. Cheers.