Skip to content

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

@kettanaito

Description

@kettanaito

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions