exit.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. 'use strict';
  2. var tap = require('tap');
  3. var path = require('path');
  4. var spawn = require('child_process').spawn;
  5. var concat = require('concat-stream');
  6. var stripFullStack = require('./common').stripFullStack;
  7. tap.test('exit ok', function (t) {
  8. t.plan(2);
  9. var tc = function (rows) {
  10. t.same(rows.toString('utf8'), [
  11. 'TAP version 13',
  12. '# array',
  13. '# hi',
  14. 'ok 1 should be equivalent',
  15. 'ok 2 should be equivalent',
  16. 'ok 3 should be equivalent',
  17. 'ok 4 should be equivalent',
  18. 'ok 5 should be equivalent',
  19. '',
  20. '1..5',
  21. '# tests 5',
  22. '# pass 5',
  23. '',
  24. '# ok',
  25. '', // yes, these double-blank-lines at the end are required.
  26. '' // if you can figure out how to remove them, please do!
  27. ].join('\n'));
  28. };
  29. var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'ok.js')]);
  30. ps.stdout.pipe(concat(tc));
  31. ps.on('exit', function (code) {
  32. t.equal(code, 0);
  33. });
  34. });
  35. tap.test('exit fail', function (t) {
  36. t.plan(2);
  37. var tc = function (rows) {
  38. t.same(stripFullStack(rows.toString('utf8')), [
  39. 'TAP version 13',
  40. '# array',
  41. 'ok 1 should be equivalent',
  42. 'ok 2 should be equivalent',
  43. 'ok 3 should be equivalent',
  44. 'ok 4 should be equivalent',
  45. 'not ok 5 should be equivalent',
  46. ' ---',
  47. ' operator: deepEqual',
  48. ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
  49. ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
  50. ' at: <anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
  51. ' stack: |-',
  52. ' Error: should be equivalent',
  53. ' [... stack stripped ...]',
  54. ' at $TEST/exit/fail.js:$LINE:$COL',
  55. ' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
  56. ' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
  57. ' at Test.<anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
  58. ' [... stack stripped ...]',
  59. ' ...',
  60. '',
  61. '1..5',
  62. '# tests 5',
  63. '# pass 4',
  64. '# fail 1',
  65. '',
  66. ''
  67. ]);
  68. };
  69. var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]);
  70. ps.stdout.pipe(concat(tc));
  71. ps.on('exit', function (code) {
  72. t.notEqual(code, 0);
  73. });
  74. });
  75. tap.test('too few exit', function (t) {
  76. t.plan(2);
  77. var tc = function (rows) {
  78. t.same(stripFullStack(rows.toString('utf8')), [
  79. 'TAP version 13',
  80. '# array',
  81. 'ok 1 should be equivalent',
  82. 'ok 2 should be equivalent',
  83. 'ok 3 should be equivalent',
  84. 'ok 4 should be equivalent',
  85. 'ok 5 should be equivalent',
  86. 'not ok 6 plan != count',
  87. ' ---',
  88. ' operator: fail',
  89. ' expected: 6',
  90. ' actual: 5',
  91. ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
  92. ' stack: |-',
  93. ' Error: plan != count',
  94. ' [... stack stripped ...]',
  95. ' ...',
  96. '',
  97. '1..6',
  98. '# tests 6',
  99. '# pass 5',
  100. '# fail 1',
  101. '',
  102. ''
  103. ]);
  104. };
  105. var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]);
  106. ps.stdout.pipe(concat(tc));
  107. ps.on('exit', function (code) {
  108. t.notEqual(code, 0);
  109. });
  110. });
  111. tap.test('more planned in a second test', function (t) {
  112. t.plan(2);
  113. var tc = function (rows) {
  114. t.same(stripFullStack(rows.toString('utf8')), [
  115. 'TAP version 13',
  116. '# first',
  117. 'ok 1 should be truthy',
  118. '# second',
  119. 'ok 2 should be truthy',
  120. 'not ok 3 plan != count',
  121. ' ---',
  122. ' operator: fail',
  123. ' expected: 2',
  124. ' actual: 1',
  125. ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
  126. ' stack: |-',
  127. ' Error: plan != count',
  128. ' [... stack stripped ...]',
  129. ' ...',
  130. '',
  131. '1..3',
  132. '# tests 3',
  133. '# pass 2',
  134. '# fail 1',
  135. '',
  136. ''
  137. ]);
  138. };
  139. var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]);
  140. ps.stdout.pipe(concat(tc));
  141. ps.on('exit', function (code) {
  142. t.notEqual(code, 0);
  143. });
  144. });
  145. tap.test('todo passing', function (t) {
  146. t.plan(2);
  147. var tc = function (rows) {
  148. t.same(stripFullStack(rows.toString('utf8')), [
  149. 'TAP version 13',
  150. '# TODO todo pass',
  151. 'ok 1 should be truthy # TODO',
  152. '',
  153. '1..1',
  154. '# tests 1',
  155. '# pass 1',
  156. '',
  157. '# ok',
  158. '',
  159. ''
  160. ]);
  161. };
  162. var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]);
  163. ps.stdout.pipe(concat(tc));
  164. ps.on('exit', function (code) {
  165. t.equal(code, 0);
  166. });
  167. });
  168. tap.test('todo failing', function (t) {
  169. t.plan(2);
  170. var tc = function (rows) {
  171. t.same(stripFullStack(rows.toString('utf8')), [
  172. 'TAP version 13',
  173. '# TODO todo fail',
  174. 'not ok 1 should be truthy # TODO',
  175. ' ---',
  176. ' operator: ok',
  177. ' expected: true',
  178. ' actual: false',
  179. ' at: Test.<anonymous> ($TEST/exit/todo_fail.js:$LINE:$COL)',
  180. ' ...',
  181. '',
  182. '1..1',
  183. '# tests 1',
  184. '# pass 1',
  185. '',
  186. '# ok',
  187. '',
  188. ''
  189. ]);
  190. };
  191. var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]);
  192. ps.stdout.pipe(concat(tc));
  193. ps.on('exit', function (code) {
  194. t.equal(code, 0);
  195. });
  196. });
  197. tap.test('forgot to call t.end()', function (t) {
  198. t.plan(2);
  199. var tc = function (rows) {
  200. t.same(stripFullStack(rows.toString('utf8')), [
  201. 'TAP version 13',
  202. '# first',
  203. 'ok 1 should be truthy',
  204. '# oops forgot end',
  205. 'ok 2 should be truthy',
  206. 'not ok 3 test exited without ending: oops forgot end',
  207. ' ---',
  208. ' operator: fail',
  209. ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
  210. ' stack: |-',
  211. ' Error: test exited without ending: oops forgot end',
  212. ' [... stack stripped ...]',
  213. ' ...',
  214. '',
  215. '1..3',
  216. '# tests 3',
  217. '# pass 2',
  218. '# fail 1',
  219. '',
  220. ''
  221. ]);
  222. };
  223. var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]);
  224. ps.stdout.pipe(concat(tc));
  225. ps.on('exit', function (code) {
  226. t.notEqual(code, 0);
  227. });
  228. });