Permalink
Browse files

Fix: #14 - Add lcov as supported format

  • Loading branch information...
athieriot committed May 22, 2013
1 parent 1495a20 commit d9a0d54051f38504f8c0bf162d3d47ce65126360
Showing with 33 additions and 2 deletions.
  1. +1 −1 README.md
  2. +1 −1 bin/covershot
  3. +1 −0 lib/format/index.js
  4. +30 −0 lib/format/lcov.js
View
@@ -36,7 +36,7 @@ npm test
- generate a coverage report
```bash
-./node_modules/covershot/bin/covershot covershot/data -f [html|clover|json]
+./node_modules/covershot/bin/covershot covershot/data -f [html|clover|json|lcov]
```
## Configuration
View
@@ -9,7 +9,7 @@ var argv = optimist
.options('f', {
alias: 'format',
default: 'html',
- describe: 'Desired output format. [html, json, plain]'
+ describe: 'Desired output format. [html, json, clover, lcov]'
})
.options('m', {
alias: 'map',
View
@@ -1,2 +1,3 @@
exports.html = require('./html');
exports.json = require('./json');
+exports.lcov = require('./lcov');
View
@@ -0,0 +1,30 @@
+var fs = require('fs');
+var path = require('path');
+var util = require('util');
+var fsutil = require('../fsutil');
+
+exports.report = function (coverageMap, outputDir, callback) {
+ var output = ""
+
+ coverageMap.files.forEach(function (file) {
+ output += "SF:lib/" + file.filename + "\n"
+
+ for (num in file.source) {
+ coverage = file.source[num].coverage
+ if (coverage !== "") {
+ output += "DA:" + num + "," + coverage + "\n"
+ }
+ }
+
+ output += "end_of_record\n"
+ });
+
+ try {
+ outputDir = outputDir || 'coverage';
+ fsutil.mkdirSync(outputDir);
+ fs.writeFile(path.join(outputDir, 'coverage.lcov'), output, callback);
+ } catch (error) {
+ console.log("Error: Unable to write to file " + outputDir + "/coverage.lcov", error);
+ return;
+ }
+};

0 comments on commit d9a0d54

Please sign in to comment.