简体   繁体   English

测试AVA + React-Native的配置

[英]Test config for AVA + React-Native

I try to test my react-native application using AVA and the babel-preset-react-native 我尝试使用AVAbabel-preset-react-native测试我的react-native应用程序

My config looks like this: 我的配置如下所示:

"scripts": {
  "test": "ava"
},
"ava": {
  "files": [
    "src/**/__tests__/*.js"
  ],
  "failFast": true,
  "require": [
    "react-native-mock/mock.js",
    "babel-register"
  ],
  "babel": {
    "presets": [
      "react-native"
    ]
  }
},
"devDependencies": {
  "ava": "^0.13.0",
  "babel-preset-react-native": "^1.2.4",
  "babel-register": "~6.4.3",
  "react-native-mock": "0.0.6"
}

…and fails like this: ......并且失败了:

/Users/zoon/Projets/xxxxx/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/index.js:556
      throw err;
      ^

SyntaxError: /Users/zoon/Projets/xxxxx/src/reducers/env.js: Unexpected token (12:8)
  10 |     case types.RECEIVE_CHANGE_ENV:
  11 |       return {
> 12 |         ...state,
     |         ^
  13 |         current: Environments[action.env]
  14 |       };
  15 |     default:

If I export this babel config in a .babelrc file and use "babel": "inherit" in my AVA config, it fails in an other way: 如果我在.babelrc文件中导出这个babel配置并在我的AVA配置中使用“babel”:“inherit”,它会以另一种方式失败:

/Users/zoon/Projets/xxxxx/node_modules/lodash-es/lodash.js:10
export { default as add } from './add';
^^^^^^

SyntaxError: Unexpected token export

I can't understand how to correctly configure this. 我无法理解如何正确配置它。 I've tried Mocha, encountered the same problems. 我试过摩卡,遇到了同样的问题。

babel-register ignores node_modules by default. babel-register默认忽略node_modules You can set ignore:false in your .babelrc to disable that behavior. 您可以在.babelrc设置ignore:false以禁用该行为。 You could (probably should) also specify a more limited regular expression to avoid processing everything in node_modules . 您可能(可能应该)也指定一个更有限的正则表达式,以避免处理node_modules 所有 node_modules

See the docs: https://babeljs.io/docs/usage/require/ 请参阅文档: https//babeljs.io/docs/usage/require/

Your complete config should probably look something like this: 您的完整配置应该看起来像这样:


.babelrc .babelrc

{
  "presets": ["react-native"],
  "ignore": false
}

package.json 的package.json

{
  "ava": {
    "babel": "inherit"
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM