| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
var path = require('path'), |
| 7 |
util = require('util'), |
| 8 |
mkdirp = require('mkdirp'), |
| 9 |
fs = require('fs'), |
| 10 |
utils = require('../object-utils'), |
| 11 |
Report = require('./index'); |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
function TeamcityReport(opts) { |
| 30 |
Report.call(this); |
| 31 |
opts = opts || {}; |
| 32 |
this.dir = opts.dir || process.cwd(); |
| 33 |
this.file = opts.file; |
| 34 |
this.blockName = opts.blockName || this.getDefaultConfig().blockName; |
| 35 |
} |
| 36 |
|
| 37 |
TeamcityReport.TYPE = 'teamcity'; |
| 38 |
util.inherits(TeamcityReport, Report); |
| 39 |
|
| 40 |
function lineForKey(value, teamcityVar) { |
| 41 |
return '##teamcity[buildStatisticValue key=\'' + teamcityVar + '\' value=\'' + value + '\']'; |
| 42 |
} |
| 43 |
|
| 44 |
Report.mix(TeamcityReport, { |
| 45 |
synopsis: function () { |
| 46 |
return 'report with system messages that can be interpreted with TeamCity'; |
| 47 |
}, |
| 48 |
getDefaultConfig: function () { |
| 49 |
return { file: null , blockName: 'Code Coverage Summary'}; |
| 50 |
}, |
| 51 |
writeReport: function (collector ) { |
| 52 |
var summaries = [], |
| 53 |
finalSummary, |
| 54 |
lines = [], |
| 55 |
text; |
| 56 |
|
| 57 |
collector.files().forEach(function (file) { |
| 58 |
summaries.push(utils.summarizeFileCoverage(collector.fileCoverageFor(file))); |
| 59 |
}); |
| 60 |
|
| 61 |
finalSummary = utils.mergeSummaryObjects.apply(null, summaries); |
| 62 |
|
| 63 |
lines.push(''); |
| 64 |
lines.push('##teamcity[blockOpened name=\''+ this.blockName +'\']'); |
| 65 |
|
| 66 |
|
| 67 |
lines.push(lineForKey(finalSummary.statements.pct, 'CodeCoverageB')); |
| 68 |
|
| 69 |
|
| 70 |
lines.push(lineForKey(finalSummary.functions.covered, 'CodeCoverageAbsMCovered')); |
| 71 |
lines.push(lineForKey(finalSummary.functions.total, 'CodeCoverageAbsMTotal')); |
| 72 |
lines.push(lineForKey(finalSummary.functions.pct, 'CodeCoverageM')); |
| 73 |
|
| 74 |
|
| 75 |
lines.push(lineForKey(finalSummary.lines.covered, 'CodeCoverageAbsLCovered')); |
| 76 |
lines.push(lineForKey(finalSummary.lines.total, 'CodeCoverageAbsLTotal')); |
| 77 |
lines.push(lineForKey(finalSummary.lines.pct, 'CodeCoverageL')); |
| 78 |
|
| 79 |
lines.push('##teamcity[blockClosed name=\''+ this.blockName +'\']'); |
| 80 |
|
| 81 |
text = lines.join('\n'); |
| 82 |
if (this.file) { |
| 83 |
mkdirp.sync(this.dir); |
| 84 |
fs.writeFileSync(path.join(this.dir, this.file), text, 'utf8'); |
| 85 |
} else { |
| 86 |
console.log(text); |
| 87 |
} |
| 88 |
this.emit('done'); |
| 89 |
} |
| 90 |
}); |
| 91 |
|
| 92 |
module.exports = TeamcityReport; |