index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 '##teamcity[buildStatisticValue key=\'' + teamcityVar + '\' value=\'' + value + '\']';
  13. }
  14. TeamcityReport.prototype.onStart = function (node, context) {
  15. var metrics = node.getCoverageSummary(),
  16. cw;
  17. cw = context.writer.writeFile(this.file);
  18. cw.println('');
  19. cw.println('##teamcity[blockOpened name=\''+ this.blockName +'\']');
  20. //Statements Covered
  21. cw.println(lineForKey(metrics.statements.covered, 'CodeCoverageAbsBCovered'));
  22. cw.println(lineForKey(metrics.statements.total, 'CodeCoverageAbsBTotal'));
  23. //Branches Covered
  24. cw.println(lineForKey(metrics.branches.covered, 'CodeCoverageAbsRCovered'));
  25. cw.println(lineForKey(metrics.branches.total, 'CodeCoverageAbsRTotal'));
  26. //Functions Covered
  27. cw.println(lineForKey(metrics.functions.covered, 'CodeCoverageAbsMCovered'));
  28. cw.println(lineForKey(metrics.functions.total, 'CodeCoverageAbsMTotal'));
  29. //Lines Covered
  30. cw.println(lineForKey(metrics.lines.covered, 'CodeCoverageAbsLCovered'));
  31. cw.println(lineForKey(metrics.lines.total, 'CodeCoverageAbsLTotal'));
  32. cw.println('##teamcity[blockClosed name=\''+ this.blockName +'\']');
  33. cw.close();
  34. };
  35. module.exports = TeamcityReport;