jest: Jest 20 can't resolve path relative to rootDir if ran from the project root
Do you want to request a feature or report a bug? Bug
What is the current behavior?
● Validation Error:
Module <rootDir>/test/setup.js in the setupTestFrameworkScriptFile option was not found.
Configuration Documentation:
https://facebook.github.io/jest/docs/configuration.html
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.
package.json
{
"scripts": "jest --config test/config.json"
}
test/config.json
{
"setupTestFrameworkScriptFile": "<rootDir>/test/setup.js"
}
test/setup.js file is present.
Example repo: https://github.com/le0nik/jest-validation-error After getting ValidationError with jest@20 install jest@19 and the test will run.
What is the expected behavior? Jest runs tests like it does in jest@19
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
- OSX 10.12.4
- Node.js 7.10.0
- npm 4.2.0
- Jest 20.0.0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 40
- Comments: 22 (3 by maintainers)
Commits related to this issue
- Use process.cwd as config.rootDir fallback Fixes #3499 and #3613 — committed to hudochenkov/jest by hudochenkov 7 years ago
- Use process.cwd as config.rootDir fallback Fixes #3499 and #3613 — committed to hudochenkov/jest by hudochenkov 7 years ago
- Use process.cwd as config.rootDir fallback Fixes #3499 and #3613 — committed to hudochenkov/jest by hudochenkov 7 years ago
- Use process.cwd as config.rootDir fallback Fixes #3499 and #3613 — committed to hudochenkov/jest by hudochenkov 7 years ago
I was able to work around this bu duplicating
rootstomodulePaths, e.g.:I was able to fix mine with a simple change:
simple for me likely because my rootDir was
.I am also having similar issues where after upgrading from
19.0.0to20.0.0, where the runners broke due to not being able to match anything viatestMatchwhich was working fine in19.0.0. My configuration is:After upgrading to
20.0.0I’m getting:Rolling back to 19.0.0 makes the issue go away and my tests are found without issue.
This is preventing us from upgrading past Jest 19 😦
I also ran into this exact same problem. I had my test
config.jsonin/test/, and using the--showConfigflag revealed that myrootDirwas being set to/testrather than the root directory where mypackage.jsonlives. SettingrootDirto../is my current workaround.@evan-scott-zocdoc same thing. Have to stay on Jest 19 and just read and listen about how delightful Jest 20 experience is.
As a workaround for people waiting for this to be resolved, adding a
"rootDir"key to your jest config might do the trick, e.g.:"rootDir": "../". Found here.Yes this is definitely a bug. We need to spend some time fixing up the new config resolution.
@bumbu yeap. Found the culprit to be this line: https://github.com/facebook/jest/blob/master/packages/jest-config/src/index.js#L50.
If the path to config is passed in
argv.config, thenrawOptionsis equal to that path and jest sets therootto the directory that contains the config.I can also add that using
also stopped working (nothing in
src/sharedwas found/resolved correctly) when I tried upgrading to v20. It sounds related to me but I could just be doing something wrong.I made some investigations and submitted a PR with explanations https://github.com/facebook/jest/pull/4587. The issue is fixed in a PR, but it creates a new problem. I hope people subscribed to this issue could cheap in and help fix an issue with
<rootDir>.