Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #360 from bcoe/text-lcov
next report text-lcov, reports lcov to stdout
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var LcovOnly = require('./lcovonly'), | ||
util = require('util'); | ||
|
||
/** | ||
* a `Report` implementation that produces an LCOV coverage and prints it | ||
* to standard out. | ||
* | ||
* Usage | ||
* ----- | ||
* | ||
* var report = require('istanbul').Report.create('text-lcov'); | ||
* | ||
* @class TextLcov | ||
* @module report | ||
* @extends LcovOnly | ||
* @constructor | ||
* @param {Object} opts optional | ||
* @param {String} [opts.log] the method used to log to console. | ||
*/ | ||
function TextLcov(opts) { | ||
var that = this; | ||
|
||
LcovOnly.call(this); | ||
|
||
this.opts = opts || {}; | ||
this.opts.log = this.opts.log || console.log; | ||
this.opts.writer = { | ||
println: function (ln) { | ||
that.opts.log(ln); | ||
} | ||
}; | ||
} | ||
|
||
TextLcov.TYPE = 'text-lcov'; | ||
util.inherits(TextLcov, LcovOnly); | ||
|
||
LcovOnly.super_.mix(TextLcov, { | ||
writeReport: function (collector) { | ||
var that = this, | ||
writer = this.opts.writer; | ||
|
||
collector.files().forEach(function (key) { | ||
that.writeFileCoverage(writer, collector.fileCoverageFor(key)); | ||
}); | ||
|
||
this.emit('done'); | ||
} | ||
}); | ||
|
||
module.exports = TextLcov; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*jslint nomen: true */ | ||
var path = require('path'), | ||
fs = require('fs'), | ||
mkdirp = require('mkdirp'), | ||
rimraf = require('rimraf'), | ||
helper = require('../cli-helper'), | ||
DIR = path.resolve(__dirname, 'sample-project'), | ||
OUTPUT_DIR = path.resolve(DIR, 'coverage'), | ||
COVER_COMMAND = 'cover', | ||
runCover = helper.runCommand.bind(null, COVER_COMMAND), | ||
Reporter = require('../../lib/report/text-lcov'), | ||
Collector = require('../../lib/collector'); | ||
|
||
module.exports = { | ||
setUp: function (cb) { | ||
rimraf.sync(OUTPUT_DIR); | ||
mkdirp.sync(OUTPUT_DIR); | ||
helper.resetOpts(); | ||
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) { | ||
cb(); | ||
}); | ||
}, | ||
tearDown: function (cb) { | ||
rimraf.sync(OUTPUT_DIR); | ||
cb(); | ||
}, | ||
"should print lcov.info to standard out": function (test) { | ||
var file = path.resolve(OUTPUT_DIR, 'coverage.json'), | ||
reporter = new Reporter({ | ||
log: function (ln) { | ||
output += ln; | ||
} | ||
}), | ||
collector = new Collector(), | ||
output = ''; | ||
|
||
collector.add(JSON.parse(fs.readFileSync(file, 'utf8'))); | ||
reporter.writeReport(collector, true); | ||
test.ok(output.match('TN:SF:'), 'failed to output report'); | ||
test.done(); | ||
} | ||
}; |