🐛 Bug Report
In a monorepo setup, that uses ts project references, it is possible to get ts-jest to compile child project refs so that tests in the parent project run in jest. This is evident in the repro repository here: https://github.com/Martaver/ts-jest-issue-805-demo which, when you clone and run yarn test navigates my-app's dependency on my-library successfully and compiles and runs the tests.
In this example, index.ts is in the root directory of each project reference and they use the default main entry in package.json, which is index.js.
Most repositories though, keep code under /src, and one of the features of project references is the ability to map a javascript main entry point in package.json back to the originating typescript entry. It can do this through outDir and rootDir.
However, when moving all code to /src and adding ourDir and rootDir configurations to tsconfig.json and setting the corresponding main in package.json of each project reference, the path resolution fails and the following error is revealed:
Cannot find module '@mfellner/my-library' from '../my-app/src/main.ts'
Unless I'm misconfiguring something, it appears ts-jest isn't honouring tsc's project resolution behaviour.
Note that tsc -b works fine (executed in packages/my-app for instance).
To Reproduce
Steps to reproduce the behavior:
- Clone https://github.com/Martaver/ts-jest-issue-805-demo/
- Switch to branch: repro-ts-jest-outDir-rootDir
- Run
yarn test... you will notice that my-app fails because it can't load my-library.
Expected behavior
ts-jest to successfully load the my-library module from the project reference, as it does when index.ts is in the root of each project.
Link to repo (highly encouraged)
https://github.com/Martaver/ts-jest-issue-805-demo/
branches:
- repro-ts-jest-outDir-rootDir (demonstrates error)
- master (demonstrates working project ref test, in root of project reference)
Debug log:
envinfo
System:
OS: macOS 10.14.6 (18G4032)
Npm packages:
jest: 26.0.1
ts-jest: 26.1.0
typescript: 3.9.3
🐛 Bug Report
In a monorepo setup, that uses ts project references, it is possible to get ts-jest to compile child project refs so that tests in the parent project run in jest. This is evident in the repro repository here: https://github.com/Martaver/ts-jest-issue-805-demo which, when you clone and run
yarn testnavigatesmy-app's dependency onmy-librarysuccessfully and compiles and runs the tests.In this example,
index.tsis in the root directory of each project reference and they use the defaultmainentry inpackage.json, which isindex.js.Most repositories though, keep code under
/src, and one of the features of project references is the ability to map a javascriptmainentry point inpackage.jsonback to the originating typescript entry. It can do this throughoutDirandrootDir.However, when moving all code to
/srcand addingourDirandrootDirconfigurations totsconfig.jsonand setting the correspondingmaininpackage.jsonof each project reference, the path resolution fails and the following error is revealed:Unless I'm misconfiguring something, it appears
ts-jestisn't honouring tsc's project resolution behaviour.Note that
tsc -bworks fine (executed inpackages/my-appfor instance).To Reproduce
Steps to reproduce the behavior:
yarn test... you will notice thatmy-appfails because it can't loadmy-library.Expected behavior
ts-jestto successfully load themy-librarymodule from the project reference, as it does whenindex.tsis in the root of each project.Link to repo (highly encouraged)
https://github.com/Martaver/ts-jest-issue-805-demo/
branches:
Debug log:
envinfo