我的问题和How to measure common coverage for Polymer components + .js files?之间有一些相似之处。尽管如此,它被接受为“拆分为.js文件并将其包含在组件中”,以便使用wct-istanbul,我的所有Web组件和测试都在.html文件中(javascript在每个.html文件中)。
我的直接问题是:我是否仍然可以使用wct-istambul来检查我的代码在测试中的覆盖范围?如果是这样,下面描述的配置有什么问题?如果没有,wct-istanbub是否计划用聚合物项目取代wct-istanbul?
的package.json
"polyserve": "^0.18.0",
"web-component-tester": "^6.0.0",
"web-component-tester-istanbul": "^0.10.0",
...
wct.conf.js
var path = require('path');
var ret = {
'suites': ['test'],
'webserver': {
'pathMappings': []
},
'plugins': {
'local': {
'browsers': ['chrome']
},
'sauce': {
'disabled': true
},
"istanbul": {
"dir": "./coverage",
"reporters": ["text-summary", "lcov"],
"include": [
"/*.html"
],
"exclude": [
],
thresholds: {
global: {
statements: 100
}
}
}
}
};
var mapping = {};
var rootPath = (__dirname).split(path.sep).slice(-1)[0];
mapping['/components/' + rootPath + '/bower_components'] = 'bower_components';
ret.webserver.pathMappings.push(mapping);
module.exports = ret;
好吧,我尝试了WCT-istanbub(https://github.com/Bubbit/wct-istanbub),它接缝是一个临时的解决方法(Code coverage of Polymer Application with WCT),它有效。
wct.conf.js
"istanbub": {
"dir": "./coverage",
"reporters": ["text-summary", "lcov"],
"include": [
"**/*.html"
],
"exclude": [
"**/test/**",
"*/*.js"
],
thresholds: {
global: {
statements: 100
}
}
}
...
结果是 ... chrome 66 RESPONSE退出() chrome 66 BrowserRunner完成 测试结束取得了巨大成功
chrome 66 (2/0/0)
=============================== Coverage summary ===============================
Statements : 21.18% ( 2011/9495 )
Branches : 15.15% ( 933/6160 )
Functions : 18.08% ( 367/2030 )
Lines : 21.14% ( 2001/9464 )
================================================================================
Coverage for statements (21.18%) does not meet configured threshold (100%)
Error: Coverage failed