index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. const fc = node.getFileCoverage();
  15. const writer = this.contentWriter;
  16. const functions = fc.f;
  17. const functionMap = fc.fnMap;
  18. const lines = fc.getLineCoverage();
  19. const branches = fc.b;
  20. const branchMap = fc.branchMap;
  21. const summary = node.getCoverageSummary();
  22. writer.println('TN:'); //no test name
  23. writer.println('SF:' + fc.path);
  24. Object.keys(functionMap).forEach(key => {
  25. const 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(functionMap).forEach(key => {
  31. const stats = functions[key];
  32. const meta = functionMap[key];
  33. writer.println('FNDA:' + [stats, meta.name].join(','));
  34. });
  35. Object.keys(lines).forEach(key => {
  36. const 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(key => {
  42. const branchArray = branches[key];
  43. const meta = branchMap[key];
  44. const line = meta.loc.start.line;
  45. let i = 0;
  46. branchArray.forEach(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;