https://github.com/jsdf/jest-alias-module-loader
https://github.com/jsdf/jest-alias-module-loader
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jsdf/jest-alias-module-loader
- Owner: jsdf
- License: mit
- Created: 2015-10-02T13:59:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-02T14:04:11.000Z (over 9 years ago)
- Last Synced: 2025-03-06T06:40:49.196Z (about 2 months ago)
- Language: JavaScript
- Size: 121 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-alias-module-loader
Jest doesn't really have a simple way of globally replacing certain modules, but I've come up with a couple. Firstly, the hacky and gross way to [replace modules is by using a regexp replace in the preprocessor](https://github.com/facebook/react/pull/4656/files). But let's not do that. Instead, this module extends the default `HasteModuleLoader` to allow us to alias some modules at `require` time:
```js
// test/aliasedModuleLoader.jsvar JestAliasModuleLoader = require('jest-alias-module-loader');
module.exports = JestAliasModuleLoader({
aliasedModules: {
// use compiled react for faster loading
'react': 'react/dist/react-with-addons',
'react/addons': 'react/dist/react-with-addons',
},
});
```To use this, just add a line to your Jest config (eg. in `package.json`):
```json
{
"jest": {
"moduleLoader": "/test/aliasedModuleLoader.js"
}
}
```