I am working on setting up a project with Webpack & Jest. At the moment Webpack resolve configurations cause complications with Jest tests. In my webpack config I have the following options set:
resolve: {
root: [__dirname + "/src/" ],
extensions: ['', '.js', '.coffee', '.jsx', '.css', '.scss', '.svg']
}
This lets me require assets and modules with:
import UnknownImg from 'assets/unknown';
The above actually lives (relative to my project root) src/assets/unknown.svg
.
However, when I run the test for files with lines like the above I get errors when resolving the path to that required module/asset.
Error: /Users/byronsm/dev/nerve-center/src/components/organisms/system_status.jsx: Cannot find module 'assets/unknown' from '/Users/byronsm/dev/nerve-center/src/components/organisms'
In this case it appears to be doing a relative lookup of the imported module path. Is there a way for me to get Jest to behave the same as Webpack?