Permalink
Browse files

object streaming test works

  • Loading branch information...
substack committed Feb 22, 2012
1 parent bfbf5cc commit 0eb71435c802718eee77f2a019477ecffbc0a7af
Showing with 11 additions and 5 deletions.
  1. +6 −1 index.js
  2. +1 −1 package.json
  3. +4 −3 test/object.js
View
@@ -21,6 +21,7 @@ module.exports = function (obj) {
var s = new BufferedStream();
s.readable = true;
s.writable = true;
+ s.type = part.type;
part.pipe(s);
part.pause();
@@ -38,6 +39,7 @@ module.exports = function (obj) {
s.readable = true;
s.writable = true;
s.pause();
+ s.type = part.type;
part.on('data', function (buf) {
s.write(buf);
});
@@ -62,7 +64,10 @@ module.exports = function (obj) {
pop();
}
else {
- var s = JSONStream.stringify();
+ var s = part.type === 'object'
+ ? JSONStream.stringifyObject()
+ : JSONStream.stringify()
+ ;
s.on('data', function (buf) {
output.emit('data', buf);
});
View
@@ -22,7 +22,7 @@
},
"dependencies" : {
"traverse" : "0.5.x",
- "JSONStream" : "0.1.x",
+ "JSONStream" : "https://github.com/substack/JSONStream/tarball/master",
"morestreams" : "0.1.x"
},
"devDependencies" : {
View
@@ -3,17 +3,18 @@ var test = require('tap').test;
var EventEmitter = require('events').EventEmitter;
-test('object stream', function (t) {
+test('object emitter', function (t) {
t.plan(1);
var ev = new EventEmitter;
+ ev.type = 'object';
var i = 0;
var iv = setInterval(function () {
if (++i === 5) {
clearInterval(iv);
ev.emit('end');
}
- else ev.emit('data', [ String.fromCharCode(i + 97), i ])
+ else ev.emit('data', [ String.fromCharCode(i + 96), i ])
}, 10);
var s = gutter([
@@ -28,7 +29,7 @@ test('object stream', function (t) {
s.on('end', function () {
t.deepEqual(
JSON.parse(data),
- [ 'foo', 5, 'bar', { baz : { a : 1, b : 2 } } ]
+ [ 'foo', 5, 'bar', { baz : { a : 1, b : 2, c : 3, d : 4 } } ]
);
t.end();
});

0 comments on commit 0eb7143

Please sign in to comment.