我已经为React Native编写了一些简单的测试并在CircleCI上运行它们,但我收到了以下错误:ReferenceError:Map未定义
我知道Map是一个新的ES6功能,但不确定我为什么会收到此错误。我的测试脚本包含--compilers babel-core/register
,但看起来babel正在编译react-native-mock库中的某些代码。
我认为这不是特定于react-native-mock,但我确实注意到库test script需要babel-core/register
:"test": "mocha --require babel-core/register test/**/*.js",
我也试过了,尽管我在保存的依赖项中使用了babel-core,但我得到了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
答案 0 :(得分:1)
对此的解决方案要求我添加circle.yml并指定节点v5.0.0。这使circle.yml能够理解new Map
正在做什么。无论出于何种原因,如果没有这项检查,它将无法运作
// circle.yml
machine:
node:
version: 5.0.0