index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 TeamcityReport(opts) {
  7. opts = opts || {};
  8. this.file = opts.file || null;
  9. this.blockName = opts.blockName || 'Code Coverage Summary';
  10. }
  11. function lineForKey(value, teamcityVar) {
  12. return (
  13. "##teamcity[buildStatisticValue key='" +
  14. teamcityVar +
  15. "' value='" +
  16. value +
  17. "']"
  18. );
  19. }
  20. TeamcityReport.prototype.onStart = function(node, context) {
  21. const metrics = node.getCoverageSummary();
  22. const cw = context.writer.writeFile(this.file);
  23. cw.println('');
  24. cw.println("##teamcity[blockOpened name='" + this.blockName + "']");
  25. //Statements Covered
  26. cw.println(
  27. lineForKey(metrics.statements.covered, 'CodeCoverageAbsBCovered')
  28. );
  29. cw.println(lineForKey(metrics.statements.total, 'CodeCoverageAbsBTotal'));
  30. //Branches Covered
  31. cw.println(lineForKey(metrics.branches.covered, 'CodeCoverageAbsRCovered'));
  32. cw.println(lineForKey(metrics.branches.total, 'CodeCoverageAbsRTotal'));
  33. //Functions Covered
  34. cw.println(
  35. lineForKey(metrics.functions.covered, 'CodeCoverageAbsMCovered')
  36. );
  37. cw.println(lineForKey(metrics.functions.total, 'CodeCoverageAbsMTotal'));
  38. //Lines Covered
  39. cw.println(lineForKey(metrics.lines.covered, 'CodeCoverageAbsLCovered'));
  40. cw.println(lineForKey(metrics.lines.total, 'CodeCoverageAbsLTotal'));
  41. cw.println("##teamcity[blockClosed name='" + this.blockName + "']");
  42. cw.close();
  43. };
  44. module.exports = TeamcityReport;