API Docs for: 0.9.1
Show:

File: lib/messenger/preceptor.js

  1. // Copyright 2014, Yahoo! Inc.
  2. // Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
  3.  
  4. var AbstractMessenger = require('../abstractMessenger');
  5.  
  6. /**
  7. * @class PreceptorMessenger
  8. * @extends AbstractMessenger
  9. * @constructor
  10. */
  11. var PreceptorMessenger = AbstractMessenger.extend(
  12.  
  13. {
  14. /**
  15. * Sends a message
  16. *
  17. * @method _send
  18. * @param {string} messageType
  19. * @param {*} data
  20. * @param {object} [options]
  21. * @private
  22. */
  23. _send: function (messageType, data, options) {
  24. this.trigger('#|# ' + messageType + " " + JSON.stringify(data) + " #|#\n", options);
  25. },
  26.  
  27.  
  28. /**
  29. * Sends intro message
  30. *
  31. * @method _sendIntro
  32. * @param {object} [options]
  33. * @private
  34. */
  35. _sendIntro: function (options) {
  36. if (!this._introSent) {
  37. this._introSent = true;
  38. this.version(options);
  39. }
  40. },
  41.  
  42.  
  43. /**
  44. * Sends the version as message
  45. *
  46. * @method version
  47. * @param {object} [options]
  48. */
  49. version: function (options) {
  50. this._sendIntro();
  51. this._send("version", 1, options);
  52. },
  53.  
  54.  
  55. /**
  56. * Item has custom data
  57. *
  58. * @method itemData
  59. * @param {string} id
  60. * @param {string} json Data in JSON format
  61. * @param {object} [options]
  62. */
  63. itemData: function (id, json, options) {
  64. this._sendIntro();
  65. this._send("itemData", [id, json], options);
  66. },
  67.  
  68. /**
  69. * Item has a custom message
  70. *
  71. * @method itemMessage
  72. * @param {string} id
  73. * @param {string} message
  74. * @param {object} [options]
  75. */
  76. itemMessage: function (id, message, options) {
  77. this._sendIntro();
  78. this._send("itemMessage", [id, message], options);
  79. },
  80.  
  81.  
  82. /**
  83. * Suite starts
  84. *
  85. * @method suiteStart
  86. * @param {string} id
  87. * @param {string} parentId
  88. * @param {string} suiteName
  89. * @param {object} [options]
  90. */
  91. suiteStart: function (id, parentId, suiteName, options) {
  92. this._sendIntro();
  93. this._send("suiteStart", [id, parentId, suiteName], options);
  94. },
  95.  
  96. /**
  97. * Suite ends
  98. *
  99. * @method suiteEnd
  100. * @param {string} id
  101. * @param {object} [options]
  102. */
  103. suiteEnd: function (id, options) {
  104. this._sendIntro();
  105. this._send("suiteEnd", [id], options);
  106. },
  107.  
  108.  
  109. /**
  110. * Test starts
  111. *
  112. * @method testStart
  113. * @param {string} id
  114. * @param {string} parentId
  115. * @param {string} testName
  116. * @param {object} [options]
  117. */
  118. testStart: function (id, parentId, testName, options) {
  119. this._sendIntro();
  120. this._send("testStart", [id, parentId, testName], options);
  121. },
  122.  
  123.  
  124. /**
  125. * Test fails
  126. *
  127. * @method testFailed
  128. * @param {string} id
  129. * @param {string} [message]
  130. * @param {string} [reason]
  131. * @param {object} [options]
  132. */
  133. testFailed: function (id, message, reason, options) {
  134. this._sendIntro();
  135. this._send("testFailed", [id, message, reason], options);
  136. },
  137.  
  138. /**
  139. * Test has an error
  140. *
  141. * @method testError
  142. * @param {string} id
  143. * @param {string} [message]
  144. * @param {string} [reason]
  145. * @param {object} [options]
  146. */
  147. testError: function (id, message, reason, options) {
  148. this._sendIntro();
  149. this._send("testError", [id, message, reason], options);
  150. },
  151.  
  152. /**
  153. * Test has passed
  154. *
  155. * @method testPassed
  156. * @param {string} id
  157. * @param {object} [options]
  158. */
  159. testPassed: function (id, options) {
  160. this._sendIntro();
  161. this._send("testPassed", [id], options);
  162. },
  163.  
  164. /**
  165. * Test is undefined
  166. *
  167. * @method testUndefined
  168. * @param {string} id
  169. * @param {object} [options]
  170. */
  171. testUndefined: function (id, options) {
  172. this._sendIntro();
  173. this._send("testUndefined", [id], options);
  174. },
  175.  
  176. /**
  177. * Test is skipped
  178. *
  179. * @method testSkipped
  180. * @param {string} id
  181. * @param {string} [reason]
  182. * @param {object} [options]
  183. */
  184. testSkipped: function (id, reason, options) {
  185. this._sendIntro();
  186. this._send("testSkipped", [id, reason], options);
  187. },
  188.  
  189. /**
  190. * Test is incomplete
  191. *
  192. * @method testIncomplete
  193. * @param {string} id
  194. * @param {object} [options]
  195. */
  196. testIncomplete: function (id, options) {
  197. this._sendIntro();
  198. this._send("testIncomplete", [id], options);
  199. }
  200. });
  201.  
  202. module.exports = PreceptorMessenger;
  203.