index.js 1.9 KB

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