ES6+mocha+istanbul,针对ES6语法的带覆盖率检查的mocha测试
安装 mocha, chai,mochawesome,istanbul
npm install mocha chai mochawesome [email protected] --save-dev
注意1:
istanbul 版本为 "^1.0.0-alpha.2"
为 istanbul 支持ES6语法安装依赖包:
npm i babel-cli babel-register babel-plugin-istanbul babel-preset-env cross-env mocha chai nyc --save-dev
注意2:
为了使 istanbul 支持ES6语法,在package.json加入:
"nyc": { "require": [ "babel-register" ], "reporter": [ "lcov", "text" ], "sourceMap": false, "instrument": false }
注意3:
为了使 istanbul 支持ES6语法,在.babelrc加入:
.babelrc
{ "presets": [ "env" ], "env": { "test": { "plugins": [ "istanbul" ] } } }
package.json
{ "name": "100", "version": "1.0.0", "description": "小猫快跳", "main": "game.js", "directories": { "test": "test" }, "scripts": { "test1": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha test/*.js -- --require babel-register", "test":"cross-env NODE_ENV=test nyc mocha" }, "author": "wangshuxian6", "license": "MIT", "devDependencies": { "babel-cli": "^6.26.0", "babel-plugin-istanbul": "^4.1.5", "babel-preset-env": "^1.6.1", "babel-register": "^6.26.0", "chai": "^4.1.2", "cross-env": "^5.1.3", "grunt": "^1.0.1", "grunt-contrib-watch": "^1.0.0", "grunt-eslint": "^20.1.0", "istanbul": "^1.0.0-alpha.2", "mocha": "^5.0.1", "mochawesome": "^3.0.2", "nyc": "^11.4.1" }, "nyc": { "require": [ "babel-register" ], "reporter": [ "lcov", "text" ], "sourceMap": false, "instrument": false } }
mocha.opts
--require babel-core/register --recursive --reporter mochawesome --bail
最终:
运行nom run test 或 nom run test2 都可以
相关推荐
上海彭彭 2020-01-14
88364458 2020-06-03
87510796 2019-12-01
86201043 2019-10-29
84344790 2019-10-19
不忘初心才能始终 2017-07-10
86201043 2019-07-01
王治 2019-07-01
84344790 2019-07-01
不忘初心才能始终 2019-07-01
88364458 2019-06-30
84344790 2019-06-29
80520394 2019-06-29
mscinsidious 2019-06-29
88364458 2017-07-10
84344790 2017-06-08
86201043 2019-06-28
80520394 2015-06-28
87510796 2019-06-27