const incData = { // 增量代码行号Hash表 'path/a.js': [1, 2, 3], 'path/b.js': [2, 3, 4], ... } const notCovData = { // 未覆盖代码行号的Hash表 'path/b.js': 'Set(3) {1, 2, 3}', 'path/c.js': 'Set(3) {1, 2, 3}', ... } let notCovLintCount = 0 let lineCount = 0 forEach(incData, (data, file) => { const notCovSet = notCovData.get(file) const notCovLines = [] if (notCovSet) { // 如果增量代码文件中有未覆盖的行数 forEach(data, lineNum => { if (notCovSet.has(lineNum)) { notCovLines.push(lineNum) } }) } else { // 增量代码的文件没有被测试覆盖到 if (!ignore) { // 如果是无意为之,所有行号均被统计 notCovLines = notCovLine.concat(data) } } console.log(file, '增量覆盖率:', (1 - notCovLines.length / data.length).toFixed(2) + '%') lineCount += data.length notCovLineCount += notCovLines.length }) console.log('总体增量覆盖率:', (1 - notCovLintCount / lineCount).toFixed(2) + '%') |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |