Closed anil-sequoia closed 3 years ago
Sorry to hear about your troubles, but I'm not sure how this is related to TSDX and you haven't made that clear. The files are already compiled so you shouldn't have to transform them, they work in dev and prod, and tsdx test
shallow merges your Jest config, so you've already overwritten much of it.
Issues also are not a support forum for debugging help. Feel free to use StackOverflow or something, but even there the expectation is that you furnish an MVCE, which is quite lacking here. You've only provided a few small snippets of a seemingly large codebase, and not a minimal reproduction.
I've provided some comments on your statements below, but, to repeat, this is not a support forum for debugging help, especially not for issues unrelated to TSDX.
The dist folder of components has index.js files which looks like this:
Yes, that's normal, intended behavior
var AllTheExportsFromComponents = require('@eureka/components');
This sounds like a recursive import, you said this is inside of components
...
The jest will not transform anything in node_modules by default. Hence the require statements in cjs file will not be resolved.
I'm not sure how those are related -- transforms and resolutions are two different things.
You normally don't need to transform anything in node_modules
either -- it contains built / compiled / transpiled code. Files output to dist/
by TSDX are already built, there's no need to transform them.
The line above is blank object. Ideally it should have reference to the object having all the components returned from @eureka/components.
If this returns something then that means it is resolved. If it's "not resolved", then Node will throw an error.
So my question is, what can do right to fix this scenario or it is not a good practice to test component's behavior coming from node_modules.
I don't understand what the problem is to begin with, but no, normally one tests the package itself. That also enables test watch mode (i.e. tsdx test --watch
), which can't be done when testing dist/
instead of src/
without running another process to constantly build (i.e. tsdx watch
).
You can have integration tests on top of that though, which would, almost by definition, test installed packages.
Current Behavior
We have a component, hooks and utilities library which is private repo based on lerna and tsdx.
The name of the packages are as follows @eureka/components, @eureka/hooks and @eureka/utilities
The dist folder of components has index.js files which looks like this:
And then the component.cjs.development has import like below:
Now this same dist folder becomes part on node_modules in another application where I am using @eureka/components
Now in dev mode and production mode it all works fine.
But the problem is with tests in this consumer application
I have started writing unit test cases using react-testing-library and jest
But the import i showed above does not resolve. and cause failure in test runs.
What all I was able to figure out yet:
The jest will not transform anything in node_modules by default. Hence the require statements in cjs file will not be resolved.
Basically if you will see above
The line above is blank object. Ideally it should have reference to the object having all the components returned from @eureka/components.
My jest config looks like this now:
So my question is, what can do right to fix this scenario or it is not a good practice to test component's behavior coming from node_modules.
Your environment