Fix writing an absolute path to modulePaths in Jest config when ejecting#12599
Fix writing an absolute path to modulePaths in Jest config when ejecting#12599mkarajohn wants to merge 2 commits into
Conversation
|
Hi @mkarajohn! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
I realized that the original fix would not work for paths longer than 1 directory deep, e.g. So, type additionalModulePaths = {
resolved: [string];
relative: [string];
}
|
Resolves #8965
Problem & Cause
As described in the linked issue, when a CRA project is ejected, the
modulePathsentry of the jest config includes an array of absolute paths, if abaseUrlis defined in thetsconfig.jsonorjsconfig.json.The array is created here exported as
additionalModulePaths.Since this exported array of
additionalModulePathsis also used in thewebpack.config.jshere, where absolute paths are in fact needed, we cannot be directly modifying the way theadditionalModulePathsarray contents are created.Solution
What this PR does in order to fix the issue, is to translate the absolute paths to relative ones in the
createJestConfig.jsfile here, since adding absolute paths in themodulePathsis problematic, in cases such as CI pipelines, or simply someone else trying to run the tests on their own machine. Making them relative to therootDirsolves any issues.Before:

After:
