jest: Jest resolver does not follow symbolic links
I have the following tree:
.
├── app_modules
│ ├── actions
│ ├── components
│ ├── __tests__
│ ├── constants
│ ├── libs
│ ├── models
│ ├── shared -> ../../../../../js_lib/shared/
│ │ ├── components
│ │ │ └── __tests__
│ │ ├── libs
│ │ └── utils
│ └── utils
└── src
└── main
When running npm test
all tests inside the symbolic link shared are not executed by the client.
Thank you.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 20 (8 by maintainers)
Yeah, I’m working with a monorepo too, and lack of symlink support is a real pain.
I understand that you don’t like symlinks, however I don’t follow why you would block using them within the tool. Anyone that doesn’t want to use symlinks doesn’t have to, they just don’t create them, but for you to disallow symlinks within the test finder makes our setup very hard to work with, especially since all the other tools we use are completely happy with symlinks.
Our setup looks like
All the code shared between the 2 projects is in the real shared folder and both projects use a symlink to place that folder into both projects.
ProjectA is the main website, ProjectB is the admin website, so the shared folder is used extensively by both projects. What I’ve shifted to is:
Which will work, but is less obvious than the original layout. All because one tool (jest) has decided that symlinks “always cause trouble”, something I would debate is false. So while it might be by design, does that design actually make sense in light of the rest of the toolchain which works just fine with symlinks?
So, even though all the other tools work with symlinks, since you don’t like symlinks, its perfectly acceptable for jest to explicitly ignore symlinks? Is that what you are saying?
https://github.com/facebook/jest/pull/7549
After lots of experimenting and digging through docs, it appears one can use the
roots
configuration option to specify multiple directories, which are included when looking for__mocks__
. This solves my problem wonderfully.no, I think it would make sense to support them overall. I think if you change the node crawler to support them behind a flag (that would disable watchman as well), I wouldn’t stop you from adding it to the codebase, granted it is well written and tested etc.
Feel free to send us a pull request that fixes Jest to fit your use case. If it doesn’t make Jest harder to maintain and works within our constraints, I’m happy to accept it.
Personally, the only reason I get to work on Jest at Facebook is because I’m solving Facebook’s problems related to JavaScript testing. This is not a problem for us so I’m not able to justify working on it myself.