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

Can't find a root directory while resolving a config file path. #5595

Closed
faustbrian opened this issue Feb 17, 2018 · 9 comments
Closed

Can't find a root directory while resolving a config file path. #5595

faustbrian opened this issue Feb 17, 2018 · 9 comments

Comments

@faustbrian
Copy link

faustbrian commented Feb 17, 2018

What is the current behavior?

The test suite fails to run because it can't properly resolve the path.

Config

module.exports = {
  projects: [{
    displayName: 'unit',
    testMatch: ['**/__tests__/unit/**/*.spec.js']
  }]
}

Execution

jest --projects unit

Error: Can't find a root directory while resolving a config file path.
Provided path to resolve: unit
cwd: /Users/code/project

What is the expected behavior?

I expected that the test suite runs with the specified configuration because when I do jest --showConfig it shows my rootDir as /Users/code/project which should properly resolve testMatch: ['**/__tests__/unit/**/*.spec.js'] to '/Users/code/project/__tests__/unit/**/*.spec.js'.

I also tried to use <rootDir> for the testMatch but the same result and it looks like it tries to resolve the unit as a path instead of looking it up in the jest.config.js?

Am I supposed to put a jest.config.js into every folder and then run jest --projects tests/unit? If that is the case then how is the projects option supposed to be used.

Jest, node, yarn and macOS are the latest versions.

@SimenB
Copy link
Member

SimenB commented Feb 17, 2018

displayName is just for the name, not a way to run it. Although that would be cool 🙂

--projects on the cli is the same as projects in config, except it can just be paths to different config file, not inline JSON

@faustbrian
Copy link
Author

Thanks, figured that after some testing and ended up putting a config into each directory.

@elyobo
Copy link

elyobo commented Mar 1, 2018

Just to confirm I understand this correctly - there's no way to specify the project to run via the CLI if it's configured using a single config file (e.g. in package.json, jest.config.js etc), but you can specify the test to run (but run all projects by default) by making a separate config file in each project and then referring to those in the main config file, e.g.

package.json snippet

  "jest": {
    "projects": [
      "<rootDir>/jest-test.config.js",
      "<rootDir>/jest-eslint.config.js"
    ]
  }

jest-test.config.js

'use strict';

module.exports = {
  displayName: 'test',
  testPathIgnorePatterns: [
    '/node_modules/',
    '/__tests__/fixtures/',
  ],
};

jest-eslint.config.js

'use strict';

module.exports = {
  runner: 'jest-runner-eslint',
  displayName: 'lint',
  testMatch: ['<rootDir>/**/*.js'],
  testPathIgnorePatterns: [
    '/node_modules/',
  ],
};

It would be nice to avoid scattering the config around like this and still be able to use --projects to indicate the project(s) to run, e.g. by matching the displayName.

@SimenB
Copy link
Member

SimenB commented Mar 2, 2018

@elyobo Correct. PR welcome for some way of specifying which of the loaded projects to run 🙂

@elyobo
Copy link

elyobo commented Mar 2, 2018

I'll see if I can find some time! I went ahead and split out the config files, which works fine, it just feels like clutter :D

@maxmilton
Copy link

Would be great to avoid duplication of identical configs in monorepos. Something like a pathMatch option for projects: [] so similar sub projects can be grouped together.

@yozlet
Copy link
Contributor

yozlet commented Aug 15, 2018

Thanks for the clarification. Could you please add that same clarification to the docs? Right now, the explanation of --projects is so minimal that I can't tell if it's confusingly ambiguous or just wrong.

@SimenB
Copy link
Member

SimenB commented Aug 18, 2018

Wanna send a PR for that? :)

yozlet added a commit to yozlet/jest that referenced this issue Aug 21, 2018
As requested by @SimenB in jestjs#5595, but only because he added a smiley.
yozlet added a commit to yozlet/jest that referenced this issue Aug 21, 2018
As requested by @SimenB in jestjs#5595, but only because he added a smiley.
yozlet added a commit to yozlet/jest that referenced this issue Aug 21, 2018
As requested by @SimenB in jestjs#5595, but only because he added a smiley.
@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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants