Last active
October 19, 2018 16:24
-
-
Save forgo/32d0295df91d5d41ca129134aec6c566 to your computer and use it in GitHub Desktop.
allows imports in jest tests to not be confused by webpack imports of non-javascript files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // HOW TO: | |
| // jest --config jest.config.js | |
| // -- assetsTransformer.js -- | |
| // const path = require('path'); | |
| // module.exports = { | |
| // process(src, filename, config, options) { | |
| // return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; | |
| // }, | |
| // }; | |
| // -- jest.config.js -- | |
| module.exports = { | |
| verbose: true, | |
| // This helps prevent configure Jest to gracefully handle asset files such as stylesheets and images. | |
| // Usually, these files aren't particularly useful in tests so we can safely mock them out. | |
| // https://jestjs.io/docs/en/webpack | |
| moduleNameMapper: { | |
| "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/assetsTransformer.js", | |
| "\\.(css|less)$": "<rootDir>/assetsTransformer.js" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment