1

我的问题和How to measure common coverage for Polymer components + .js files?之间有一些相似之处?. 尽管如此,它被接受为答案“拆分为 .js 文件并将其包含到组件中”,以便使用 wct-istanbul 并且我的所有 Web 组件和测试都在 .html 文件中(javascript 在每个 .html 文件中)。

我的直截了当的问题是:我仍然可以使用 wct-istambul 来检查我的代码中有多少被测试覆盖了吗?如果是这样,下面描述的配置有什么问题?如果没有,wct-istanbub 是否计划在聚合物项目中取代 wct-istanbul?

包.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 ),这似乎是一种临时解决方法(使用 WCT 的 Polymer Application 的代码覆盖率),它可以工作。

wct.conf.js

        "istanbub": {
            "dir": "./coverage",
            "reporters": ["text-summary", "lcov"],
            "include": [
                "**/*.html"
            ],
            "exclude": [
              "**/test/**",
              "*/*.js"
            ],
            thresholds: {
              global: {
                statements: 100
              }
            }
        }
...

结果是... chrome 66 RESPONSE quit() chrome 66 BrowserRunner complete 测试运行大获成功

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
4

0 回答 0