STEP:npm测试 错误:“意外的保留字” 我今天早些时候有这个工作,我不知道我改变了什么可能导致回归.当我运行npm测试时,我得到“意外的保留字”并指向ES6导入语句.我的理解是–co
错误:“意外的保留字”
我今天早些时候有这个工作,我不知道我改变了什么可能导致回归.当我运行npm测试时,我得到“意外的保留字”并指向ES6导入语句.我的理解是–compilers js:babel-register应该解决这个问题.
我尝试在全局和本地安装babel-core,而使用babel-core / register.结果相同.
这是我的package.json.
{ "name": "fresh", "version": "0.0.1", "private": true, "scripts": { "remotedev": "remotedev --hostname=localhost --port=8000", "start": "node node_modules/react-native/local-cli/cli.js start", "test": "mocha --compilers js:babel-register 'test/**/*.test.js'", "test:watch": "npm run test -- --watch --watch-extensions jsx" }, "dependencies": { "immutable": "^3.7.6", "lodash": "^4.5.1", "ramda": "^0.19.1", "react-native": "^0.21.0", "react-native-router-flux": "^2.3.8", "react-native-sortable-listview": "0.0.5", "react-redux": "^4.4.0", "redux": "^3.3.1", "redux-saga": "^0.9.1", "reselect": "^2.0.3" }, "devDependencies": { "babel-register": "^6.7.2", "chai": "^3.5.0", "chai-immutable": "^1.5.3", "mocha": "^2.4.5", "redux-devtools-filter-actions": "^1.1.0", "remote-redux-devtools": "^0.1.2", "remotedev-server": "0.0.3" } }
这是2个教程,表明这应该工作.
https://onsen.io/blog/mocha-chaijs-unit-test-coverage-es6/
http://jamesknelson.com/testing-in-es6-with-mocha-and-babel-6/
同样,我今天早些时候使用此脚本成功执行了测试.
npm install babel-preset-es2015
然后用.创建.babelrc文件
{ "presets": ["es2015"] }