我试图将nyc
ava
和babel
放在一起。我遇到了async / await分支显示为未覆盖的问题,因此这很有效,我在集成babel-plugin-istanbul
插件进行测试时遇到问题。
我在项目中有两个文件,src/index.js
和src/test.js
。
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ava",
"coverage": "NODE_ENV=test nyc npm run test",
"report": "nyc report --reporter=html",
"report:open": "open ./coverage/index.html",
"cover": "npm run coverage && npm run report && npm run report:open"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-runtime": "^6.26.0",
"bluebird": "^3.5.0",
"lodash": "^4.17.4"
},
"devDependencies": {
"ava": "^0.22.0",
"babel-cli": "^6.26.0",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.26.0",
"nyc": "^11.2.1",
"sinon": "^3.2.1",
"testdouble": "^3.2.4"
},
"babel": {
"presets": ["env"],
"plugins": ["transform-runtime"],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
},
"ava": {
"require": ["babel-register"],
"babel": "inherit"
},
"nyc": {
"sourceMap": false,
"instrument": false
}
}
这里有什么:
> example@1.0.0 coverage /Users/me/Desktop/example
> NODE_ENV=test nyc npm run test
> example@1.0.0 test /Users/me/Desktop/example
> ava
11 passed
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
> example@1.0.0 report /Users/me/Desktop/example
> nyc report --reporter=html
> example@1.0.0 report:open /Users/em/Desktop/example
> open ./coverage/index.html
为什么没有src/index.js
出现在报道中?
答案 0 :(得分:0)
尝试将test.js
移动到某个测试文件夹test/test.js
下