-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在 jest --coverage 时候会报错 #189
Comments
Refs #172 |
测试环境其实没必要用这个。 |
对啊,我的意思就是希望有个disable的配置项,只需要在test env下配置一次就行了 |
Would you mind providing an English explanation please? Might be handy for future references. Also I would say there's still an issue here, see #172 (comment) |
@pascalduez Don't use |
@yesmeck Thanks! That also the conclusion I ended up with. |
Thanks a lot. After hours of researches, it's the unique answer that saves my life. |
@kive323 how to disabled babel-plugin-import in test environment? |
Here is my
I only enable babel-plugin-import in dev and production environment. |
If you're use a const {NODE_ENV = 'development'} = process.env;
const presets = ['react-app', '@babel/preset-typescript'];
const plugins = [
[
'named-asset-import',
{
loaderMap: {
svg: {
ReactComponent: '@svgr/webpack?-svgo,+titleProp,+ref![path]'
}
}
}
],
[
'module-name-mapper',
{
moduleNameMapper: {
'^src/(.*)': '<rootDir>/src/$1'
}
}
],
'react-hot-loader/babel'
];
if (NODE_ENV !== 'test') {
plugins.push(['import', {libraryName: 'antd', libraryDirectory: 'es', style: 'css'}]);
}
module.exports = {
presets,
plugins
}; |
To disable babel-plugin-import in test:
This way, you have it enabled by default without explicitly doing it for development and production, and only have it disabled in test env. |
单纯 jest 测试的时候正常,但是配合
--coverage
的时候就报错了,后来去掉import
那部分配置就 OK 了报错信息类似下面这样的:
虽然有个解决办法就是把 import 配置转移到各个 env 下面,但是这样毕竟不够优雅,想知道有没有啥开关可以在
test
部分配置一下?我的
.babelrc
配置如下:The text was updated successfully, but these errors were encountered: