Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest 20 can't resolve path relative to rootDir if ran from the project root #3499

Closed
le0nik opened this issue May 6, 2017 · 22 comments
Closed
Labels

Comments

@le0nik
Copy link

le0nik commented May 6, 2017

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
@cpojer
Copy link
Member

cpojer commented May 7, 2017

Yes this is definitely a bug. We need to spend some time fixing up the new config resolution.

@JaKXz
Copy link

JaKXz commented May 7, 2017

I can also add that using

"moduleDirectories": [
  "node_modules",
  "<rootDir>/src/shared"
]

also stopped working (nothing in src/shared was found/resolved correctly) when I tried upgrading to v20. It sounds related to me but I could just be doing something wrong.

@EvHaus
Copy link

EvHaus commented May 8, 2017

I am also having similar issues where after upgrading from 19.0.0 to 20.0.0, where the runners broke due to not being able to match anything via testMatch which was working fine in 19.0.0. My configuration is:

{
  "collectCoverageFrom": ["src/**/*.js"],
  "coverageDirectory": "<rootDir>/coverage",
  "coveragePathIgnorePatterns": [
      "/node_modules/"
  ],
  "moduleNameMapper": {
	"\\.(less)$": "identity-obj-proxy"
  },
  "setupFiles": ["<rootDir>/__tests__/environ-jest.js"],
  "testMatch": ["<rootDir>/src/**/*.test.js"]
}

After upgrading to 20.0.0 I'm getting:

No tests found
In /Users/evgueni.naverniouk/Git/ux
  483 files checked.
  testMatch: <rootDir>/src/**/*.test.js - 0 matches
  testPathIgnorePatterns: /node_modules/ - 483 matches
Pattern: "" - 0 matches

Rolling back to 19.0.0 makes the issue go away and my tests are found without issue.

@joscha
Copy link

joscha commented May 9, 2017

I was able to work around this bu duplicating roots to modulePaths, e.g.:

  roots: ['<rootDir>/src'],
  modulePaths: ['<rootDir>/src'],

@tim-mc
Copy link

tim-mc commented May 10, 2017

I also ran into this exact same problem. I had my test config.json in /test/, and using the --showConfig flag revealed that my rootDir was being set to /test rather than the root directory where my package.json lives. Setting rootDir to ../ is my current workaround.

@thymikee
Copy link
Collaborator

Addressed in #3538

@maiis
Copy link

maiis commented May 10, 2017

Thanks @tim-mc, works for me as well 👍

@marr
Copy link
Contributor

marr commented May 10, 2017

I was able to fix mine with a simple change:

"jest": {
     "moduleDirectories": [
       "node_modules",
-      "<rootDir>/src",
-      "<rootDir>/test"
+      "src",
+      "test"
     ],
     "moduleNameMapper": {

simple for me likely because my rootDir was .

@le0nik
Copy link
Author

le0nik commented May 11, 2017

@thymikee in my case <rootDir> was used in setupTestFrameworkScriptFile property and the error is still present in jest@20.0.1

@mockdeep
Copy link

We're still seeing this issue on jest@20.0.1, same as @le0nik with the setupTestFrameworkScriptFile.

@bumbu
Copy link

bumbu commented May 19, 2017

The issue is that <rootDir> gets replaced with the folder in which jest-config.json lives, and not with the:

rootDir [string]
Default: The root of the directory containing the package.json or the pwd if no package.json is found

I opened #3613 for that

@le0nik
Copy link
Author

le0nik commented May 21, 2017

@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, then rawOptions is equal to that path and jest sets the root to the directory that contains the config.

@evan-scott-zocdoc
Copy link

This is preventing us from upgrading past Jest 19 :(

@le0nik
Copy link
Author

le0nik commented Jul 17, 2017

@evan-scott-zocdoc same thing. Have to stay on Jest 19 and just read and listen about how delightful Jest 20 experience is.

@cpojer
Copy link
Member

cpojer commented Aug 24, 2017

@aaronabramov is this fixed in jest@test?

@le0nik
Copy link
Author

le0nik commented Sep 4, 2017

Not fixed in jest@21.

@hudochenkov
Copy link

I made some investigations and submitted a PR with explanations #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>.

@mockdeep
Copy link

mockdeep commented Oct 6, 2017

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.

@le0nik le0nik closed this as completed Oct 24, 2017
@EvHaus
Copy link

EvHaus commented Oct 30, 2017

Confirming that the issue I described above is resolved in jest@21.3.0-beta.. Thank you!

hudochenkov added a commit to hudochenkov/jest that referenced this issue Nov 11, 2017
hudochenkov added a commit to hudochenkov/jest that referenced this issue Nov 12, 2017
hudochenkov added a commit to hudochenkov/jest that referenced this issue Feb 20, 2018
@Fi1osof
Copy link

Fi1osof commented Oct 13, 2018

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.

This works for me too:

module.exports = { 
  rootDir: process.cwd(),
};

@aemre
Copy link

aemre commented Aug 3, 2019

check your package.json file is setupTestFrameworkScriptFile path correct.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.