diff --git a/bin/vows b/bin/vows index 4bac746..cd36fc6 100755 --- a/bin/vows +++ b/bin/vows @@ -59,6 +59,7 @@ var help = [ " --cover-plain Print plain coverage map if detected", " --cover-html Write coverage map to \"coverage.html\"", " --cover-json Write unified coverage map to \"coverage.json\"", + " --cover-xml Write coverage map to \"coverage.xml\" in Emma xml", " --no-color Don't use terminal colors", " --version Show version", " -h, --help You're staring at it" @@ -134,6 +135,10 @@ while (arg = argv.shift()) { options.coverage = true; _coverage = require('../lib/vows/coverage/report-json'); break; + case 'cover-xml': + options.coverage = true; + _coverage = require('../lib/vows/coverage/report-xml'); + break; case 'verbose': case 'v': options.verbose = true; diff --git a/lib/vows/coverage/report-xml.js b/lib/vows/coverage/report-xml.js new file mode 100644 index 0000000..d816592 --- /dev/null +++ b/lib/vows/coverage/report-xml.js @@ -0,0 +1,81 @@ +var util = require('util'), + file = require('./file'); + +this.name = 'coverage-report-xml'; + +this.report = function (coverageMap) { + var all = { + xml: '', + packages: 0, + files: 0, + lines: 0, + hits: 0 + }, + data = {}; + + // group data by path + for (var filename in coverageMap) { + if (coverageMap.hasOwnProperty(filename)) { + var pkg = (filename.indexOf('/') > 0) + ? filename.substr(0, filename.lastIndexOf('/')) + : filename; + if (!data[pkg]) { + data[pkg] = {}; + } + data[pkg][ (filename.indexOf('/')) + ? filename.substr(filename.lastIndexOf('/') + 1, filename.length) + : filename ] + = file.coverage(filename, coverageMap[filename]); + } + } + + // generate groups xml-fragment + for (var pkg in data) { + if (data.hasOwnProperty(pkg)) { + var pkgStat = { + xml: '', + files: 0, + lines: 0, + hits: 0 + }; + + all.xml += '\t\n'; + + for (var filename in data[pkg]) { + if (data[pkg].hasOwnProperty(filename)) { + pkgStat.files += 1; + pkgStat.lines += data[pkg][filename].sloc; + pkgStat.hits += data[pkg][filename].hits; + + pkgStat.xml += '\t\t\n' + + '\t\t\t\n' + + '\t\t\n'; + } + } + + all.packages += 1; + all.files += pkgStat.files; + all.lines += pkgStat.lines; + all.hits += pkgStat.hits; + + all.xml += '\t\t\n' + + pkgStat.xml + + '\t\n'; + } + } + + all.xml = '\n' + + '\n\n' + + '\t\n' + + '\t\n' + + '\t\n' + + '\t\n' + + '\t\n' + + '\n\n' + + '\n' + + '\t\n' + + all.xml + + '\n\n\n'; + + util.print(all.xml); +}; \ No newline at end of file