Code coverage report for preceptor-reporter/lib/messenger/teamCity.js

Statements: 100% (17 / 17)      Branches: 58.33% (7 / 12)      Functions: 100% (9 / 9)      Lines: 100% (17 / 17)      Ignored: none     

All files » preceptor-reporter/lib/messenger/ » teamCity.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132      1 1             1                       99                                     56   56 99     56                       5                     5                       16                       16                             8 5   3                         6       1  
// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
 
var AbstractMessenger = require('../abstractMessenger');
var _ = require('underscore');
 
/**
 * @class TeamCity messenger
 * @extends AbstractMessenger
 * @constructor
 */
var TeamCityMessenger = AbstractMessenger.extend(
 
	{
		/**
		 * Escape teamcity message
		 *
		 * @method _escape
		 * @param {string} msg
		 * @return {string}
		 * @private
		 */
		_escape: function (msg) {
			return (msg + '').
				replace(/\|/g, "||").
				replace(/'/g, "|'").
				replace(/\n/g, "|n").
				replace(/\r/g, "|r").
				replace(/\[/g, "|[").
				replace(/]/g, "|]");
		},
 
		/**
		 * Sends a message
		 *
		 * @method _send
		 * @param {string} messageType
		 * @param {object} data
		 * @param {object} [options]
		 * @private
		 */
		_send: function (messageType, data, options) {
			var outputData = [];
 
			_.each(_.keys(data), function (key) {
				outputData.push(key + "='" + this._escape(data[key]) + "'");
			}, this);
 
			this.trigger("##teamcity[" + messageType + " " + outputData.join(' ') + "]\n", options);
		},
 
 
		/**
		 * Suite starts
		 *
		 * @method testSuiteStarted
		 * @param {string} suiteName
		 * @param {object} [options]
		 */
		testSuiteStarted: function (suiteName, options) {
			this._send("testSuiteStarted", { name: suiteName }, options);
		},
 
		/**
		 * Suite ends
		 *
		 * @method testSuiteFinished
		 * @param {string} suiteName
		 * @param {object} [options]
		 */
		testSuiteFinished: function (suiteName, options) {
			this._send("testSuiteFinished", { name: suiteName }, options);
		},
 
 
		/**
		 * Test starts
		 *
		 * @method testStarted
		 * @param {string} testName
		 * @param {object} [options]
		 */
		testStarted: function (testName, options) {
			this._send("testStarted", { name: testName }, options);
		},
 
		/**
		 * Test starts
		 *
		 * @method testFinished
		 * @param {string} testName
		 * @param {int} duration Duration in ms
		 * @param {object} [options]
		 */
		testFinished: function (testName, duration, options) {
			this._send("testFinished", { name: testName, duration: duration }, options);
		},
 
 
		/**
		 * Test fails
		 *
		 * @method testFailed
		 * @param {string} testName
		 * @param {boolean} [error=false]
		 * @param {string} [message]
		 * @param {string} [details]
		 * @param {object} [options]
		 */
		testFailed: function (testName, error, message, details, options) {
			if (error) {
				this._send("testFailed", { name: testName, message: message || '', details: details || '', error: 'true' }, options);
			} else {
				this._send("testFailed", { name: testName, message: message || '', details: details || '' }, options);
			}
		},
 
		/**
		 * Test is ignored
		 *
		 * @method testIgnored
		 * @param {string} testName
		 * @param {string} [message]
		 * @param {object} [options]
		 */
		testIgnored: function (testName, message, options) {
			this._send("testIgnored", { name: testName, message: message || '' }, options);
		}
	});
 
module.exports = TeamCityMessenger;