Closed pumano closed 1 year ago
Looks like I found solution: By default ts-jest
uses TypeScript compiler in the context of a project (yours), with full type-checking and features. But it can also be used to compile each file separately, what TypeScript calls an ‘isolated module’. That’s what the isolatedModules
option (which defaults to false
) does. Link to ts-jest
const nxPreset = require("@nrwl/jest/preset").default;
module.exports = {
...nxPreset,
globals: {
'ts-jest': {
isolatedModules: true
}
},
};
That really solve 2 of my problems:
But got problem:
Hi @pumano,
In your example, you say that importing helpers lib from UIKit doesn't use the lib with the ts error, but it does. because helpers imports the ts error lib then importing from helpers will therefore include the ts error lib.
You can see this by viewing the nx project graph (nx graph
).
As you mentioned, you can run with isolatedModules which turns off type checking, which is a great solution if you don't want/need to type check your tests.
another option is to use deep imports for tests so you don't include everything in your barrel (index.ts) file if you're only wanting to import 1 thing without transforming/checking the whole library public API. this is handy when your projects end up being very large.
I'm going to close this issue since it's working as intended.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
I have nx layout
libs
when I create unit test inside uikit and import something from helpers I got errors from some-other-lib-typescript-errors. How? I don't import it somehow. Yes, helpers lib can load something, but not my plain function that I import. That problem exists 1-1.5 year.
Looks like jest trying to load some code from libraries as modules and create some typechecking, but I don't need it, I need run my test only, without somehow loading other modules that is not used directly via imports.
Expected Behavior
run my tests only, without loading other modules that is not used directly via imports.
GitHub Repo
https://github.com/pumano/nx-jest-typechecking-not-used-libraries
Steps to Reproduce
npm i --force
nx test uikit
Nx Report
Failure Logs
Additional Information
No response