jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: config options set at root level aren't copied to `projects`

Open davidjb opened this issue 1 year ago • 23 comments

Version

29.5.0

Steps to reproduce

  1. Clone minimal repo: https://gist.github.com/davidjb/eb8803286d8e6b1f0ca0d95e231fe3ca
  2. npm i
  3. Mock project dir: mkdir -p path/to/example
  4. npm test -- --showConfig
  5. Observe config output where child project configuration has Jest's defaults set and not the root-level config for testMatch, testPathIgnorePatterns, watchPathIgnorePatterns and so on (output below).

Expected behavior

The documentation for projects (https://jestjs.io/docs/configuration#projects-arraystring--projectconfig) states that:

With the projects option enabled, Jest will copy the root-level configuration options to each individual child configuration during the test run, resolving its values in the child's context.

So, the expectation is that an option set at the global level would be applied to all project entries.

Actual behavior

Project config use Jest's configuration defaults instead of the root-level config set. Interestingly, the global options don't actually show up under globalConfig, either:


{
  "configs": [
    {
      [...]
      "testMatch": [
        "**/__tests__/**/*.[jt]s?(x)",
        "**/?(*.)+(spec|test).[tj]s?(x)"
      ],
      "testPathIgnorePatterns": [
        "/node_modules/"
      ],
      [...]
      "watchPathIgnorePatterns": []
    }
  ],
  "globalConfig": {
    [...]
    "projects": [
      {
        "displayName": "example",
        "rootDir": "path/to/example"
      }
    ],
    [...]
    "testTimeout": 12345,
    [...]
  },
  "version": "29.5.0"
}

Additional context

Note that this was tested in both package.json and jest.config.js - the results are the same. Also, whilst this example focuses on testMatch, testPathIgnorePatterns and watchPathIgnorePatterns, the issue appears to affect all options I've tried - such as setupFilesAfterEnv too.

That said, some options (such as testTimeout) will automatically apply to all projects, presumably because they're set at a global level and can't be applied to a project. In this specific case trying to set testTimeout for a project results in a Validation Warning: Unknown option "testTimeout" with value 678 was found. This is probably a typing mistake. Fixing it will remove this message.

Environment

System:
    OS: macOS 13.4
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 20.2.0 - /opt/homebrew/bin/node
    Yarn: 3.4.1 - /opt/homebrew/bin/yarn
    npm: 9.6.6 - /opt/homebrew/bin/npm
  npmPackages:
    jest: ^29.5.0 => 29.5.0

davidjb avatar Jun 13 '23 01:06 davidjb

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[bot] avatar Jul 13 '23 02:07 github-actions[bot]

/unstale

davidjb avatar Jul 13 '23 03:07 davidjb

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[bot] avatar Aug 12 '23 04:08 github-actions[bot]

/unstale

davidjb avatar Aug 12 '23 04:08 davidjb

Check discussion and motivations in #12871 which introduced the lines in question. Nobody was listening, so I gave up. Just open a PR with a revert or improve the explanation.

That is complex. Global config are not copied, only options from project config. What is global and project configs? How to explain that? Uff.. Perhaps suggesting to run jest --showConfig and inspect the resolved configs is enough?


developers shouldn't rely on --showConfig to understand how rootDir works only if you're using projects. For instance, I've been using Jest for more than 4 years and I've never heard of --showConfig

That’s a quote from that discussion. This is why I think some more education around --showConfig could be good idea.

Here we talked about collectCoverageFrom which simply ignores the <rootDir> token. That is another part documentation is missing.

mrazauskas avatar Aug 12 '23 04:08 mrazauskas

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[bot] avatar Sep 11 '23 06:09 github-actions[bot]

/unstale

davidjb avatar Sep 11 '23 07:09 davidjb

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[bot] avatar Oct 11 '23 09:10 github-actions[bot]

/unstale

davidjb avatar Oct 12 '23 13:10 davidjb

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[bot] avatar Nov 11 '23 14:11 github-actions[bot]

/unstale

davidjb avatar Nov 13 '23 03:11 davidjb

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[bot] avatar Dec 13 '23 03:12 github-actions[bot]

/unstale

davidjb avatar Jan 03 '24 08:01 davidjb

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[bot] avatar Feb 02 '24 09:02 github-actions[bot]

/unstale

davidjb avatar Feb 02 '24 10:02 davidjb

The projects implementation is useless because its related documentation is awful. Many things simply don't work as described, others are unintuitive. I had to go one by one, splitting options between the main config file and the "projects" config files until they more or less worked.

ernestostifano avatar Feb 10 '24 08:02 ernestostifano

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[bot] avatar Mar 11 '24 08:03 github-actions[bot]

/unstale

davidjb avatar Mar 12 '24 14:03 davidjb

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[bot] avatar Apr 11 '24 15:04 github-actions[bot]

/unstale

davidjb avatar Apr 12 '24 14:04 davidjb

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[bot] avatar May 12 '24 15:05 github-actions[bot]

/unstale

davidjb avatar May 14 '24 04:05 davidjb

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[bot] avatar Jun 13 '24 05:06 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Jul 13 '24 06:07 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Jul 13 '24 06:07 github-actions[bot]

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[bot] avatar Aug 13 '24 00:08 github-actions[bot]