question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
SimenBcommented, Mar 2, 2018

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

1reaction
maxmiltoncommented, Mar 7, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't find a root directory while resolving a config file path ...
Solved: On test pipeline using default bitbucket-pipelines.yml i'm getting the following error: Error: Can't find a root directory while resolving a.
Read more >
Resolve file paths in Jest - webpack
When I run jest command in npm, I get an error saying 'Cannot find module ...`. How can I resolve file paths when...
Read more >
Configuring Jest
Use the <rootDir> string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your...
Read more >
Support for roots and modulePaths in jest.config.js files
Basically, you need to take into consideration the jest configuration for resolving the files. The IDE is capable of link the file (maybe...
Read more >
try running this command: jest...
Error: Can't find a root directory while resolving a config file path. Provided path to resolve: /home/runner/config.json. cwd: /home/runner/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found