objectMode.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. 'use strict';
  2. var tap = require('tap');
  3. var tape = require('../');
  4. var forEach = require('for-each');
  5. var through = require('through');
  6. tap.test('object results', function (assert) {
  7. var printer = through({ objectMode: true });
  8. var objects = [];
  9. printer.write = function (obj) {
  10. objects.push(obj);
  11. };
  12. printer.end = function (obj) {
  13. if (obj) { objects.push(obj); }
  14. var todos = 0;
  15. var skips = 0;
  16. var testIds = [];
  17. var endIds = [];
  18. var asserts = 0;
  19. assert.equal(objects.length, 13);
  20. forEach(objects, function (object) {
  21. if (object.type === 'assert') {
  22. asserts++;
  23. } else if (object.type === 'test') {
  24. testIds.push(object.id);
  25. if (object.skip) {
  26. skips++;
  27. } else if (object.todo) {
  28. todos++;
  29. }
  30. } else if (object.type === 'end') {
  31. endIds.push(object.text);
  32. // test object should exist
  33. assert.notEqual(testIds.indexOf(object.test), -1);
  34. }
  35. });
  36. assert.equal(asserts, 5);
  37. assert.equal(skips, 1);
  38. assert.equal(todos, 2);
  39. assert.equal(testIds.length, endIds.length);
  40. assert.end();
  41. };
  42. tape.createStream({ objectMode: true }).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. });