Recipe for using AVA with Webpack aliases
See original GitHub issueI use Webpack in my app and I defined aliases in config: webpack.config.dev.js:
....
resolve: {
// We can now require('file') instead of require('file.jsx')
extensions: ['', '.js', '.jsx', '.scss'],
alias: {
actions: PATHS.app + '/actions',
components: PATHS.app + '/components',
store: PATHS.app + '/store',
reducers: PATHS.app + '/reducers',
helpers: PATHS.app + '/helpers',
sagas: PATHS.app + '/sagas',
services: PATHS.app + '/services',
},
}
....
And I import modules like so: componts/LoginPage.js
import {login} from 'actions/Login'
instead of
import {login} from '../actions/Login'
But AVA doesn’t allow to define aliases, so I’m unable to test componts/LoginPage.js with AVA since it throws that error:
Error: Cannot find module 'actions/Login'
Is there a solution?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Using webpack aliases in AVA tests
I need to include the aliases from webpack into AVA when it runs. I used webpack's resolve.alias to access all the files under...
Read more >Using Webpack Aliases In Ava Tests
I'm working on some unit tests of React components.The tests are written with AVA and use Enzyme to shallow render components.When the component...
Read more >avajs/ava
We make use of aliases in webpack to alias some of our requires so that we can switch between a local and a...
Read more >npm:@ava/babel
Adds Babel 7 support to AVA so you can use the latest JavaScript syntax in your ... Webpack aliases can be used to...
Read more >ts-node
... by running `npm i ts-node`. There are 7243 other projects in the npm registry using ts-node. ... Recipes. Watching and restarting; AVA....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you, guys for your help. It seems to work with following configs:
config/webpack.config.ava.js
package.json
.babelrc
Btw, I have another solution of my problem (without using webpack):