API Docs for: 0.9.1
Show:

File: lib/reporter/spec.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.  
  6. /**
  7. * @class SpecReporter
  8. * @extends AbstractReporter
  9. * @constructor
  10. *
  11. * @property {int} _commentCounter
  12. */
  13. var SpecReporter = AbstractReporter.extend(
  14.  
  15. {
  16. /**
  17. * Initializes the instance
  18. *
  19. * @method initialize
  20. */
  21. initialize: function () {
  22. this.__super();
  23.  
  24. if (this.getOptions().progress === undefined) {
  25. this.getOptions().progress = true;
  26. }
  27. if (this.getOptions().output === undefined) {
  28. this.getOptions().output = true;
  29. }
  30. },
  31.  
  32.  
  33. /**
  34. * Spacing for object
  35. *
  36. * @method _spacing
  37. * @param {object} obj
  38. * @return {string}
  39. * @private
  40. */
  41. _spacing: function (obj) {
  42. return new Array(obj.level + 1).join(' ');
  43. },
  44.  
  45.  
  46. /**
  47. * Called when reporting starts
  48. *
  49. * @method start
  50. */
  51. start: function () {
  52. this.__super();
  53.  
  54. this._commentCounter = 0;
  55. },
  56.  
  57. /**
  58. * Called when reporting stops
  59. *
  60. * @method stop
  61. */
  62. stop: function () {
  63. this.__super();
  64. this.console(undefined, 'stop', "\n");
  65. },
  66.  
  67.  
  68. /**
  69. * Called when suite starts
  70. *
  71. * @method suiteStart
  72. * @param {string} id
  73. * @param {string} parentId
  74. * @param {string} suiteName
  75. */
  76. suiteStart: function (id, parentId, suiteName) {
  77. this.__super(id, parentId, suiteName);
  78. this.console(id, 'start', "\n" + this._spacing(this.getContainer().getAction(id)) + suiteName + "\n");
  79. },
  80.  
  81. /**
  82. * Called when suite ends
  83. *
  84. * @method suiteEnd
  85. * @param {string} id
  86. */
  87. suiteEnd: function (id) {
  88. this.__super(id);
  89. },
  90.  
  91.  
  92. /**
  93. * Called when test fails
  94. *
  95. * @method testFailed
  96. * @param {string} id
  97. * @param {string} [message]
  98. * @param {string} [reason]
  99. */
  100. testFailed: function (id, message, reason) {
  101. var action = this.getContainer().getAction(id),
  102. start = '', end = '';
  103.  
  104. this.__super(id, message, reason);
  105.  
  106. if (this.useColor()) {
  107. start = '\x1B[31m';
  108. end = '\x1B[0m';
  109. }
  110. this._commentCounter++;
  111. this.console(id, 'end', this._spacing(action) + start + this._commentCounter + ') ' + action.name + end + "\n");
  112. },
  113.  
  114. /**
  115. * Called when test has an error
  116. *
  117. * @method testError
  118. * @param {string} id
  119. * @param {string} [message]
  120. * @param {string} [reason]
  121. */
  122. testError: function (id, message, reason) {
  123. var action = this.getContainer().getAction(id),
  124. start = '', end = '';
  125.  
  126. this.__super(id, message, reason);
  127.  
  128. if (this.useColor()) {
  129. start = '\x1B[31m';
  130. end = '\x1B[0m';
  131. }
  132. this._commentCounter++;
  133. this.console(id, 'end', this._spacing(action) + start + this._commentCounter + ') ' + action.name + end + "\n");
  134. },
  135.  
  136. /**
  137. * Called when test has passed
  138. *
  139. * @method testPassed
  140. * @param {string} id
  141. */
  142. testPassed: function (id) {
  143. var action = this.getContainer().getAction(id),
  144. checkMark = '✓',
  145. start = '', end = '';
  146.  
  147. this.__super(id);
  148.  
  149. if (this.useColor()) {
  150. checkMark = '\x1B[32m' + checkMark + '\x1B[0m';
  151. start = '\x1B[37m';
  152. end = '\x1B[0m';
  153. }
  154. this.console(id, 'end', this._spacing(action) + checkMark + ' ' + start + action.name + end + "\n");
  155. },
  156.  
  157. /**
  158. * Called when test is undefined
  159. *
  160. * @method testUndefined
  161. * @param {string} id
  162. */
  163. testUndefined: function (id) {
  164. var action = this.getContainer().getAction(id),
  165. start = '', end = '';
  166.  
  167. this.__super(id);
  168.  
  169. if (this.useColor()) {
  170. start = '\x1B[33m';
  171. end = '\x1B[0m';
  172. }
  173. this._commentCounter++;
  174. this.console(id, 'end', this._spacing(action) + start + this._commentCounter + ') ' + action.name + end + "\n");
  175. },
  176.  
  177. /**
  178. * Called when test is skipped
  179. *
  180. * @method testSkipped
  181. * @param {string} id
  182. * @param {string} [reason]
  183. */
  184. testSkipped: function (id, reason) {
  185. var action = this.getContainer().getAction(id),
  186. start = '', end = '';
  187.  
  188. this.__super(id, reason);
  189.  
  190. if (this.useColor()) {
  191. start = '\x1B[35m';
  192. end = '\x1B[0m';
  193. }
  194. this._commentCounter++;
  195. this.console(id, 'end', this._spacing(action) + start + this._commentCounter + ') ' + action.name + end + "\n");
  196. },
  197.  
  198. /**
  199. * Called when test is incomplete
  200. *
  201. * @method testIncomplete
  202. * @param {string} id
  203. */
  204. testIncomplete: function (id) {
  205. var action = this.getContainer().getAction(id),
  206. dash = '-',
  207. start = '', end = '';
  208.  
  209. this.__super(id);
  210.  
  211. if (this.useColor()) {
  212. start = '\x1B[34m';
  213. end = '\x1B[0m';
  214. }
  215. this.console(id, 'end', this._spacing(action) + start + dash + ' ' + action.name + end + "\n");
  216. }
  217. });
  218.  
  219. module.exports = SpecReporter;
  220.