API Docs for: 0.9.1
Show:

File: lib/reporter/plain.js

  1. // Copyright 2014, Yahoo! Inc.
  2. // Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
  3.  
  4. var AbstractReporter = require('../abstractReporter');
  5. var util = require('util');
  6.  
  7. /**
  8. * @class PlainReporter
  9. * @extends AbstractReporter
  10. * @constructor
  11. */
  12. var PlainReporter = AbstractReporter.extend(
  13.  
  14. {
  15. /**
  16. * Initializes the instance
  17. *
  18. * @method initialize
  19. */
  20. initialize: function () {
  21. this.__super();
  22.  
  23. if (this.getOptions().progress === undefined) {
  24. this.getOptions().progress = true;
  25. }
  26. if (this.getOptions().output === undefined) {
  27. this.getOptions().output = true;
  28. }
  29. },
  30.  
  31.  
  32. /**
  33. * Escape message
  34. *
  35. * @method _escape
  36. * @param {string} msg
  37. * @return {string}
  38. * @private
  39. */
  40. _escape: function (msg) {
  41. return (msg + '').
  42. replace(/'/g, "\\'").
  43. replace(/\n/g, "\\n").
  44. replace(/\r/g, "\\r");
  45. },
  46.  
  47.  
  48. /**
  49. * Called when reporting stops
  50. *
  51. * @method stop
  52. */
  53. stop: function () {
  54. this.__super();
  55. },
  56.  
  57.  
  58. /**
  59. * Called when suite starts
  60. *
  61. * @method suiteStart
  62. * @param {string} id
  63. * @param {string} parentId
  64. * @param {string} suiteName
  65. */
  66. suiteStart: function (id, parentId, suiteName) {
  67. this.__super(id, parentId, suiteName);
  68. this.console(id, 'start', util.format("suiteStarted name='%s'", this._escape(suiteName)) + "\n");
  69. },
  70.  
  71. /**
  72. * Called when suite ends
  73. *
  74. * @method suiteEnd
  75. * @param {string} id
  76. */
  77. suiteEnd: function (id) {
  78. this.__super(id);
  79. this.console(id, 'end', util.format("suiteFinished name='%s'", this._escape(this.getContainer().getAction(id).name)) + "\n");
  80. },
  81.  
  82.  
  83. /**
  84. * Called when any item has custom data
  85. *
  86. * @method itemData
  87. * @param {string} id
  88. * @param {string} json JSON-data
  89. */
  90. itemData: function (id, json) {
  91. var action;
  92.  
  93. this.__super(id, json);
  94.  
  95. action = this.getContainer().getAction(id);
  96. this.console(id, 'start', util.format("itemData name='%s' data='%s'", this._escape(action.name), this._escape(json)) + "\n");
  97. },
  98.  
  99. /**
  100. * Called when any item has a custom message
  101. *
  102. * @method itemMessage
  103. * @param {string} id
  104. * @param {string} message
  105. */
  106. itemMessage: function (id, message) {
  107. var action;
  108.  
  109. this.__super(id, message);
  110.  
  111. action = this.getContainer().getAction(id);
  112. this.console(id, 'start', util.format("itemMessage name='%s' message='%s'", this._escape(action.name), this._escape(message)) + "\n");
  113. },
  114.  
  115.  
  116. /**
  117. * Called when test starts
  118. *
  119. * @method testStart
  120. * @param {string} id
  121. * @param {string} parentId
  122. * @param {string} testName
  123. */
  124. testStart: function (id, parentId, testName) {
  125. this.__super(id, parentId, testName);
  126. this.console(id, 'start', util.format("testStarted name='%s'", this._escape(testName)) + "\n");
  127. },
  128.  
  129.  
  130. /**
  131. * Called when test fails
  132. *
  133. * @method testFailed
  134. * @param {string} id
  135. * @param {string} [message]
  136. * @param {string} [reason]
  137. */
  138. testFailed: function (id, message, reason) {
  139. var action;
  140.  
  141. this.__super(id, message, reason);
  142.  
  143. action = this.getContainer().getAction(id);
  144. this.console(id, 'end', util.format("testFailed name='%s' message='%s' details='%s'", this._escape(action.name), this._escape(message), this._escape(reason)) + "\n");
  145. },
  146.  
  147. /**
  148. * Called when test has an error
  149. *
  150. * @method testError
  151. * @param {string} id
  152. * @param {string} [message]
  153. * @param {string} [reason]
  154. */
  155. testError: function (id, message, reason) {
  156. var action;
  157.  
  158. this.__super(id, message, reason);
  159.  
  160. action = this.getContainer().getAction(id);
  161. this.console(id, 'end', util.format("testError name='%s' message='%s' details='%s'", this._escape(action.name), this._escape(message), this._escape(reason)) + "\n");
  162. },
  163.  
  164. /**
  165. * Called when test has passed
  166. *
  167. * @method testPassed
  168. * @param {string} id
  169. */
  170. testPassed: function (id) {
  171. var action;
  172.  
  173. this.__super(id);
  174.  
  175. action = this.getContainer().getAction(id);
  176. this.console(id, 'end', util.format("testPassed name='%s' duration='%s'", this._escape(action.name), this._escape(action.duration)) + "\n");
  177. },
  178.  
  179. /**
  180. * Called when test is undefined
  181. *
  182. * @method testUndefined
  183. * @param {string} id
  184. */
  185. testUndefined: function (id) {
  186. var action;
  187.  
  188. this.__super(id);
  189.  
  190. action = this.getContainer().getAction(id);
  191. this.console(id, 'end', util.format("testUndefined name='%s'", this._escape(action.name)) + "\n");
  192. },
  193.  
  194. /**
  195. * Called when test is skipped
  196. *
  197. * @method testSkipped
  198. * @param {string} id
  199. * @param {string} [reason]
  200. */
  201. testSkipped: function (id, reason) {
  202. var action;
  203.  
  204. this.__super(id, reason);
  205.  
  206. action = this.getContainer().getAction(id);
  207. this.console(id, 'end', util.format("testSkipped name='%s' message='%s'", this._escape(action.name), this._escape(reason)) + "\n");
  208. },
  209.  
  210. /**
  211. * Called when test is incomplete
  212. *
  213. * @method testIncomplete
  214. * @param {string} id
  215. */
  216. testIncomplete: function (id) {
  217. var action;
  218.  
  219. this.__super(id);
  220.  
  221. action = this.getContainer().getAction(id);
  222. this.console(id, 'end', util.format("testIncomplete name='%s'", this._escape(action.name)) + "\n");
  223. }
  224. });
  225.  
  226. module.exports = PlainReporter;
  227.