Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

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