我为React Native编写了一些简单的测试,并在CircleCI上运行,但我得到了以下错误:ReferenceError:Map未定义
我知道Map是一个新的ES6功能,但不确定为什么会出现这个错误。我的测试脚本包括--compilers babel-core/register
,但看起来babel并没有在react原生mock库中编译一些代码。
我不认为这是特定于react native mock的,但我确实注意到库在测试脚本中需要babel-core/register
:"test": "mocha --require babel-core/register test/**/*.js",
尽管我保存的依赖项中有babel核心,但我也尝试过,并获得了Error: Cannot find module 'js:babel-core/register'
。
任何建设性的帮助都将不胜感激。
$ npm test
> BlocMessenger@0.0.1 test /home/ubuntu/Messenger
> mocha --require react-native-mock/mock.js --compilers js:babel-core/register --recursive App/**/__tests__/*.test.js
/home/ubuntu/Messenger/node_modules/react-native-mock/build/api/AppState.js:18
change: new Map(),
^
ReferenceError: Map is not defined
at Object.<anonymous> (/home/ubuntu/Messenger/node_modules/react-native-mock/build/api/AppState.js:18:15)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/ubuntu/Messenger/node_modules/babel-core/node_modules/babel-register/lib/node.js:134:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/ubuntu/Messenger/node_modules/react-native-mock/build/react-native.js:66:13)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/ubuntu/Messenger/node_modules/babel-core/node_modules/babel-register/lib/node.js:134:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/ubuntu/Messenger/node_modules/react-native-mock/mock.js:1:85)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/ubuntu/Messenger/node_modules/babel-core/node_modules/babel-register/lib/node.js:134:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at args (/home/ubuntu/nvm/v0.10.33/lib/node_modules/mocha/bin/_mocha:310:3)
at Array.forEach (native)
at Object.<anonymous> (/home/ubuntu/nvm/v0.10.33/lib/node_modules/mocha/bin/_mocha:309:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
npm ERR! Test failed. See above for more details.
npm test returned exit code 1
解决方案要求我添加一个circle.yml并指定节点v5.0.0。这使circle.yml能够理解new Map
在做什么。无论出于何种原因,如果没有检查,它都不会工作
// circle.yml
machine:
node:
version: 5.0.0
https://github.com/Bloc/Messenger/blob/master/circle.yml#L3