Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new report text-lcov, reports lcov to stdout #360

Merged
merged 1 commit into from May 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/report/text-lcov.js
@@ -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;
42 changes: 42 additions & 0 deletions test/cli/test-text-lcov-report.js
@@ -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();
}
};