I'm writing a Jest test and am having trouble resolving this import which uses webpack's worker-loader
import ImageInfoWorker from 'worker-loader?name=image_info!@WORKERS/image-info';
I have some other aliases which are resolving properly in my tests, such as:
import Store from '@SUPPORT/store';
import * as api from '@SUPPORT/api';
Here is the relevant snippet from package.json
"jest": {
"moduleFileExtensions": ["js", "jsx"],
"moduleNameMapper": {
"^@CSS/(.*)$": "<rootDir>/css/$1",
"^@COMPONENTS/(.*)$": "<rootDir>/js/components/$1",
"^@MODELS/(.*)$": "<rootDir>/js/models/$1",
"^@STORES/(.*)$": "<rootDir>/js/stores/$1",
"^@SUPPORT/(.*)$": "<rootDir>/js/support/$1",
"^(.*?)@WORKERS/(.*)$": "$1<rootDir>/js/workers/$2"
}
}
And here is the resolve
section of my webpack config:
resolve: {
extensions: ['.js', '.jsx'],
modules: [process.env.NODE_PATH, 'node_modules'],
alias: {
'@CSS': path.join(projectRoot, 'css'),
'@COMPONENTS': path.join(projectRoot, 'js', 'components'),
'@MODELS': path.join(projectRoot, 'js', 'models'),
'@STORES': path.join(projectRoot, 'js', 'stores'),
'@SUPPORT': path.join(projectRoot, 'js', 'support'),
'@WORKERS': path.join(projectRoot, 'js', 'workers')
}
},
If you don't need the path to be resolved, you can use "moduleNameMapper"
to ignore the import.
First, create an empty module that contains export default ''
.
Next, add the following to your package.json
:
"jest": {
"moduleNameMapper": {
"^worker-plugin/loader.+$": "<rootDir>/EmptyModule"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With