istanbul-reports
Advanced tools
Comparing version 2.2.3 to 2.2.4
@@ -6,2 +6,10 @@ # Change Log | ||
## [2.2.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-reports@2.2.3...istanbul-reports@2.2.4) (2019-04-24) | ||
**Note:** Version bump only for package istanbul-reports | ||
## [2.2.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-reports@2.2.2...istanbul-reports@2.2.3) (2019-04-17) | ||
@@ -8,0 +16,0 @@ |
@@ -103,167 +103,173 @@ /* | ||
function getBreadcrumbHtml(node, linkMapper) { | ||
let parent = node.getParent(); | ||
const nodePath = []; | ||
function fixPct(metrics) { | ||
Object.keys(emptyClasses).forEach(key => { | ||
metrics[key].pct = 0; | ||
}); | ||
return metrics; | ||
} | ||
while (parent) { | ||
nodePath.push(parent); | ||
parent = parent.getParent(); | ||
class HtmlReport { | ||
constructor(opts) { | ||
this.verbose = opts.verbose; | ||
this.linkMapper = opts.linkMapper || standardLinkMapper; | ||
this.subdir = opts.subdir || ''; | ||
this.date = Date(); | ||
this.skipEmpty = opts.skipEmpty; | ||
} | ||
const linkPath = nodePath.map(ancestor => { | ||
const target = linkMapper.relativePath(node, ancestor); | ||
const name = ancestor.getRelativeName() || 'All files'; | ||
return '<a href="' + target + '">' + name + '</a>'; | ||
}); | ||
getBreadcrumbHtml(node) { | ||
let parent = node.getParent(); | ||
const nodePath = []; | ||
linkPath.reverse(); | ||
return linkPath.length > 0 | ||
? linkPath.join(' / ') + ' ' + node.getRelativeName() | ||
: 'All files'; | ||
} | ||
while (parent) { | ||
nodePath.push(parent); | ||
parent = parent.getParent(); | ||
} | ||
function fillTemplate(node, templateData, linkMapper, context) { | ||
const summary = node.getCoverageSummary(); | ||
templateData.entity = node.getQualifiedName() || 'All files'; | ||
templateData.metrics = summary; | ||
templateData.reportClass = context.classForPercent( | ||
'statements', | ||
summary.statements.pct | ||
); | ||
templateData.pathHtml = getBreadcrumbHtml(node, linkMapper); | ||
templateData.base = { | ||
css: linkMapper.assetPath(node, 'base.css') | ||
}; | ||
templateData.sorter = { | ||
js: linkMapper.assetPath(node, 'sorter.js'), | ||
image: linkMapper.assetPath(node, 'sort-arrow-sprite.png') | ||
}; | ||
templateData.blockNavigation = { | ||
js: linkMapper.assetPath(node, 'block-navigation.js') | ||
}; | ||
templateData.prettify = { | ||
js: linkMapper.assetPath(node, 'prettify.js'), | ||
css: linkMapper.assetPath(node, 'prettify.css') | ||
}; | ||
} | ||
const linkPath = nodePath.map(ancestor => { | ||
const target = this.linkMapper.relativePath(node, ancestor); | ||
const name = ancestor.getRelativeName() || 'All files'; | ||
return '<a href="' + target + '">' + name + '</a>'; | ||
}); | ||
function HtmlReport(opts) { | ||
this.verbose = opts.verbose; | ||
this.linkMapper = opts.linkMapper || standardLinkMapper; | ||
this.subdir = opts.subdir || ''; | ||
this.date = Date(); | ||
this.skipEmpty = opts.skipEmpty; | ||
} | ||
linkPath.reverse(); | ||
return linkPath.length > 0 | ||
? linkPath.join(' / ') + ' ' + node.getRelativeName() | ||
: 'All files'; | ||
} | ||
HtmlReport.prototype.getTemplateData = function() { | ||
return { datetime: this.date }; | ||
}; | ||
fillTemplate(node, templateData, context) { | ||
const linkMapper = this.linkMapper; | ||
const summary = node.getCoverageSummary(); | ||
templateData.entity = node.getQualifiedName() || 'All files'; | ||
templateData.metrics = summary; | ||
templateData.reportClass = context.classForPercent( | ||
'statements', | ||
summary.statements.pct | ||
); | ||
templateData.pathHtml = this.getBreadcrumbHtml(node); | ||
templateData.base = { | ||
css: linkMapper.assetPath(node, 'base.css') | ||
}; | ||
templateData.sorter = { | ||
js: linkMapper.assetPath(node, 'sorter.js'), | ||
image: linkMapper.assetPath(node, 'sort-arrow-sprite.png') | ||
}; | ||
templateData.blockNavigation = { | ||
js: linkMapper.assetPath(node, 'block-navigation.js') | ||
}; | ||
templateData.prettify = { | ||
js: linkMapper.assetPath(node, 'prettify.js'), | ||
css: linkMapper.assetPath(node, 'prettify.css') | ||
}; | ||
} | ||
HtmlReport.prototype.getWriter = function(context) { | ||
if (!this.subdir) { | ||
return context.writer; | ||
getTemplateData() { | ||
return { datetime: this.date }; | ||
} | ||
return context.writer.writerForDir(this.subdir); | ||
}; | ||
HtmlReport.prototype.onStart = function(root, context) { | ||
const assetHeaders = { | ||
'.js': '/* eslint-disable */\n' | ||
}; | ||
getWriter(context) { | ||
if (!this.subdir) { | ||
return context.writer; | ||
} | ||
return context.writer.writerForDir(this.subdir); | ||
} | ||
['.', 'vendor'].forEach(subdir => { | ||
const writer = this.getWriter(context); | ||
const srcDir = path.resolve(__dirname, 'assets', subdir); | ||
fs.readdirSync(srcDir).forEach(f => { | ||
const resolvedSource = path.resolve(srcDir, f); | ||
const resolvedDestination = '.'; | ||
const stat = fs.statSync(resolvedSource); | ||
let dest; | ||
onStart(root, context) { | ||
const assetHeaders = { | ||
'.js': '/* eslint-disable */\n' | ||
}; | ||
if (stat.isFile()) { | ||
dest = resolvedDestination + '/' + f; | ||
if (this.verbose) { | ||
console.log('Write asset: ' + dest); | ||
['.', 'vendor'].forEach(subdir => { | ||
const writer = this.getWriter(context); | ||
const srcDir = path.resolve(__dirname, 'assets', subdir); | ||
fs.readdirSync(srcDir).forEach(f => { | ||
const resolvedSource = path.resolve(srcDir, f); | ||
const resolvedDestination = '.'; | ||
const stat = fs.statSync(resolvedSource); | ||
let dest; | ||
if (stat.isFile()) { | ||
dest = resolvedDestination + '/' + f; | ||
if (this.verbose) { | ||
console.log('Write asset: ' + dest); | ||
} | ||
writer.copyFile( | ||
resolvedSource, | ||
dest, | ||
assetHeaders[path.extname(f)] | ||
); | ||
} | ||
writer.copyFile( | ||
resolvedSource, | ||
dest, | ||
assetHeaders[path.extname(f)] | ||
); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
function fixPct(metrics) { | ||
Object.keys(emptyClasses).forEach(key => { | ||
metrics[key].pct = 0; | ||
}); | ||
return metrics; | ||
} | ||
onSummary(node, context) { | ||
const linkMapper = this.linkMapper; | ||
const templateData = this.getTemplateData(); | ||
const children = node.getChildren(); | ||
const skipEmpty = this.skipEmpty; | ||
HtmlReport.prototype.onSummary = function(node, context) { | ||
const linkMapper = this.linkMapper; | ||
const templateData = this.getTemplateData(); | ||
const children = node.getChildren(); | ||
const skipEmpty = this.skipEmpty; | ||
this.fillTemplate(node, templateData, context); | ||
const cw = this.getWriter(context).writeFile(linkMapper.getPath(node)); | ||
cw.write(headerTemplate(templateData)); | ||
cw.write(summaryTableHeader); | ||
children.forEach(child => { | ||
const metrics = child.getCoverageSummary(); | ||
const isEmpty = metrics.isEmpty(); | ||
if (skipEmpty && isEmpty) { | ||
return; | ||
} | ||
const reportClasses = isEmpty | ||
? emptyClasses | ||
: { | ||
statements: context.classForPercent( | ||
'statements', | ||
metrics.statements.pct | ||
), | ||
lines: context.classForPercent( | ||
'lines', | ||
metrics.lines.pct | ||
), | ||
functions: context.classForPercent( | ||
'functions', | ||
metrics.functions.pct | ||
), | ||
branches: context.classForPercent( | ||
'branches', | ||
metrics.branches.pct | ||
) | ||
}; | ||
const data = { | ||
metrics: isEmpty ? fixPct(metrics) : metrics, | ||
reportClasses, | ||
file: child.getRelativeName(), | ||
output: linkMapper.relativePath(node, child) | ||
}; | ||
cw.write(summaryLineTemplate(data) + '\n'); | ||
}); | ||
cw.write(summaryTableFooter); | ||
cw.write(footerTemplate(templateData)); | ||
cw.close(); | ||
} | ||
fillTemplate(node, templateData, linkMapper, context); | ||
const cw = this.getWriter(context).writeFile(linkMapper.getPath(node)); | ||
cw.write(headerTemplate(templateData)); | ||
cw.write(summaryTableHeader); | ||
children.forEach(child => { | ||
const metrics = child.getCoverageSummary(); | ||
const isEmpty = metrics.isEmpty(); | ||
if (skipEmpty && isEmpty) { | ||
return; | ||
} | ||
const reportClasses = isEmpty | ||
? emptyClasses | ||
: { | ||
statements: context.classForPercent( | ||
'statements', | ||
metrics.statements.pct | ||
), | ||
lines: context.classForPercent('lines', metrics.lines.pct), | ||
functions: context.classForPercent( | ||
'functions', | ||
metrics.functions.pct | ||
), | ||
branches: context.classForPercent( | ||
'branches', | ||
metrics.branches.pct | ||
) | ||
}; | ||
const data = { | ||
metrics: isEmpty ? fixPct(metrics) : metrics, | ||
reportClasses, | ||
file: child.getRelativeName(), | ||
output: linkMapper.relativePath(node, child) | ||
}; | ||
cw.write(summaryLineTemplate(data) + '\n'); | ||
}); | ||
cw.write(summaryTableFooter); | ||
cw.write(footerTemplate(templateData)); | ||
cw.close(); | ||
}; | ||
onDetail(node, context) { | ||
const linkMapper = this.linkMapper; | ||
const templateData = this.getTemplateData(); | ||
HtmlReport.prototype.onDetail = function(node, context) { | ||
const linkMapper = this.linkMapper; | ||
const templateData = this.getTemplateData(); | ||
this.fillTemplate(node, templateData, context); | ||
const cw = this.getWriter(context).writeFile(linkMapper.getPath(node)); | ||
cw.write(headerTemplate(templateData)); | ||
cw.write('<pre><table class="coverage">\n'); | ||
cw.write( | ||
detailTemplate( | ||
annotator.annotateSourceCode(node.getFileCoverage(), context) | ||
) | ||
); | ||
cw.write('</table></pre>\n'); | ||
cw.write(footerTemplate(templateData)); | ||
cw.close(); | ||
} | ||
} | ||
fillTemplate(node, templateData, linkMapper, context); | ||
const cw = this.getWriter(context).writeFile(linkMapper.getPath(node)); | ||
cw.write(headerTemplate(templateData)); | ||
cw.write('<pre><table class="coverage">\n'); | ||
cw.write( | ||
detailTemplate( | ||
annotator.annotateSourceCode(node.getFileCoverage(), context) | ||
) | ||
); | ||
cw.write('</table></pre>\n'); | ||
cw.write(footerTemplate(templateData)); | ||
cw.close(); | ||
}; | ||
module.exports = HtmlReport; |
{ | ||
"name": "istanbul-reports", | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"description": "istanbul reports", | ||
@@ -15,7 +15,7 @@ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>", | ||
"dependencies": { | ||
"handlebars": "^4.1.0" | ||
"handlebars": "^4.1.2" | ||
}, | ||
"devDependencies": { | ||
"istanbul-lib-coverage": "^2.0.4", | ||
"istanbul-lib-report": "^2.0.7" | ||
"istanbul-lib-coverage": "^2.0.5", | ||
"istanbul-lib-report": "^2.0.8" | ||
}, | ||
@@ -38,3 +38,3 @@ "license": "BSD-3-Clause", | ||
}, | ||
"gitHead": "d98bbced044b2416f488bb1bbd37efefd1202a52" | ||
"gitHead": "90e60cc47833bb780680f916488ca24f0be36ca2" | ||
} |
@@ -1,3 +0,2 @@ | ||
istanbul-reports | ||
================ | ||
# istanbul-reports | ||
@@ -7,9 +6,9 @@ [![Greenkeeper badge](https://badges.greenkeeper.io/istanbuljs/istanbul-reports.svg)](https://greenkeeper.io/) | ||
* node.getRelativeName | ||
- node.getRelativeName | ||
* context.getSource(filePath) | ||
* context.classForPercent(type, percent) | ||
* context.console.colorize(str, class) | ||
* context.writer | ||
* context.console.write | ||
* context.console.println | ||
- context.getSource(filePath) | ||
- context.classForPercent(type, percent) | ||
- context.console.colorize(str, class) | ||
- context.writer | ||
- context.console.write | ||
- context.console.println |
95033
1984
14
+ Addeduglify-js@3.17.4(transitive)
- Removeduglify-js@3.18.0(transitive)
Updatedhandlebars@^4.1.2