jest: Jest 20 has problems reading config through --config CLI option
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Since switching to jest 20, it doesn’t apply my exclusion patterns from the collectCoverageFrom
setting, whereas jest 29 used to do this correctly.
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
I’m using this config:
{
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!src/{client,server,shared}/*.{js,jsx}",
"!src/{client,server,shared}/{components,data,services}/*/index.js",
"!src/client/services/analytics/**",
"!src/shared/services/raven/**"
]
}
For jest 19, this config would correctly exclude the ignored files from the coverage report, whereas jest 20 still includes them in the coverage report.
jest 19: https://coveralls.io/builds/11407983 jest 20: https://coveralls.io/builds/11453060
What is the expected behavior?
For jest to apply the exclusion patterns and ignore the matching files when reporting coverage.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest 20 yarn 0.24.4 node 7.10.0 macos sierra
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 33 (2 by maintainers)
I also ran into issues with the
--config
option after upgrading, and this is what I have found:rootDir
is no longer relative to the current working directory (in whichjest
is called), but instead relative to the config file location. This is a good change, but I haven’t seen it documented anywhere.tl;dr: I had a
jest.config.json
file withrootDir: ''
in a subdirectory. Changing it torootDir: '..'
makes the tests run again.Ok i’ve tested it and the problem looks like if the file doesn’t have
.json
extension, it doesn’t read it. I’ve renamed my config files tojest.config.json
andjest-ci.config.json
and they both work as expected. Thanks @pjnovas!After testing some more, it seems that jest 20 does not load my .jestrc config (used in combination with
jest --config .jestrc --coverage
. Which did work with jest 19.After including the config in package.json instead of separately, excluding files from coverage works again. Weird that this broke though.
I’m having trouble too.
jest.config.js
and hasmodule.exports
, it works.jest.config.json
with plain JSON content, it does not work..jestrc
with JSON content ormodule.exports
does not work.jest
key inpackage.json
works.Running
jest --showConfig
correctly shows my root directory, but it just doesn’t seem to want to use the.jestrc
file. It’s strange, but I’ve simply added the config to thepackage.json
and it’s no big deal. But it’s a little confusing because I believe the two failing options I mentioned are supposed to work, right? (I’m new to Jest, so I’m not sure what the Jest 19 behavior was.)We’re experiencing a very terse error in the
lerna
project when attempting to run jest 20.0.3 with a--config
option (that previously worked in jest 19): https://github.com/evocateur/lerna/tree/upgrade-jestAfter cloning and checking out the branch:
What it yields (after the preintegration lifecycle script runs):
test/config/integration.json
yarn jest -- --showConfig --config=test/config/integration.json
doesn’t even output the config, as the default without--config
does successfully.hate this bug to ☑️
As a workaround for now you may want to set
"rootDir": "../../"
or so.For those having silent failures, check that you’re node version is > 6.
Only
jest.config.js
andjest
key in package.json are automatically taken as your config. for.jestrc
you need to specify--config
flag. E.g.jest --config=.jestrc
I was having a similar issue to where jest 20.0.4 would just quit with no feedback and no tests run when I used the --config option. Running the same command through npm at least gave me Exit status 1, but that really didn’t clear up what the problem was.
My jest.config.json isn’t in my project root, but I use <rootDir> within it. I didn’t have a rootDir option, though. As soon as I added a rootDir entry with a path back to where jest is run from, it started working. This wasn’t needed in jest 19, and the lack of feedback turned it into a guessing game for me to try to figure out what the problem was.