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

Statements: 100% (31 / 31)      Branches: 100% (2 / 2)      Functions: 100% (14 / 14)      Lines: 100% (31 / 31)      Ignored: none     

All files » preceptor-reporter/lib/messenger/ » preceptor.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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203      1             1                         60                       60 2 2                       3 3                         7 7                       3 3                           5 5                     5 5                           16 16                           3 3                         3 3                     5 5                     3 3                       4 4                     3 3       1  
// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
 
var AbstractMessenger = require('../abstractMessenger');
 
/**
 * @class PreceptorMessenger
 * @extends AbstractMessenger
 * @constructor
 */
var PreceptorMessenger = AbstractMessenger.extend(
 
	{
		/**
		 * Sends a message
		 *
		 * @method _send
		 * @param {string} messageType
		 * @param {*} data
		 * @param {object} [options]
		 * @private
		 */
		_send: function (messageType, data, options) {
			this.trigger('#|# ' + messageType + " " + JSON.stringify(data) + " #|#\n", options);
		},
 
 
		/**
		 * Sends intro message
		 *
		 * @method _sendIntro
		 * @param {object} [options]
		 * @private
		 */
		_sendIntro: function (options) {
			if (!this._introSent) {
				this._introSent = true;
				this.version(options);
			}
		},
 
 
		/**
		 * Sends the version as message
		 *
		 * @method version
		 * @param {object} [options]
		 */
		version: function (options) {
			this._sendIntro();
			this._send("version", 1, options);
		},
 
 
		/**
		 * Item has custom data
		 *
		 * @method itemData
		 * @param {string} id
		 * @param {string} json Data in JSON format
		 * @param {object} [options]
		 */
		itemData: function (id, json, options) {
			this._sendIntro();
			this._send("itemData", [id, json], options);
		},
 
		/**
		 * Item has a custom message
		 *
		 * @method itemMessage
		 * @param {string} id
		 * @param {string} message
		 * @param {object} [options]
		 */
		itemMessage: function (id, message, options) {
			this._sendIntro();
			this._send("itemMessage", [id, message], options);
		},
 
 
		/**
		 * Suite starts
		 *
		 * @method suiteStart
		 * @param {string} id
		 * @param {string} parentId
		 * @param {string} suiteName
		 * @param {object} [options]
		 */
		suiteStart: function (id, parentId, suiteName, options) {
			this._sendIntro();
			this._send("suiteStart", [id, parentId, suiteName], options);
		},
 
		/**
		 * Suite ends
		 *
		 * @method suiteEnd
		 * @param {string} id
		 * @param {object} [options]
		 */
		suiteEnd: function (id, options) {
			this._sendIntro();
			this._send("suiteEnd", [id], options);
		},
 
 
		/**
		 * Test starts
		 *
		 * @method testStart
		 * @param {string} id
		 * @param {string} parentId
		 * @param {string} testName
		 * @param {object} [options]
		 */
		testStart: function (id, parentId, testName, options) {
			this._sendIntro();
			this._send("testStart", [id, parentId, testName], options);
		},
 
 
		/**
		 * Test fails
		 *
		 * @method testFailed
		 * @param {string} id
		 * @param {string} [message]
		 * @param {string} [reason]
		 * @param {object} [options]
		 */
		testFailed: function (id, message, reason, options) {
			this._sendIntro();
			this._send("testFailed", [id, message, reason], options);
		},
 
		/**
		 * Test has an error
		 *
		 * @method testError
		 * @param {string} id
		 * @param {string} [message]
		 * @param {string} [reason]
		 * @param {object} [options]
		 */
		testError: function (id, message, reason, options) {
			this._sendIntro();
			this._send("testError", [id, message, reason], options);
		},
 
		/**
		 * Test has passed
		 *
		 * @method testPassed
		 * @param {string} id
		 * @param {object} [options]
		 */
		testPassed: function (id, options) {
			this._sendIntro();
			this._send("testPassed", [id], options);
		},
 
		/**
		 * Test is undefined
		 *
		 * @method testUndefined
		 * @param {string} id
		 * @param {object} [options]
		 */
		testUndefined: function (id, options) {
			this._sendIntro();
			this._send("testUndefined", [id], options);
		},
 
		/**
		 * Test is skipped
		 *
		 * @method testSkipped
		 * @param {string} id
		 * @param {string} [reason]
		 * @param {object} [options]
		 */
		testSkipped: function (id, reason, options) {
			this._sendIntro();
			this._send("testSkipped", [id, reason], options);
		},
 
		/**
		 * Test is incomplete
		 *
		 * @method testIncomplete
		 * @param {string} id
		 * @param {object} [options]
		 */
		testIncomplete: function (id, options) {
			this._sendIntro();
			this._send("testIncomplete", [id], options);
		}
	});
 
module.exports = PreceptorMessenger;