Commit 0b4aec06 by lxyang

feat:0.0.6版本优化绝对行数显示

parent 3f4dc584
......@@ -154,5 +154,13 @@ var addSorting = (function () {
enableUI();
};
})();
window.onload = function () {
var isHtmlCss = document.getElementById('isHtmlCss')
if (isHtmlCss) {
isHtmlCss.addEventListener('click', isHtmlShow())
}
}
function isHtmlShow() {
console.log(111111)
}
window.addEventListener('load', addSorting);
......@@ -122,11 +122,12 @@ handlebars.registerHelper('show_ignores', function (metrics) {
handlebars.registerHelper('show_lines', function (opts) {
var maxLines = Number(opts.fn(this)),
i,
array = [];
for (i = 0; i < maxLines; i += 1) {
array = [],
startIndex = Number(opts.data.root.startIndex) || 0;
for (i = startIndex; i < maxLines; i += 1) {
array[i] = i + 1;
}
array = array.slice(startIndex, array.length)
return array.join('\n');
});
......@@ -139,21 +140,13 @@ handlebars.registerHelper('show_line_execution_counts', function (context, opts)
lineNumber,
array = [],
covered,
value = '',
newList = []
if (Array.isArray(changeLists)) {
for (var i = 0; i < changeLists.length; i++) {
if (changeLists[i] - startIndex >= 0) {
newList.push(changeLists[i] - startIndex)
}
}
}
for (i = 0; i < maxLines; i += 1) {
value = '';
for (i = startIndex; i < maxLines; i += 1) {
var label = '';
lineNumber = i + 1;
value = '&nbsp;';
covered = 'neutral';
if (newList.includes(lineNumber)) {
if (changeLists.includes(lineNumber)) {
label = '<span class="neutral-new" style="color: #57a3f3;">新增或变更语句</span> &nbsp;'
}
if (lines.hasOwnProperty(lineNumber)) {
......@@ -209,19 +202,19 @@ function annotateLines(fileCoverage, structuredText) {
function annotateStatements(fileCoverage, structuredText) {
var statementStats = fileCoverage.s,
statementMeta = fileCoverage.statementMap;
Object.keys(statementStats).forEach(function (stName) {
statementMeta = fileCoverage.statementMap,
startIndex = fileCoverage.startIndex;
Object.keys(statementStats).forEach(function (stName, index) {
var count = statementStats[stName],
meta = statementMeta[stName],
type = count > 0 ? 'yes' : 'no',
startCol = meta.start.column,
endCol = meta.end.column + 1,
startLine = meta.start.line,
endLine = meta.end.line,
startLine = meta.start.line - startIndex,
endLine = meta.end.line - startIndex,
openSpan = lt + 'span class="' + (meta.skip ? 'cstat-skip' : 'cstat-no') + '"' + title('statement not covered') + gt,
closeSpan = lt + '/span' + gt,
text;
if (type === 'no' && structuredText[startLine] && structuredText[startLine].text) {
if (endLine !== startLine) {
endLine = startLine;
......@@ -239,7 +232,8 @@ function annotateStatements(fileCoverage, structuredText) {
function annotateFunctions(fileCoverage, structuredText) {
var fnStats = fileCoverage.f,
fnMeta = fileCoverage.fnMap;
fnMeta = fileCoverage.fnMap,
startIndex = fileCoverage.startIndex;
if (!fnStats) { return; }
Object.keys(fnStats).forEach(function (fName) {
var count = fnStats[fName],
......@@ -247,8 +241,8 @@ function annotateFunctions(fileCoverage, structuredText) {
type = count > 0 ? 'yes' : 'no',
startCol = meta.loc.start.column,
endCol = meta.loc.end.column + 1,
startLine = meta.loc.start.line,
endLine = meta.loc.end.line,
startLine = meta.loc.start.line - startIndex,
endLine = meta.loc.end.line - startIndex,
openSpan = lt + 'span class="' + (meta.skip ? 'fstat-skip' : 'fstat-no') + '"' + title('function not covered') + gt,
closeSpan = lt + '/span' + gt,
text;
......@@ -269,9 +263,9 @@ function annotateFunctions(fileCoverage, structuredText) {
function annotateBranches(fileCoverage, structuredText) {
var branchStats = fileCoverage.b,
branchMeta = fileCoverage.branchMap;
branchMeta = fileCoverage.branchMap,
startIndex = fileCoverage.startIndex;
if (!branchStats) { return; }
Object.keys(branchStats).forEach(function (branchName) {
var branchArray = branchStats[branchName],
sumCount = branchArray.reduce(function (p, n) { return p + n; }, 0),
......@@ -295,11 +289,10 @@ function annotateBranches(fileCoverage, structuredText) {
type = count > 0 ? 'yes' : 'no';
startCol = meta.start.column;
endCol = meta.end.column + 1;
startLine = meta.start.line;
endLine = meta.end.line;
startLine = meta.start.line - startIndex;
endLine = meta.end.line - startIndex;
openSpan = lt + 'span class="branch-' + i + ' ' + (meta.skip ? 'cbranch-skip' : 'cbranch-no') + '"' + title('branch not covered') + gt;
closeSpan = lt + '/span' + gt;
if (count === 0 && structuredText[startLine] && structuredText[startLine].text) { //skip branches taken
if (endLine !== startLine) {
endLine = startLine;
......@@ -456,9 +449,9 @@ Report.mix(HtmlReport, {
fileCoverage.code.join('\n') + '\n' : sourceStore.get(fileCoverage.path),
IS_HTML_CSS = fileCoverage.IS_HTML_CSS !== undefined || fileCoverage.IS_HTML_CSS !== null ? fileCoverage.IS_HTML_CSS : true,
{code, startIndex = 0} = jsChange({code: sourceText.split(/(?:\r?\n)|\r/), isHtmlVue, IS_HTML_CSS}),
count = 0
count = startIndex
fileCoverage.startIndex = startIndex
var structured = code.map(function (str) { count += 1; return { line: count, covered: null, text: new InsertionText(str, true) }; }),
var structured = code.map(function (str) {count += 1; return { line: count, covered: null, text: new InsertionText(str, true) }; }),
context;
// code, 'code' // 页面结构在structured之前删除html和css结构
// structured, 'structured' 行数注入
......@@ -467,20 +460,23 @@ Report.mix(HtmlReport, {
this.fillTemplate(node, templateData);
var headerTemplates = headerTemplate(templateData)
var headerTemplatePush= headerTemplates.replace('</style>', '</style><style>' + prettifyCss + baseCss + '</style>')
var isCommonTable = '<pre><table class="coverage">\n'
// !IS_HTML_CSS ? '<button onclick="isHtmlShow()" id="isHtmlCss" type="button" style="background: rgb(45, 140, 240); border: 0; position: fixed; color: #fff; top: 10px; right: 10px; width: 80px; height: 80px; border-radius: 50%; font-size: 12px; text-align: center; padding: 0; z-index: 9999">显示隐藏HTML、CSS</button><pre><table class="coverage">\n' : '<pre><table class="coverage">\n'
writer.write(headerTemplatePush);
writer.write('<pre><table class="coverage">\n');
writer.write(isCommonTable);
annotateLines(fileCoverage, structured);
//note: order is important, since statements typically result in spanning the whole line and doing branches late
//causes mismatched tags
annotateBranches(fileCoverage, structured);
annotateBranches(fileCoverage, structured, startIndex);
annotateFunctions(fileCoverage, structured);
annotateStatements(fileCoverage, structured);
structured.shift();
context = {
structured: structured,
maxLines: structured.length,
fileCoverage: fileCoverage
maxLines: structured.length + startIndex,
fileCoverage: fileCoverage,
startIndex: startIndex
};
writer.write(detailTemplate(context));
writer.write('</table></pre>\n');
......
{
"name": "ry-istanbul-web",
"version": "0.0.5",
"version": "0.0.6",
"description": "Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale",
"keywords": [
"coverage",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment