jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: preset cannot set rootDir configuration property

Open ddurschlag opened this issue 3 years ago • 6 comments

Version

28.1.1

Steps to reproduce

  1. Set jest config preset to a file/module that includes a rootDir setting.
  2. Notice that this isn't honored.

I'm providing a kinda crappy repro here because I can also provide the root cause:

Incoming options are always merged in on top of the loaded preset ({...preset, ...options}) and also always have a rootDir. This means the preset's value is always ignored!

Expected behavior

I expected my rootdir (which in my case is dynamically generated based on internal conventions) to be honored.

Actual behavior

My rootdir was not honored :(

Additional context

Here's where the bad thing happens:

mergeModuleNameMapperWithPreset(options, preset); mergeTransformWithPreset(options, preset); mergeGlobalsWithPreset(options, preset); return {...preset, ...options}; // <-- this bit, right here, overwrites any preset value that is also in options... including always rootDir

Environment

System:
    OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (12) x64 Intel(R) Xeon(R) W-2133 CPU @ 3.60GHz
  Binaries:
    Node: 16.14.2 - <path removed>
    npm: 7.17.0 - /local-ssd/ddurschl/global_modules/bin/npm
  npmPackages:
    jest: ^28.1.1 => 28.1.1

ddurschlag avatar Jun 22 '22 15:06 ddurschlag

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 22 '22 15:07 github-actions[bot]

Still an issue.

ddurschlag avatar Jul 22 '22 15:07 ddurschlag

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 21 '22 16:08 github-actions[bot]

Wanna send a PR?

SimenB avatar Aug 22 '22 09:08 SimenB

Wanna send a PR?

Sure! What behavior would you like? I could swap the presets and options so that presets always win, I could specifically pull rootDir from presets and overwrite with it at the end, or (most complicated) I could try to separate "options" from "default options" and merge default options -> presets -> options.

ddurschlag avatar Aug 22 '22 14:08 ddurschlag

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 21 '22 14:09 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 Oct 21 '22 14:10 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 Nov 21 '22 00:11 github-actions[bot]