istanbul-reports
Advanced tools
Comparing version 3.0.0-alpha.3 to 3.0.0-alpha.4
@@ -6,2 +6,13 @@ # Change Log | ||
# [3.0.0-alpha.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-reports@3.0.0-alpha.3...istanbul-reports@3.0.0-alpha.4) (2019-11-18) | ||
### Bug Fixes | ||
* Remove handlebars ([#503](https://github.com/istanbuljs/istanbuljs/issues/503)) ([aa8ae7f](https://github.com/istanbuljs/istanbuljs/commit/aa8ae7fe42ef9c8aeaa193309bafb22ad725bc3d)), closes [#476](https://github.com/istanbuljs/istanbuljs/issues/476) | ||
# [3.0.0-alpha.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-reports@3.0.0-alpha.2...istanbul-reports@3.0.0-alpha.3) (2019-10-19) | ||
@@ -8,0 +19,0 @@ |
@@ -269,4 +269,2 @@ /* | ||
module.exports = { | ||
annotateSourceCode | ||
}; | ||
module.exports = annotateSourceCode; |
@@ -8,25 +8,127 @@ 'use strict'; | ||
const path = require('path'); | ||
const handlebars = require('handlebars').create(); | ||
const html = require('html-escaper'); | ||
const { ReportBase } = require('istanbul-lib-report'); | ||
const annotator = require('./annotator'); | ||
const helpers = require('./helpers'); | ||
const templateFor = function(name) { | ||
return handlebars.compile( | ||
fs.readFileSync( | ||
path.resolve(__dirname, 'templates', name + '.txt'), | ||
'utf8' | ||
) | ||
); | ||
}; | ||
const headerTemplate = templateFor('head'); | ||
const footerTemplate = templateFor('foot'); | ||
const detailTemplate = handlebars.compile( | ||
[ | ||
function htmlHead(details) { | ||
return ` | ||
<head> | ||
<title>Code coverage report for ${html.escape(details.entity)}</title> | ||
<meta charset="utf-8" /> | ||
<link rel="stylesheet" href="${html.escape(details.prettify.css)}" /> | ||
<link rel="stylesheet" href="${html.escape(details.base.css)}" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style type='text/css'> | ||
.coverage-summary .sorter { | ||
background-image: url(${html.escape(details.sorter.image)}); | ||
} | ||
</style> | ||
</head> | ||
`; | ||
} | ||
function headerTemplate(details) { | ||
function metricsTemplate({ pct, covered, total }, kind) { | ||
return ` | ||
<div class='fl pad1y space-right2'> | ||
<span class="strong">${pct}% </span> | ||
<span class="quiet">${kind}</span> | ||
<span class='fraction'>${covered}/${total}</span> | ||
</div> | ||
`; | ||
} | ||
function skipTemplate(metrics) { | ||
const statements = metrics.statements.skipped; | ||
const branches = metrics.branches.skipped; | ||
const functions = metrics.functions.skipped; | ||
const countLabel = (c, label, plural) => | ||
c === 0 ? [] : `${c} ${label}${c === 1 ? '' : plural}`; | ||
const skips = [].concat( | ||
countLabel(statements, 'statement', 's'), | ||
countLabel(functions, 'function', 's'), | ||
countLabel(branches, 'branch', 'es') | ||
); | ||
if (skips.length === 0) { | ||
return ''; | ||
} | ||
return ` | ||
<div class='fl pad1y'> | ||
<span class="strong">${skips.join(', ')}</span> | ||
<span class="quiet">Ignored</span> | ||
</div> | ||
`; | ||
} | ||
return ` | ||
<!doctype html> | ||
<html lang="en"> | ||
${htmlHead(details)} | ||
<body> | ||
<div class='wrapper'> | ||
<div class='pad1'> | ||
<h1>${details.pathHtml}</h1> | ||
<div class='clearfix'> | ||
${metricsTemplate(details.metrics.statements, 'Statements')} | ||
${metricsTemplate(details.metrics.branches, 'Branches')} | ||
${metricsTemplate(details.metrics.functions, 'Functions')} | ||
${metricsTemplate(details.metrics.lines, 'Lines')} | ||
${skipTemplate(details.metrics)} | ||
</div> | ||
<p class="quiet"> | ||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block. | ||
</p> | ||
</div> | ||
<div class='status-line ${details.reportClass}'></div> | ||
`; | ||
} | ||
function footerTemplate(details) { | ||
return ` | ||
<div class='push'></div><!-- for sticky footer --> | ||
</div><!-- /wrapper --> | ||
<div class='footer quiet pad2 space-top1 center small'> | ||
Code coverage generated by | ||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a> | ||
at ${html.escape(details.datetime)} | ||
</div> | ||
</div> | ||
<script src="${html.escape(details.prettify.js)}"></script> | ||
<script> | ||
window.onload = function () { | ||
prettyPrint(); | ||
}; | ||
</script> | ||
<script src="${html.escape(details.sorter.js)}"></script> | ||
<script src="${html.escape(details.blockNavigation.js)}"></script> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
function detailTemplate(data) { | ||
const lineNumbers = new Array(data.maxLines).fill().map((_, i) => i + 1); | ||
const lineLink = num => | ||
`<a name='L${num}'></a><a href='#L${num}'>${num}</a>`; | ||
const lineCount = line => | ||
`<span class="cline-any cline-${line.covered}">${line.hits}</span>`; | ||
/* This is rendered in a `<pre>`, need control of all whitespace. */ | ||
return [ | ||
'<tr>', | ||
'<td class="line-count quiet">{{#show_lines}}{{maxLines}}{{/show_lines}}</td>', | ||
'<td class="line-coverage quiet">{{#show_line_execution_counts lineCoverage}}{{maxLines}}{{/show_line_execution_counts}}</td>', | ||
'<td class="text"><pre class="prettyprint lang-js">{{#show_code annotatedCode}}{{/show_code}}</pre></td>', | ||
'</tr>\n' | ||
].join('') | ||
); | ||
`<td class="line-count quiet">${lineNumbers | ||
.map(lineLink) | ||
.join('\n')}</td>`, | ||
`<td class="line-coverage quiet">${data.lineCoverage | ||
.map(lineCount) | ||
.join('\n')}</td>`, | ||
`<td class="text"><pre class="prettyprint lang-js">${data.annotatedCode.join( | ||
'\n' | ||
)}</pre></td>`, | ||
'</tr>' | ||
].join(''); | ||
} | ||
const summaryTableHeader = [ | ||
@@ -51,18 +153,56 @@ '<div class="pad1">', | ||
].join('\n'); | ||
const summaryLineTemplate = handlebars.compile( | ||
[ | ||
'<tr>', | ||
'<td class="file {{reportClasses.statements}}" data-value="{{file}}"><a href="{{output}}">{{file}}</a></td>', | ||
'<td data-value="{{metrics.statements.pct}}" class="pic {{reportClasses.statements}}"><div class="chart">{{#show_picture}}{{metrics.statements.pct}}{{/show_picture}}</div></td>', | ||
'<td data-value="{{metrics.statements.pct}}" class="pct {{reportClasses.statements}}">{{metrics.statements.pct}}%</td>', | ||
'<td data-value="{{metrics.statements.total}}" class="abs {{reportClasses.statements}}">{{metrics.statements.covered}}/{{metrics.statements.total}}</td>', | ||
'<td data-value="{{metrics.branches.pct}}" class="pct {{reportClasses.branches}}">{{metrics.branches.pct}}%</td>', | ||
'<td data-value="{{metrics.branches.total}}" class="abs {{reportClasses.branches}}">{{metrics.branches.covered}}/{{metrics.branches.total}}</td>', | ||
'<td data-value="{{metrics.functions.pct}}" class="pct {{reportClasses.functions}}">{{metrics.functions.pct}}%</td>', | ||
'<td data-value="{{metrics.functions.total}}" class="abs {{reportClasses.functions}}">{{metrics.functions.covered}}/{{metrics.functions.total}}</td>', | ||
'<td data-value="{{metrics.lines.pct}}" class="pct {{reportClasses.lines}}">{{metrics.lines.pct}}%</td>', | ||
'<td data-value="{{metrics.lines.total}}" class="abs {{reportClasses.lines}}">{{metrics.lines.covered}}/{{metrics.lines.total}}</td>', | ||
'</tr>\n' | ||
].join('\n\t') | ||
); | ||
function summaryLineTemplate(details) { | ||
const { reportClasses, metrics, file, output } = details; | ||
const percentGraph = pct => { | ||
if (!isFinite(pct)) { | ||
return ''; | ||
} | ||
const cls = ['cover-fill']; | ||
if (pct === 100) { | ||
cls.push('cover-full'); | ||
} | ||
pct = Math.floor(pct); | ||
return [ | ||
`<div class="${cls.join(' ')}" style="width: ${pct}%"></div>`, | ||
`<div class="cover-empty" style="width: ${100 - pct}%"></div>` | ||
].join(''); | ||
}; | ||
const summaryType = (type, showGraph = false) => { | ||
const info = metrics[type]; | ||
const reportClass = reportClasses[type]; | ||
const result = [ | ||
`<td data-value="${info.pct}" class="pct ${reportClass}">${info.pct}%</td>`, | ||
`<td data-value="${info.total}" class="abs ${reportClass}">${info.covered}/${info.total}</td>` | ||
]; | ||
if (showGraph) { | ||
result.unshift( | ||
`<td data-value="${info.pct}" class="pic ${reportClass}">`, | ||
`<div class="chart">${percentGraph(info.pct)}</div>`, | ||
`</td>` | ||
); | ||
} | ||
return result; | ||
}; | ||
return [] | ||
.concat( | ||
'<tr>', | ||
`<td class="file ${ | ||
reportClasses.statements | ||
}" data-value="${html.escape(file)}"><a href="${html.escape( | ||
output | ||
)}">${html.escape(file)}</a></td>`, | ||
summaryType('statements', true), | ||
summaryType('branches'), | ||
summaryType('functions'), | ||
summaryType('lines'), | ||
'</tr>\n' | ||
) | ||
.join('\n\t'); | ||
} | ||
const summaryTableFooter = ['</tbody>', '</table>', '</div>'].join('\n'); | ||
@@ -76,4 +216,2 @@ const emptyClasses = { | ||
helpers.registerHelpers(handlebars); | ||
const standardLinkMapper = { | ||
@@ -270,7 +408,3 @@ getPath(node) { | ||
cw.write('<pre><table class="coverage">\n'); | ||
cw.write( | ||
detailTemplate( | ||
annotator.annotateSourceCode(node.getFileCoverage(), context) | ||
) | ||
); | ||
cw.write(detailTemplate(annotator(node.getFileCoverage(), context))); | ||
cw.write('</table></pre>\n'); | ||
@@ -277,0 +411,0 @@ cw.write(footerTemplate(templateData)); |
{ | ||
"name": "istanbul-reports", | ||
"version": "3.0.0-alpha.3", | ||
"version": "3.0.0-alpha.4", | ||
"description": "istanbul reports", | ||
@@ -17,3 +17,3 @@ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>", | ||
"dependencies": { | ||
"handlebars": "^4.4.2", | ||
"html-escaper": "^2.0.0", | ||
"istanbul-lib-report": "^3.0.0-alpha.1" | ||
@@ -61,3 +61,3 @@ }, | ||
}, | ||
"gitHead": "70f48b7e6b60d17b8e2b5a03388a004deb6b8785" | ||
"gitHead": "c69ce0cce10c1fb394b55ef0169e44e70f14ad24" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3765
280379
40
+ Addedhtml-escaper@^2.0.0
+ Addedhtml-escaper@2.0.2(transitive)
- Removedhandlebars@^4.4.2
- Removedhandlebars@4.7.8(transitive)
- Removedminimist@1.2.8(transitive)
- Removedneo-async@2.6.2(transitive)
- Removedsource-map@0.6.1(transitive)
- Removeduglify-js@3.19.3(transitive)
- Removedwordwrap@1.0.0(transitive)