
/**
 * Module dependencies.
 */

var Base = require('./base');

/**
 * Expose `Teamcity`.
 */

exports = module.exports = Teamcity;

/**
 * Initialize a new `Teamcity` reporter.
 *
 * @param {Runner} runner
 * @api public
 */

function Teamcity(runner) {
  Base.call(this, runner);
  var stats = this.stats;

  runner.on('start', function() {
    console.log("##teamcity[testSuiteStarted name='mocha.suite']");
  });

  runner.on('test', function(test) {
    console.log("##teamcity[testStarted name='" + escape(test.fullTitle()) + "']");
  });

  runner.on('fail', function(test, err) {
    console.log("##teamcity[testFailed name='" + escape(test.fullTitle()) + "' message='" + escape(err.message) + "']");
  });

  runner.on('pending', function(test) {
    console.log("##teamcity[testIgnored name='" + escape(test.fullTitle()) + "' message='pending']");
  });

  runner.on('test end', function(test) {
    console.log("##teamcity[testFinished name='" + escape(test.fullTitle()) + "' duration='" + test.duration + "']");
  });

  runner.on('end', function() {
    console.log("##teamcity[testSuiteFinished name='mocha.suite' duration='" + stats.duration + "']");
  });
}

/**
 * Escape the given `str`.
 */

function escape(str) {
  return str.replace("|", "||")
            .replace("\n", "|n")
            .replace("\r", "|r")
            .replace("[", "|[")
            .replace("]", "|]")
            .replace("\u0085", "|x")
            .replace("\u2028", "|l")
            .replace("\u2029", "|p")
            .replace(/'/g, "|'");
}

@@ -1253,11 +1253,12 @@
 ace(
-%22%7C%22
+/%7C/g
 , %22%7C
@@ -1286,12 +1286,13 @@
 ace(
-%22%5Cn%22
+/%5Cn/g
 , %22%7C
@@ -1320,12 +1320,13 @@
 ace(
-%22%5Cr%22
+/%5Cr/g
 , %22%7C
@@ -1354,11 +1354,13 @@
 ace(
-%22%5B%22
+/%5C%5B/g
 , %22%7C
@@ -1388,11 +1388,13 @@
 ace(
-%22%5D%22
+/%5C%5D/g
 , %22%7C
@@ -1422,16 +1422,17 @@
 ace(
-%22
+/
 %5Cu0085
-%22
+/g
 , %22%7C
@@ -1460,16 +1460,17 @@
 ace(
-%22
+/
 %5Cu2028
-%22
+/g
 , %22%7C
@@ -1498,16 +1498,17 @@
 ace(
-%22
+/
 %5Cu2029
-%22
+/g
 , %22%7C

Use global replace regex