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
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.
Would you mind providing a repo with this failing case of reading Jest config this way?
Hey,
Using --config .jestrc didn't work like it used to in v19.x. However it worked with a js config file even without the --config flag
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-jest
After cloning and checking out the branch:
yarn integration
What it yields (after the preintegration lifecycle script runs):
$ jest --config test/config/integration.json
error Command failed with exit code 1.
test/config/integration.json
{
"bail": true,
"roots": [
"<rootDir>/test/integration"
],
"testEnvironment": "node",
"setupTestFrameworkScriptFile": "<rootDir>/test/integration/_setupTestFramework.js",
"snapshotSerializers": [
"<rootDir>/test/helpers/serializePlaceholders.js"
],
"verbose": true
}
yarn jest -- --showConfig --config=test/config/integration.json doesn't even output the config, as the default without --config does successfully.
As a workaround for now you may want to set "rootDir": "../../" or so.
@thymikee Well, it started running, but now I have a ton of _really_ scary Maximum call stack size exceeded and UnhandledPromiseRejectionWarning spamming my console (which notably still hasn't exited since I began running the tests with the updated rootDir two minutes ago...)
$ jest --config test/config/integration.json
FAIL test/integration/lerna-init.test.js
โ lerna init โบ initializes empty directory
RangeError: Maximum call stack size exceeded
at _callee$ (test/integration/lerna-init.test.js:31:33)
at tryCatch (node_modules/regenerator-runtime/runtime.js:64:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:355:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:116:21)
at step (test/integration/lerna-init.test.js:8:388)
at test/integration/lerna-init.test.js:8:548
โ lerna init โบ updates existing metadata
RangeError: Maximum call stack size exceeded
at _callee2$ (test/integration/lerna-init.test.js:42:33)
at tryCatch (node_modules/regenerator-runtime/runtime.js:64:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:355:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:116:21)
at step (test/integration/lerna-init.test.js:8:388)
at test/integration/lerna-init.test.js:8:548
lerna init
โ initializes empty directory (2344ms)
โ updates existing metadata (476ms)
โ removes VERSION file (2ms)
Snapshot Summary
โบ 2 obsolete snapshots found, run with `yarn run integration -- -u` to remove them.
Test Suites: 1 failed, 1 of 7 total
Tests: 2 failed, 1 passed, 3 total
Snapshots: 3 passed, 3 total
Time: 4.812s
Ran all test suites.
error Command failed with exit code 1.
[~/github/lerna] (bump-jest)$ (node:54328) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RangeError: Maximum call stack size exceeded
(node:54328) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): RangeError: Maximum call stack size exceeded
(node:54328) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)
(node:54328) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
(node:54330) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RangeError: Maximum call stack size exceeded
(node:54330) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
(node:54327) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RangeError: Maximum call stack size exceeded
(node:54327) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
Err, it did exit, the UnhandledPromiseRejectionWarning stuff just emitted after the terminal reappeared.
And it works when config is set from package.json?
I can run my unit tests with only the jest stanza in package.json, no --config passed.
"jest": {
"collectCoverageFrom": [
"src/**/*.js"
],
"modulePathIgnorePatterns": [
"<rootDir>/test/fixtures"
],
"roots": [
"<rootDir>/src",
"<rootDir>/test"
],
"setupFiles": [
"<rootDir>/test/helpers/env.js"
],
"testEnvironment": "node",
"testMatch": [
"**/test/*.js"
]
},
Notably, the package.json config does _not_ run the same tests.
Hm, maybe one of your libs are conflicting with regenerator-runtime?
The version of regenerator-runtime didn't change, though, nor did any of my babelrc config etc. The only variant in this equation is jest.
@ismay it's happening the same to me, if I run yarn test -- --showConfig (where test is jest --config .jestrc) it doesn't read .jestrc file at all...
@ismay @serginator exactly same here, I have renamed my .jestrc into jest.config.js and all working back again. I have just trying to move from 19.0.1 into 20.0.3
Mmm so you can load the default config file, but what if you need another
config file for CI purposes for example? That's why I'm using --config,
because I need to have two config files, .jestrc for development and
.jestrc-ci for Jenkins :(
@serginator oh but it is working with a custom config, it's just not picking up the .jestrc (IDK why)
My change is jest --config jest.config.json and it works (doing it from an npm test)
Then I guess I have to test it tomorrow, maybe if you name the file .jestrc
it doesn't read it, but if it is a .js it works
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
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 to jest.config.json and jest-ci.config.json and they both work as expected. Thanks @pjnovas!
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 which jest 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 with rootDir: '' in a subdirectory. Changing it to rootDir: '..' makes the tests run again.
I'm having trouble too.
jest.config.js and has module.exports, it works.jest.config.json with plain JSON content, it does not work..jestrc with JSON content or module.exports does not work.jest key in package.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 the package.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.)
Can you try with jest@test.
After installing jest@test, my npm list looks like this:
โโโฌ [email protected]
โ โโโฌ [email protected]
โ โโโ [email protected]
โโโฌ [email protected] invalid
โ โโโ [email protected] extraneous
npm ERR! invalid: [email protected] /Users/msikma/Projects/reisan/reisan-application/packages/reisan-backend-api/node_modules/jest
npm ERR! extraneous: [email protected] /Users/msikma/Projects/reisan/reisan-application/packages/reisan-backend-api/node_modules/jest-cli
npm ERR! extraneous: [email protected] /Users/msikma/Projects/reisan/reisan-application/packages/reisan-backend-api/node_modules/node-pre-gyp
npm ERR! extraneous: [email protected] /Users/msikma/Projects/reisan/reisan-application/packages/reisan-backend-api/node_modules/ajv-keywords/node_modules/ajv
Test results are identical to my previous comment.
I think it's fair if I give more information about my setup, just for completeness:
.jestrc etc. were done with the jest section removed)I'm running a Lerna multi-package project, which has its own package.json (with nothing in it except Lerna itself), but I ran the same tests with the package outside of the multi-package setup and the results were the same.
edit: link removed, guess it's no longer necessary.
Only jest.config.js and jest key in package.json are automatically taken as your config. for .jestrc you need to specify --config flag. E.g. jest --config=.jestrc
My bad, as I mentioned before I was under the mistaken impression that this would work out of the box. Not from the docs, but from reading issues. I probably just misread someone's comment. No problem, sticking with the regular methods is fine.
More to the point, I'm not getting the same error when using --config as other people, with either jest@test or 20.0.4.
hate this bug to :ballot_box_with_check:
For those having silent failures, check that you're node version is > 6.
Observation:
When I'm running Jest and specifying a config file via the --config option and I try to set the <rootDir> token in the transforms section, I get the following error:

Note that this error message will happen also if your rootDir is set but just isn't resolving to a valid file path. Perhaps there could be better error output?
Jest version : 21.2.1
Stackoverflow thread: https://stackoverflow.com/questions/47192083/is-it-possible-to-have-multiple-jest-configs-within-a-single-project
edit: I figured it out. You use "projects" which could be better documented. See the stack overflow post for more info.
Closing as from what I understand the issue is fixed. Happy to reopen if anybody still has errors
I still got an issue! If you place config in .jestrc it could not find any test. However if you add .json extension to config file, it works.
This is definitely a bug, and I think this should be fixed. Rc files should be considered as json and being processed.
Also having this issue with a config file with .js as the extension. Adding rootDir: '..', to the config as someone suggested above works.
As a workaround for now you may want to set
"rootDir": "../../"or so.
set it where?
Most helpful comment
I also ran into issues with the
--configoption after upgrading, and this is what I have found:rootDiris no longer relative to the current working directory (in whichjestis 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.jsonfile withrootDir: ''in a subdirectory. Changing it torootDir: '..'makes the tests run again.