[jest-expo]: wrong TypeScript mappings using Jest Projects #28559
Labels
CLI
Versioned Expo CLI -- `npx expo start`
needs more info
To be used when awaiting reporter response
Summary
Hello,
I am using
jest-expo
v50.0.4
along with Jest Projects and it is creating a wrong entry in the moduleNameMapper field.Particularly, given the following simplified repo structure:
. ├── packages │ └── the-jest-project │ └── jest.config.cjs └── tsconfig.json
And the following
paths
in thetsconfig.json
file:Running
jest --show-config
outputs the following for the project'smoduleNameMapper
field:The mapped value
"/path/to/repository/packages/the-jest-project/packages/$1"
is obviously wrong. And it breaks all matching tests.This happens because you are using
<rootDir>
here, which within Jest Projects refers to the project (package) root and not the root of the repository. Instead, TypeScript mappings refer to the root of the repository.This potentially will break many projects, especially monorepos, which are encouraged to implement Jest Projects approach.
I would suggest to make your TypeScript mappings feature
opt-in
(or allow to opt-out to no introduce breaking changes) or drop it altogether since I am not sure you will be able to consistently adapt it to the multiple possible edge cases.Additionally, your
moduleNameMapper
values cannot be overridden. My temporary solution was to add the following entries before, with a pattern that does not break:Now, this is not ideal for many reasons, but especially because it breaks native
ESM
exports resolution, for example:Because the
exports
field in a package JSON could have many complex configurations that are not replicable usingmoduleNameMapper
alone.What platform(s) does this occur on?
No response
SDK Version
N/A
Environment
N/A
Minimal reproducible example
N/A
The text was updated successfully, but these errors were encountered: