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

[Docs]: Mention "rootDir" points to a different directory when using "projects" #12691

Closed
kettanaito opened this issue Apr 19, 2022 · 10 comments · Fixed by #12871
Closed

[Docs]: Mention "rootDir" points to a different directory when using "projects" #12691

kettanaito opened this issue Apr 19, 2022 · 10 comments · Fixed by #12871

Comments

@kettanaito
Copy link
Contributor

Version

27.0.6

Steps to reproduce

Consider the following root-level configuration:

// jest.config.js
module.exports = {
  projects: ['<rootDir>/packages/*'],
  collectCoverageFrom: ['<rootDir>/src/*'}
}

Expected behavior

This needs to be mentioned in the documentation for projects. I've spent two days trying to understand why Jest doesn't pick up correct glob patterns in collectCoverageFrom just to find out that rootDir doesn't mean what I expect it to mean.

I've checked both projects and collectCoverageFrom sections of the documentation and found no mention whatsoever that would've helped me save time debugging.

Actual behavior

The values of rootDir in those two configuration options point to different paths:

  • For projects the rootDir points to CWD, effectively.
  • For collectCoverageFrom the rootDir points to each project's root directory.

This is confusing because the same placeholder is written in the same module but means different things.

Why this happens

This happens because when using projects Jest appends configurations like collectCoverageFrom to each individual project's configuration. In other words, the rootDir in collectCoverageFrom gets evaluated on each individual project's run, while the rootDir in projects is evaluated when the root-level config is parsed.

Additional context

No response

Environment

System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  npmPackages:
    jest: ^27.0.6 => 27.3.1
@kettanaito kettanaito changed the title [Docs]: Mention "rootDir" changes when using "projects" [Docs]: Mention "rootDir" points to a different directory when using "projects" Apr 19, 2022
@kettanaito
Copy link
Contributor Author

A mention like this in the docs would be extremely helpful:

Note that when using projects, each option in the root-level configuration will be copied to each project's configuration upon test runs. This means that any <rootDir> values in the options will resolve to each project's root directory.

There's certainly a more straightforward explanation than this.

@SimenB
Copy link
Member

SimenB commented Apr 19, 2022

PR very much welcome!

@kettanaito
Copy link
Contributor Author

Hey, @SimenB. Awesome! I'll open a pull request as soon as I have a minute.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@kettanaito
Copy link
Contributor Author

I've opened a pull request that addresses this change to the documentation. Would appreciate a review!

@github-actions github-actions bot removed the Stale label May 24, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jun 23, 2022
@github-actions github-actions bot removed the Stale label Jul 15, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 14, 2022
@kettanaito
Copy link
Contributor Author

The pull request is opened since a few months back: #12871
I'd appreciate some final review from the team to have it merged.

@github-actions github-actions bot removed the Stale label Aug 15, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@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 Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants