[Bug]: preset cannot set rootDir configuration property
Version
28.1.1
Steps to reproduce
- Set jest config preset to a file/module that includes a rootDir setting.
- 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
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.
Still an issue.
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.
Wanna send a PR?
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.
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.
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.
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.