index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright 2012-2015, Yahoo Inc.
  3. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  4. */
  5. "use strict";
  6. function LcovOnlyReport(opts) {
  7. this.file = opts.file || 'lcov.info';
  8. this.contentWriter = null;
  9. }
  10. LcovOnlyReport.prototype.onStart = function (root, context) {
  11. this.contentWriter = context.writer.writeFile(this.file);
  12. };
  13. LcovOnlyReport.prototype.onDetail = function (node) {
  14. var fc = node.getFileCoverage(),
  15. writer = this.contentWriter,
  16. functions = fc.f,
  17. functionMap = fc.fnMap,
  18. lines = fc.getLineCoverage(),
  19. branches = fc.b,
  20. branchMap = fc.branchMap,
  21. summary = node.getCoverageSummary();
  22. writer.println('TN:'); //no test name
  23. writer.println('SF:' + fc.path);
  24. Object.keys(functions).forEach(function (key) {
  25. var meta = functionMap[key];
  26. writer.println('FN:' + [meta.decl.start.line, meta.name].join(','));
  27. });
  28. writer.println('FNF:' + summary.functions.total);
  29. writer.println('FNH:' + summary.functions.covered);
  30. Object.keys(functions).forEach(function (key) {
  31. var stats = functions[key],
  32. meta = functionMap[key];
  33. writer.println('FNDA:' + [stats, meta.name].join(','));
  34. });
  35. Object.keys(lines).forEach(function (key) {
  36. var stat = lines[key];
  37. writer.println('DA:' + [key, stat].join(','));
  38. });
  39. writer.println('LF:' + summary.lines.total);
  40. writer.println('LH:' + summary.lines.covered);
  41. Object.keys(branches).forEach(function (key) {
  42. var branchArray = branches[key],
  43. meta = branchMap[key],
  44. line = meta.loc.start.line,
  45. i = 0;
  46. branchArray.forEach(function (b) {
  47. writer.println('BRDA:' + [line, key, i, b].join(','));
  48. i += 1;
  49. });
  50. });
  51. writer.println('BRF:' + summary.branches.total);
  52. writer.println('BRH:' + summary.branches.covered);
  53. writer.println('end_of_record');
  54. };
  55. LcovOnlyReport.prototype.onEnd = function () {
  56. this.contentWriter.close();
  57. };
  58. module.exports = LcovOnlyReport;