Closed chrissantamaria closed 1 year ago
Hey! Sorry for the delay in seeing this.
Thanks for the detailed issues; I'll be able to take a look in a couple of days.
Hey FYI I was able to just use the webpack
plugin instead of the jest
one in my jest.config file and seems to work fine that way.
Hi! Sorry for the bump but just wanted to check in on the status of this. I think my branch may fix the issue, so I'd be happy to open a PR if you'd like and we can go from there. Thanks!
Hey Chris!
Sorry to miss this, I've been a bit busy. Have a list of things to get to, so let me review this, add you to the list and let you know at what position of the queue you will be in!
One moment, caller...
Blimey, I'm useless at picking up PRs at the moment. Sorry.
👋 big fan of this package! Ran into a subtle issue in my (unconventional) repo structure.
Problem
Consider this highly simplified and somewhat contrived example:
The bulk of the code lives in
src
, though there's also anapp
directory which functionally is its own package. However, it does share modules (and aliases) withsrc
. Consider thisjsconfig.json
:Both the top-level package and
app
have their own set of tests and correspondingjest.config.js
files. In the top-level config, I would expect (and do correctly get!) the followingmoduleNameMapper
value generated byalias-hq
:Likewise for
app
, I would expect this in its config (app/jest.config.js
):However, I instead get this:
Root cause
This seems to be due to the Jest plugin's implementation using
path.join
: https://github.com/davestewart/alias-hq/blob/dfb0446a1af3d8eb2e44cb14ae66a26de7347837/src/plugins/jest/index.js#L16When
baseUrl
is..
,join
removes the<rootDir>
segment entirely. However, in this case (I think) we always want that to exist. Paths like<rootDir>/../src/utils/$1
resolve just fine with Jest's parser.I've created a reproduction repo matching this described case for easier testing. I also have a branch up which (from what I can tell) fixes the issue - happy to open a PR if you think this is sufficient.
Possible misconfiguration
I wasn't entirely sure how to configure
alias-hq
for this sort of situation. I did the following inapp/jest.config.js
:(I think) I had to manually point to
jsconfig.json
since it's not in a standard location relative to this config. I also manually set abaseUrl
so that paths would be set relative to the parent dir. Still fairly new to this package so please let me know if there's a better / simpler way to configure this!Happy to clarify any details - thanks!