Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

objectMode.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var tap = require('tap');
  2. var tape = require('../');
  3. var forEach = require('for-each');
  4. var through = require('through');
  5. tap.test('object results', function (assert) {
  6. var printer = through({ objectMode: true });
  7. var objects = [];
  8. printer.write = function (obj) {
  9. objects.push(obj);
  10. };
  11. printer.end = function (obj) {
  12. if (obj) objects.push(obj);
  13. var todos = 0;
  14. var skips = 0;
  15. var testIds = [];
  16. var endIds = [];
  17. var asserts = 0;
  18. assert.equal(objects.length, 13);
  19. forEach(objects, function (obj) {
  20. if (obj.type === 'assert') {
  21. asserts++;
  22. } else if (obj.type === 'test') {
  23. testIds.push(obj.id);
  24. if (obj.skip) {
  25. skips++;
  26. } else if (obj.todo) {
  27. todos++;
  28. }
  29. } else if (obj.type === 'end') {
  30. endIds.push(obj.text);
  31. // test object should exist
  32. assert.notEqual(testIds.indexOf(obj.test), -1);
  33. }
  34. });
  35. assert.equal(asserts, 5);
  36. assert.equal(skips, 1);
  37. assert.equal(todos, 2);
  38. assert.equal(testIds.length, endIds.length);
  39. assert.end();
  40. };
  41. tape.createStream({ objectMode: true })
  42. .pipe(printer);
  43. tape('parent', function (t1) {
  44. t1.equal(true, true);
  45. t1.test('child1', {skip: true}, function (t2) {
  46. t2.equal(true, true);
  47. t2.equal(true, false);
  48. t2.end();
  49. });
  50. t1.test('child2', {todo: true}, function (t3) {
  51. t3.equal(true, false);
  52. t3.equal(true, true);
  53. t3.end();
  54. });
  55. t1.test('child3', {todo: true});
  56. t1.equal(true, true);
  57. t1.equal(true, true);
  58. t1.end();
  59. });
  60. });