I have a TypeScript project using Yarn workspaces and TypeScript project references. I have a single shared project used by my backend and frontend projects. As expected, some tests in both backend and frontend projects rely on classes and functions exported from the shared project.
When using 25.3.1 version, I can run the tests without any issues. Shared code is correctly imported.
After updating to 25.4.0 or 25.5.0, I run into the following issue:
FAIL backend <TEST NAME>.test.ts
● Test suite failed to run
File not found: /PATH/TO/PROJECT/packages/shared/dist/index.js (resolved as: /PATH/TO/PROJECT/packages/shared/dist/index.js)
at ConfigSet.resolvePath (../../node_modules/ts-jest/dist/config/config-set.js:697:19)
at Object.getCompileResultFromReferencedProject (../../node_modules/ts-jest/dist/compiler/compiler-utils.js:122:38)
at compileFn (../../node_modules/ts-jest/dist/compiler/language-service.js:126:41)
at Object.compile (../../node_modules/ts-jest/dist/compiler/instance.js:52:21)
at TsJestTransformer.process (../../node_modules/ts-jest/dist/ts-jest-transformer.js:85:41)
at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:481:35)
at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:586:40)
at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:624:25)
It seems that the shared project cannot be correctly resolved.
Steps to reproduce the behavior:
See https://github.com/czyzby/ts-node-1613-reproduction.
System:
OS: Linux Mint 19.3
Npm packages:
jest: 25.1.0
ts-jest: 25.4.0
typescript: 3.8.3
would you please try 25.5.1-alpha.0 by install ts-jest@next ?
Same issue, shared project is not correctly resolved.
Hmm ok so it’s a different issue with 25.5.1 trying to solve. Would you please provide a minimum repo ? That will be faster for debugging
in 25.5.0 we added a partial support for TypeScript projectReferences. From the log I can see it goes into the path of trying to resolve file because the monorepo uses projectReferences.
Can you please try to run tsc -b, clear jest cache and rerun test ? I'm curious
I'll try to provide a minimal example.
I did clear the cache, removed node_modules, etc. Only reverting to 25.3 helped so far.
did you run tsc -b before running tests ?
I didn't, and I never had to before. Can confirm that tsc -b generates index.js in the directory that ts-jest expect it to be, but I'd rather not have to run tsc -b on the shared module each time before running the tests.
ok, I will add an option to ts-jest to disable/enable support projectReferences and publish it into 25.5.1-alpha.1 , would you please help to test once it's published ?
See this repo. master branch passes with 25.3, while reproduction branch fails with 25.5 even though tests were not modified. This is the failing CI build.
here is the fix for your issue https://drive.google.com/open?id=17p2-uk8Z26k0qd8NGhhtE7KOz3wntcLZ I have cloned your repo and test this fix against reproduction branch and it worked for me. Would you please check to confirm ?
I'll be able to test it in a few hours, but I'd assume it's OK. I'll give you pushing rights to the repository, you can test it against the CI.
that is great !
anyways, e2e tests already covered it :)
I can confirm that the fixed version you uploaded passes the CI tests.
Nice, the fix will be in 25.5.1 Thanks for your confirmation.
close via #1614
25.5.1 is out
Thanks, the tests pass as expected without tsc -b when using 25.5.1. Can I remove the reproduction repository now @ahnpnl?
sure 👍