I understand that jest does not work with webpack directly and hence any transformations that are enabled through webpack in your regular config need to be enabled in jest through various other means. Since jest supports babel config, it is fairly easier to do most of the required transformations, as webpack would also be using the same babel config, but in case of specific loaders like css loader or file loader, we have to make changes to moduleNameMapper in jest to mock those.
If you are using define plugin in webpack, we can kinda replicate the same with globals in jest.
One thing that I am currently stuck on though is to enable string replace loader like functionality with some jest or babel config.
Scenario:
I have some import statements which have a dummy string like:
import sm-specific from blah
And later on sm-specific is replaced by webpack before build, using string replace loader. The problem is, there is no way in jest that I know of, which can enable the same functionality, and so jest starts giving out error in module resolution, since it cannot find sm-specific anywhere.
The expectation is to have something in jest so that sm-specific can be replaced before jest runs the test.
Any pointers?
Please note that I can't use globals for this similar to how I could use for definePlugin, as import statements do not allow template strings and definePlugin variables have to be used as variables.