teamcity.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Module dependencies.
  3. */
  4. var Base = require('./base');
  5. /**
  6. * Expose `Teamcity`.
  7. */
  8. exports = module.exports = Teamcity;
  9. /**
  10. * Initialize a new `Teamcity` reporter.
  11. *
  12. * @param {Runner} runner
  13. * @api public
  14. */
  15. function Teamcity(runner) {
  16. Base.call(this, runner);
  17. var stats = this.stats;
  18. runner.on('start', function() {
  19. console.log("##teamcity[testSuiteStarted name='mocha.suite']");
  20. });
  21. runner.on('test', function(test) {
  22. console.log("##teamcity[testStarted name='" + escape(test.fullTitle()) + "']");
  23. });
  24. runner.on('fail', function(test, err) {
  25. console.log("##teamcity[testFailed name='" + escape(test.fullTitle()) + "' message='" + escape(err.message) + "']");
  26. });
  27. runner.on('pending', function(test) {
  28. console.log("##teamcity[testIgnored name='" + escape(test.fullTitle()) + "' message='pending']");
  29. });
  30. runner.on('test end', function(test) {
  31. console.log("##teamcity[testFinished name='" + escape(test.fullTitle()) + "' duration='" + test.duration + "']");
  32. });
  33. runner.on('end', function() {
  34. console.log("##teamcity[testSuiteFinished name='mocha.suite' duration='" + stats.duration + "']");
  35. });
  36. }
  37. /**
  38. * Escape the given `str`.
  39. */
  40. function escape(str) {
  41. return str
  42. .replace(/\|/g, "||")
  43. .replace(/\n/g, "|n")
  44. .replace(/\r/g, "|r")
  45. .replace(/\[/g, "|[")
  46. .replace(/\]/g, "|]")
  47. .replace(/\u0085/g, "|x")
  48. .replace(/\u2028/g, "|l")
  49. .replace(/\u2029/g, "|p")
  50. .replace(/'/g, "|'");
  51. }