Permalink
Browse files

testing a single buffered stream

  • Loading branch information...
1 parent 0409795 commit 5abfa091bd22711842496772de926ac3ab950b06 @substack committed Nov 10, 2011
Showing with 39 additions and 2 deletions.
  1. +39 −2 test/single.js
View
@@ -3,14 +3,16 @@ var fs = require('fs');
var es = require('event-stream');
var test = require('tap').test;
var EventEmitter = require('events').EventEmitter;
+var BufferedStream = require('morestreams').BufferedStream;
+var es = require('event-stream');
var words = fs.readFileSync(__dirname + '/words.txt', 'utf8')
.split(/\n/)
.slice(0, -1)
.map(function (s) { return s + '\n' })
;
-test('single stream in an object', function (t) {
+test('single stream', function (t) {
t.plan(1);
var s = gutter({
@@ -42,7 +44,7 @@ test('single stream in an object', function (t) {
});
});
-test('single stream in an event emitter', function (t) {
+test('single stream with an event emitter', function (t) {
t.plan(1);
var ws = words.slice();
@@ -80,3 +82,38 @@ test('single stream in an event emitter', function (t) {
t.end();
});
});
+
+test('single stream with a BufferedStream', function (t) {
+ t.plan(1);
+
+ var bs = new BufferedStream;
+ es.connect(
+ fs.createReadStream(__dirname + '/words.txt'),
+ es.split()
+ ).pipe(bs);
+
+ var s = gutter({
+ a : 3,
+ b : 4,
+ stream : bs,
+ c : 5
+ });
+
+ var data = '';
+ s.on('data', function (buf) {
+ data += buf;
+ });
+
+ s.on('end', function () {
+ t.deepEqual(
+ JSON.parse(data),
+ {
+ a : 3,
+ b : 4,
+ stream : words,
+ c : 5
+ }
+ );
+ t.end();
+ });
+});

0 comments on commit 5abfa09

Please sign in to comment.