comment.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. 'use strict';
  2. var concat = require('concat-stream');
  3. var tap = require('tap');
  4. var tape = require('../');
  5. // Exploratory test to ascertain proper output when no t.comment() call
  6. // is made.
  7. tap.test('no comment', function (assert) {
  8. assert.plan(1);
  9. var verify = function (output) {
  10. assert.equal(output.toString('utf8'), [
  11. 'TAP version 13',
  12. '# no comment',
  13. '',
  14. '1..0',
  15. '# tests 0',
  16. '# pass 0',
  17. '',
  18. '# ok',
  19. ''
  20. ].join('\n'));
  21. };
  22. var test = tape.createHarness();
  23. test.createStream().pipe(concat(verify));
  24. test('no comment', function (t) {
  25. t.end();
  26. });
  27. });
  28. // Exploratory test, can we call t.comment() passing nothing?
  29. tap.test('missing argument', function (assert) {
  30. assert.plan(1);
  31. var test = tape.createHarness();
  32. test.createStream();
  33. test('missing argument', function (t) {
  34. try {
  35. t.comment();
  36. t.end();
  37. } catch (err) {
  38. assert.equal(err.constructor, TypeError);
  39. } finally {
  40. assert.end();
  41. }
  42. });
  43. });
  44. // Exploratory test, can we call t.comment() passing nothing?
  45. tap.test('null argument', function (assert) {
  46. assert.plan(1);
  47. var test = tape.createHarness();
  48. test.createStream();
  49. test('null argument', function (t) {
  50. try {
  51. t.comment(null);
  52. t.end();
  53. } catch (err) {
  54. assert.equal(err.constructor, TypeError);
  55. } finally {
  56. assert.end();
  57. }
  58. });
  59. });
  60. // Exploratory test, how is whitespace treated?
  61. tap.test('whitespace', function (assert) {
  62. assert.plan(1);
  63. var verify = function (output) {
  64. assert.equal(output.toString('utf8'), [
  65. 'TAP version 13',
  66. '# whitespace',
  67. '# ',
  68. '# a',
  69. '# a',
  70. '# a',
  71. '',
  72. '1..0',
  73. '# tests 0',
  74. '# pass 0',
  75. '',
  76. '# ok',
  77. ''
  78. ].join('\n'));
  79. };
  80. var test = tape.createHarness();
  81. test.createStream().pipe(concat(verify));
  82. test('whitespace', function (t) {
  83. t.comment(' ');
  84. t.comment(' a');
  85. t.comment('a ');
  86. t.comment(' a ');
  87. t.end();
  88. });
  89. });
  90. // Exploratory test, how about passing types other than strings?
  91. tap.test('non-string types', function (assert) {
  92. assert.plan(1);
  93. var verify = function (output) {
  94. assert.equal(output.toString('utf8'), [
  95. 'TAP version 13',
  96. '# non-string types',
  97. '# true',
  98. '# false',
  99. '# 42',
  100. '# 6.66',
  101. '# [object Object]',
  102. '# [object Object]',
  103. '# [object Object]',
  104. '# function ConstructorFunction() {}',
  105. '',
  106. '1..0',
  107. '# tests 0',
  108. '# pass 0',
  109. '',
  110. '# ok',
  111. ''
  112. ].join('\n'));
  113. };
  114. var test = tape.createHarness();
  115. test.createStream().pipe(concat(verify));
  116. test('non-string types', function (t) {
  117. t.comment(true);
  118. t.comment(false);
  119. t.comment(42);
  120. t.comment(6.66);
  121. t.comment({});
  122. t.comment({ answer: 42 });
  123. function ConstructorFunction() {}
  124. t.comment(new ConstructorFunction());
  125. t.comment(ConstructorFunction);
  126. t.end();
  127. });
  128. });
  129. tap.test('multiline string', function (assert) {
  130. assert.plan(1);
  131. var verify = function (output) {
  132. assert.equal(output.toString('utf8'), [
  133. 'TAP version 13',
  134. '# multiline strings',
  135. '# a',
  136. '# b',
  137. '# c',
  138. '# d',
  139. '',
  140. '1..0',
  141. '# tests 0',
  142. '# pass 0',
  143. '',
  144. '# ok',
  145. ''
  146. ].join('\n'));
  147. };
  148. var test = tape.createHarness();
  149. test.createStream().pipe(concat(verify));
  150. test('multiline strings', function (t) {
  151. t.comment([
  152. 'a',
  153. 'b'
  154. ].join('\n'));
  155. t.comment([
  156. 'c',
  157. 'd'
  158. ].join('\r\n'));
  159. t.end();
  160. });
  161. });
  162. tap.test('comment with createStream/objectMode', function (assert) {
  163. assert.plan(1);
  164. var test = tape.createHarness();
  165. test.createStream({ objectMode: true }).on('data', function (row) {
  166. if (typeof row === 'string') {
  167. assert.equal(row, 'comment message');
  168. }
  169. });
  170. test('t.comment', function (t) {
  171. t.comment('comment message');
  172. t.end();
  173. });
  174. });