stream1-read.js 565 B

123456789101112131415161718192021222324252627282930
  1. var test = require('tape');
  2. var read = require('..');
  3. var co = require('co');
  4. var through = require('through');
  5. test('read', function(t) {
  6. var times = 3;
  7. t.plan(2 + times);
  8. co(function*() {
  9. var stream = through();
  10. process.nextTick(function() {
  11. (function next() {
  12. stream.queue('foo');
  13. if (--times) setTimeout(next, 10);
  14. else stream.end();
  15. })();
  16. });
  17. var chunk;
  18. while (chunk = yield read(stream)) {
  19. t.equal(chunk, 'foo', 'data event');
  20. }
  21. t.ok(true, 'ended');
  22. }, t.error.bind(t));
  23. });