Commit 0b4aec06 by lxyang

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

parent 3f4dc584
...@@ -154,5 +154,13 @@ var addSorting = (function () { ...@@ -154,5 +154,13 @@ var addSorting = (function () {
enableUI(); enableUI();
}; };
})(); })();
window.onload = function () {
var isHtmlCss = document.getElementById('isHtmlCss')
if (isHtmlCss) {
isHtmlCss.addEventListener('click', isHtmlShow())
}
}
function isHtmlShow() {
console.log(111111)
}
window.addEventListener('load', addSorting); window.addEventListener('load', addSorting);
...@@ -122,11 +122,12 @@ handlebars.registerHelper('show_ignores', function (metrics) { ...@@ -122,11 +122,12 @@ handlebars.registerHelper('show_ignores', function (metrics) {
handlebars.registerHelper('show_lines', function (opts) { handlebars.registerHelper('show_lines', function (opts) {
var maxLines = Number(opts.fn(this)), var maxLines = Number(opts.fn(this)),
i, i,
array = []; array = [],
startIndex = Number(opts.data.root.startIndex) || 0;
for (i = 0; i < maxLines; i += 1) { for (i = startIndex; i < maxLines; i += 1) {
array[i] = i + 1; array[i] = i + 1;
} }
array = array.slice(startIndex, array.length)
return array.join('\n'); return array.join('\n');
}); });
...@@ -139,21 +140,13 @@ handlebars.registerHelper('show_line_execution_counts', function (context, opts) ...@@ -139,21 +140,13 @@ handlebars.registerHelper('show_line_execution_counts', function (context, opts)
lineNumber, lineNumber,
array = [], array = [],
covered, covered,
value = '', value = '';
newList = [] for (i = startIndex; i < maxLines; i += 1) {
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) {
var label = ''; var label = '';
lineNumber = i + 1; lineNumber = i + 1;
value = '&nbsp;'; value = '&nbsp;';
covered = 'neutral'; covered = 'neutral';
if (newList.includes(lineNumber)) { if (changeLists.includes(lineNumber)) {
label = '<span class="neutral-new" style="color: #57a3f3;">新增或变更语句</span> &nbsp;' label = '<span class="neutral-new" style="color: #57a3f3;">新增或变更语句</span> &nbsp;'
} }
if (lines.hasOwnProperty(lineNumber)) { if (lines.hasOwnProperty(lineNumber)) {
...@@ -209,19 +202,19 @@ function annotateLines(fileCoverage, structuredText) { ...@@ -209,19 +202,19 @@ function annotateLines(fileCoverage, structuredText) {
function annotateStatements(fileCoverage, structuredText) { function annotateStatements(fileCoverage, structuredText) {
var statementStats = fileCoverage.s, var statementStats = fileCoverage.s,
statementMeta = fileCoverage.statementMap; statementMeta = fileCoverage.statementMap,
Object.keys(statementStats).forEach(function (stName) { startIndex = fileCoverage.startIndex;
Object.keys(statementStats).forEach(function (stName, index) {
var count = statementStats[stName], var count = statementStats[stName],
meta = statementMeta[stName], meta = statementMeta[stName],
type = count > 0 ? 'yes' : 'no', type = count > 0 ? 'yes' : 'no',
startCol = meta.start.column, startCol = meta.start.column,
endCol = meta.end.column + 1, endCol = meta.end.column + 1,
startLine = meta.start.line, startLine = meta.start.line - startIndex,
endLine = meta.end.line, endLine = meta.end.line - startIndex,
openSpan = lt + 'span class="' + (meta.skip ? 'cstat-skip' : 'cstat-no') + '"' + title('statement not covered') + gt, openSpan = lt + 'span class="' + (meta.skip ? 'cstat-skip' : 'cstat-no') + '"' + title('statement not covered') + gt,
closeSpan = lt + '/span' + gt, closeSpan = lt + '/span' + gt,
text; text;
if (type === 'no' && structuredText[startLine] && structuredText[startLine].text) { if (type === 'no' && structuredText[startLine] && structuredText[startLine].text) {
if (endLine !== startLine) { if (endLine !== startLine) {
endLine = startLine; endLine = startLine;
...@@ -239,7 +232,8 @@ function annotateStatements(fileCoverage, structuredText) { ...@@ -239,7 +232,8 @@ function annotateStatements(fileCoverage, structuredText) {
function annotateFunctions(fileCoverage, structuredText) { function annotateFunctions(fileCoverage, structuredText) {
var fnStats = fileCoverage.f, var fnStats = fileCoverage.f,
fnMeta = fileCoverage.fnMap; fnMeta = fileCoverage.fnMap,
startIndex = fileCoverage.startIndex;
if (!fnStats) { return; } if (!fnStats) { return; }
Object.keys(fnStats).forEach(function (fName) { Object.keys(fnStats).forEach(function (fName) {
var count = fnStats[fName], var count = fnStats[fName],
...@@ -247,8 +241,8 @@ function annotateFunctions(fileCoverage, structuredText) { ...@@ -247,8 +241,8 @@ function annotateFunctions(fileCoverage, structuredText) {
type = count > 0 ? 'yes' : 'no', type = count > 0 ? 'yes' : 'no',
startCol = meta.loc.start.column, startCol = meta.loc.start.column,
endCol = meta.loc.end.column + 1, endCol = meta.loc.end.column + 1,
startLine = meta.loc.start.line, startLine = meta.loc.start.line - startIndex,
endLine = meta.loc.end.line, endLine = meta.loc.end.line - startIndex,
openSpan = lt + 'span class="' + (meta.skip ? 'fstat-skip' : 'fstat-no') + '"' + title('function not covered') + gt, openSpan = lt + 'span class="' + (meta.skip ? 'fstat-skip' : 'fstat-no') + '"' + title('function not covered') + gt,
closeSpan = lt + '/span' + gt, closeSpan = lt + '/span' + gt,
text; text;
...@@ -269,9 +263,9 @@ function annotateFunctions(fileCoverage, structuredText) { ...@@ -269,9 +263,9 @@ function annotateFunctions(fileCoverage, structuredText) {
function annotateBranches(fileCoverage, structuredText) { function annotateBranches(fileCoverage, structuredText) {
var branchStats = fileCoverage.b, var branchStats = fileCoverage.b,
branchMeta = fileCoverage.branchMap; branchMeta = fileCoverage.branchMap,
startIndex = fileCoverage.startIndex;
if (!branchStats) { return; } if (!branchStats) { return; }
Object.keys(branchStats).forEach(function (branchName) { Object.keys(branchStats).forEach(function (branchName) {
var branchArray = branchStats[branchName], var branchArray = branchStats[branchName],
sumCount = branchArray.reduce(function (p, n) { return p + n; }, 0), sumCount = branchArray.reduce(function (p, n) { return p + n; }, 0),
...@@ -295,11 +289,10 @@ function annotateBranches(fileCoverage, structuredText) { ...@@ -295,11 +289,10 @@ function annotateBranches(fileCoverage, structuredText) {
type = count > 0 ? 'yes' : 'no'; type = count > 0 ? 'yes' : 'no';
startCol = meta.start.column; startCol = meta.start.column;
endCol = meta.end.column + 1; endCol = meta.end.column + 1;
startLine = meta.start.line; startLine = meta.start.line - startIndex;
endLine = meta.end.line; endLine = meta.end.line - startIndex;
openSpan = lt + 'span class="branch-' + i + ' ' + (meta.skip ? 'cbranch-skip' : 'cbranch-no') + '"' + title('branch not covered') + gt; openSpan = lt + 'span class="branch-' + i + ' ' + (meta.skip ? 'cbranch-skip' : 'cbranch-no') + '"' + title('branch not covered') + gt;
closeSpan = lt + '/span' + gt; closeSpan = lt + '/span' + gt;
if (count === 0 && structuredText[startLine] && structuredText[startLine].text) { //skip branches taken if (count === 0 && structuredText[startLine] && structuredText[startLine].text) { //skip branches taken
if (endLine !== startLine) { if (endLine !== startLine) {
endLine = startLine; endLine = startLine;
...@@ -456,9 +449,9 @@ Report.mix(HtmlReport, { ...@@ -456,9 +449,9 @@ Report.mix(HtmlReport, {
fileCoverage.code.join('\n') + '\n' : sourceStore.get(fileCoverage.path), 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, 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}), {code, startIndex = 0} = jsChange({code: sourceText.split(/(?:\r?\n)|\r/), isHtmlVue, IS_HTML_CSS}),
count = 0 count = startIndex
fileCoverage.startIndex = 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; context;
// code, 'code' // 页面结构在structured之前删除html和css结构 // code, 'code' // 页面结构在structured之前删除html和css结构
// structured, 'structured' 行数注入 // structured, 'structured' 行数注入
...@@ -467,20 +460,23 @@ Report.mix(HtmlReport, { ...@@ -467,20 +460,23 @@ Report.mix(HtmlReport, {
this.fillTemplate(node, templateData); this.fillTemplate(node, templateData);
var headerTemplates = headerTemplate(templateData) var headerTemplates = headerTemplate(templateData)
var headerTemplatePush= headerTemplates.replace('</style>', '</style><style>' + prettifyCss + baseCss + '</style>') 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(headerTemplatePush);
writer.write('<pre><table class="coverage">\n'); writer.write(isCommonTable);
annotateLines(fileCoverage, structured); annotateLines(fileCoverage, structured);
//note: order is important, since statements typically result in spanning the whole line and doing branches late //note: order is important, since statements typically result in spanning the whole line and doing branches late
//causes mismatched tags //causes mismatched tags
annotateBranches(fileCoverage, structured); annotateBranches(fileCoverage, structured, startIndex);
annotateFunctions(fileCoverage, structured); annotateFunctions(fileCoverage, structured);
annotateStatements(fileCoverage, structured); annotateStatements(fileCoverage, structured);
structured.shift(); structured.shift();
context = { context = {
structured: structured, structured: structured,
maxLines: structured.length, maxLines: structured.length + startIndex,
fileCoverage: fileCoverage fileCoverage: fileCoverage,
startIndex: startIndex
}; };
writer.write(detailTemplate(context)); writer.write(detailTemplate(context));
writer.write('</table></pre>\n'); writer.write('</table></pre>\n');
......
{ {
"name": "ry-istanbul-web", "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", "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": [ "keywords": [
"coverage", "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