github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/sample-apps/node/node_modules/logfmt/test/stream_stringify_test.js (about) 1 var logfmt = require('../logfmt'), 2 through = require('through'), 3 stream = require('stream'), 4 assert = require('assert'); 5 6 //avoid test bleeding 7 var logfmt = new logfmt; 8 9 suite('logfmt.streamStringify', function() { 10 test("stringifies all the objects", function(done){ 11 var s = new stream.PassThrough({objectMode: true}); 12 13 s.push({hello: 'kitty'}); 14 s.push({foo: 'bar'}); 15 s.push({path: '/'}); 16 s.push(null); 17 var matches = ['path=/\n', 'foo=bar\n', 'hello=kitty\n']; 18 s.pipe(logfmt.streamStringify()).pipe(through(function(data){ 19 assert.equal(data, matches.pop()) 20 },function(){ 21 done() 22 })) 23 }) 24 25 test("accepts a delimiter", function(done){ 26 var s = new stream.PassThrough({objectMode: true}); 27 28 s.push({hello: 'kitty'}); 29 s.push({foo: 'bar'}); 30 s.push({path: '/'}); 31 s.push(null); 32 var matches = ['path=/', 'foo=bar', 'hello=kitty']; 33 s.pipe(logfmt.streamStringify({delimiter: ''})).pipe(through(function(data){ 34 assert.equal(data, matches.pop()) 35 },function(){ 36 done() 37 })) 38 }) 39 })