node-stream
Advanced tools
Comparing version 0.0.3 to 0.0.4
/* jshint node:true */ | ||
var first = require('./lib/first.js'); | ||
var firstObj = require('./lib/firstObj.js'); | ||
var firstJson = require('./lib/firstJson.js'); | ||
var forEach = require('./lib/forEach.js'); | ||
@@ -11,2 +15,5 @@ var forEachObj = require('./lib/forEachObj.js'); | ||
first.obj = firstObj; | ||
first.json = firstJson; | ||
forEach.obj = forEachObj; | ||
@@ -19,4 +26,5 @@ forEach.json = forEachJson; | ||
module.exports = { | ||
first: first, | ||
forEach: forEach, | ||
wait: wait | ||
}; |
{ | ||
"name": "node-stream", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Utilities for working with node streams.", | ||
@@ -30,3 +30,3 @@ "main": "index.js", | ||
"codeclimate-test-reporter": "^0.3.1", | ||
"grandma": "0.0.15", | ||
"grandma": "0.0.16", | ||
"istanbul": "^0.4.3", | ||
@@ -33,0 +33,0 @@ "lodash": "^4.12.0", |
/* jshint node:true */ | ||
var stream = require('stream'); | ||
var _ = require('lodash'); | ||
var structure = require('./_utilities/structure.js'); | ||
var forEach = require('../index.js').forEach; | ||
var data = ['item1', 'item2', 'item3', 'item4']; | ||
function getReadableStream() { | ||
var readableStream = new stream.Readable(); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
return readableStream; | ||
} | ||
module.exports = { | ||
beforeEach: function(done) { | ||
this.stream = getReadableStream(); | ||
done(); | ||
}, | ||
module.exports = structure(data, { | ||
test: function(done) { | ||
forEach(this.stream, _.noop, done); | ||
} | ||
}; | ||
}); |
/* jshint node:true */ | ||
var stream = require('stream'); | ||
var _ = require('lodash'); | ||
var structure = require('./_utilities/structure.js'); | ||
var forEachJson = require('../index.js').forEach.json; | ||
var data = ['{"item1":"json"}', '{"item2":"json"}', '{"item3":"json"}']; | ||
function getReadableStream() { | ||
var readableStream = new stream.Readable(); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
return readableStream; | ||
} | ||
module.exports = { | ||
beforeEach: function(done) { | ||
this.stream = getReadableStream(); | ||
done(); | ||
}, | ||
module.exports = structure(data, { | ||
test: function(done) { | ||
forEachJson(this.stream, _.noop, done); | ||
} | ||
}; | ||
}); |
/* jshint node:true */ | ||
var stream = require('stream'); | ||
var _ = require('lodash'); | ||
var structure = require('./_utilities/structure.js'); | ||
var forEachObj = require('../index.js').forEach.obj; | ||
var data = ['item1', 'item2', 'item3', 'item4']; | ||
function getReadableStream() { | ||
var readableStream = new stream.Readable(); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
return readableStream; | ||
} | ||
module.exports = { | ||
beforeEach: function(done) { | ||
this.stream = getReadableStream(); | ||
done(); | ||
}, | ||
module.exports = structure(data, { | ||
test: function(done) { | ||
forEachObj(this.stream, _.noop, done); | ||
} | ||
}; | ||
}); |
/* jshint node:true */ | ||
var stream = require('stream'); | ||
var structure = require('./_utilities/structure.js'); | ||
var wait = require('../index.js').wait; | ||
var data = ['item1', 'item2', 'item3', 'item4']; | ||
function getReadableStream() { | ||
var readableStream = new stream.Readable(); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
return readableStream; | ||
} | ||
module.exports = { | ||
beforeEach: function(done) { | ||
this.stream = getReadableStream(); | ||
done(); | ||
}, | ||
module.exports = structure(data, { | ||
test: function(done) { | ||
wait(this.stream, done); | ||
} | ||
}; | ||
}); |
/* jshint node:true */ | ||
var stream = require('stream'); | ||
var structure = require('./_utilities/structure.js'); | ||
var waitJson = require('../index.js').wait.json; | ||
var data = ['[', '{"item1":"json"}', ',{"item2":"json"}', ',{"item3":"json"}', ']']; | ||
function getReadableStream() { | ||
var readableStream = new stream.Readable(); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
return readableStream; | ||
} | ||
module.exports = { | ||
beforeEach: function(done) { | ||
this.stream = getReadableStream(); | ||
done(); | ||
}, | ||
module.exports = structure(data, { | ||
test: function(done) { | ||
waitJson(this.stream, done); | ||
} | ||
}; | ||
}); |
/* jshint node:true */ | ||
var stream = require('stream'); | ||
var structure = require('./_utilities/structure.js'); | ||
var waitObj = require('../index.js').wait.obj; | ||
var data = ['item1', 'item2', 'item3', 'item4']; | ||
function getReadableStream() { | ||
var readableStream = new stream.Readable(); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
return readableStream; | ||
} | ||
module.exports = { | ||
beforeEach: function(done) { | ||
this.stream = getReadableStream(); | ||
done(); | ||
}, | ||
module.exports = structure(data, { | ||
test: function(done) { | ||
waitObj(this.stream, done); | ||
} | ||
}; | ||
}); |
@@ -31,2 +31,5 @@ #node-stream | ||
* [`first`](#first) | ||
* [`first.obj`](#firstObj) | ||
* [`first.json`](#firstJson) | ||
* [`forEach`](#forEach) | ||
@@ -39,2 +42,44 @@ * [`forEach.obj`](#forEachObj) | ||
<a name="first"></a> | ||
### first(stream, onEnd) | ||
Consume the first item in a stream and call a callback with a buffer of that item. | ||
```js | ||
nodeStream.first( | ||
stream, | ||
function(err, data) { | ||
// err is null or an Error object | ||
// data is a Buffer object | ||
} | ||
); | ||
``` | ||
<a name="firstObj"></a> | ||
### first.obj(stream, onEnd) | ||
Consume the first item in a stream and call a callback with that item. | ||
```js | ||
nodeStream.first.obj( | ||
stream, | ||
function(err, data) { | ||
// err is null or an Error object | ||
// data is an array | ||
} | ||
); | ||
``` | ||
<a name="firstJson"></a> | ||
### first.json(stream, onEnd) | ||
Consume the first item in a stream and call a callback with a JSON parsed object. Stream will error if the consumed data is not parseable. | ||
```js | ||
nodeStream.first.json( | ||
stream, | ||
function(err, data) { | ||
// err is null or an Error object | ||
// data is a JSON parsed object | ||
} | ||
); | ||
``` | ||
<a name="forEach"></a> | ||
@@ -41,0 +86,0 @@ ### forEach(stream, onData, onEnd) |
/* jshint node:true, mocha: true */ | ||
var stream = require('stream'); | ||
var _ = require('lodash'); | ||
var expect = require('chai').expect; | ||
var getReadableStream = require('./_utilities/getReadableStream.js'); | ||
var getDuplexStream = require('./_utilities/getDuplexStream.js'); | ||
var forEach = require('../lib/forEach.js'); | ||
@@ -33,16 +35,4 @@ | ||
it('iterates through a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -52,18 +42,6 @@ }); | ||
it('iterates through a Readable object stream', function(done) { | ||
var readableStream = new stream.Readable({ | ||
var readableStream = getReadableStream(data, { | ||
objectMode: true | ||
}); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -73,16 +51,4 @@ }); | ||
it('returns an error for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data.concat([12])); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
forEach(readableStream, _.noop, function(err) { | ||
@@ -97,16 +63,4 @@ expect(arguments).to.have.length(1); | ||
it('iterates through a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -116,18 +70,6 @@ }); | ||
it('iterates through a Duplex object stream', function(done) { | ||
var duplexStream = new stream.Duplex({ | ||
var duplexStream = getDuplexStream(data, { | ||
objectMode: true | ||
}); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -137,16 +79,4 @@ }); | ||
it('returns an error for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data.concat([12])); | ||
duplexStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
forEach(duplexStream, _.noop, function(err) { | ||
@@ -153,0 +83,0 @@ expect(arguments).to.have.length(1); |
/* jshint node:true, mocha: true */ | ||
var stream = require('stream'); | ||
var _ = require('lodash'); | ||
var expect = require('chai').expect; | ||
var getReadableStream = require('./_utilities/getReadableStream.js'); | ||
var getDuplexStream = require('./_utilities/getDuplexStream.js'); | ||
var forEachJson = require('../lib/forEachJson.js'); | ||
@@ -33,16 +35,4 @@ | ||
it('iterates through a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -52,18 +42,6 @@ }); | ||
it('iterates through a Readable object stream', function(done) { | ||
var readableStream = new stream.Readable({ | ||
var readableStream = getReadableStream(data, { | ||
objectMode: true | ||
}); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -73,15 +51,14 @@ }); | ||
it('returns an error for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data.concat([12])); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat(['{"non":"json}']); | ||
forEachJson(readableStream, _.noop, function(err) { | ||
expect(arguments).to.have.length(1); | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.equal('Invalid non-string/buffer chunk'); | ||
done(); | ||
}); | ||
}); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
it('returns an error for invalid JSON on a Readable stream', function(done) { | ||
var readableStream = getReadableStream(data.concat(['{"non":"json}'])); | ||
@@ -91,2 +68,3 @@ forEachJson(readableStream, _.noop, function(err) { | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.match(/^Unexpected end of(?: JSON)? input$/); | ||
done(); | ||
@@ -97,16 +75,4 @@ }); | ||
it('iterates through a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -116,18 +82,6 @@ }); | ||
it('iterates through a Duplex object stream', function(done) { | ||
var duplexStream = new stream.Duplex({ | ||
var duplexStream = getDuplexStream(data, { | ||
objectMode: true | ||
}); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -137,15 +91,14 @@ }); | ||
it('returns an error for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data.concat([12])); | ||
duplexStream._read = (function() { | ||
var d = data.slice().concat(['{"non":"json}']); | ||
forEachJson(duplexStream, _.noop, function(err) { | ||
expect(arguments).to.have.length(1); | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.equal('Invalid non-string/buffer chunk'); | ||
done(); | ||
}); | ||
}); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
it('returns an error for a invalid JSON on a Duplex stream', function(done) { | ||
var duplexStream = getDuplexStream(data.concat(['{"non":"json}'])); | ||
@@ -155,2 +108,3 @@ forEachJson(duplexStream, _.noop, function(err) { | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.match(/^Unexpected end of(?: JSON)? input$/); | ||
done(); | ||
@@ -157,0 +111,0 @@ }); |
/* jshint node:true, mocha: true */ | ||
var stream = require('stream'); | ||
var _ = require('lodash'); | ||
var expect = require('chai').expect; | ||
var getReadableStream = require('./_utilities/getReadableStream.js'); | ||
var getDuplexStream = require('./_utilities/getDuplexStream.js'); | ||
var forEachObj = require('../lib/forEachObj.js'); | ||
@@ -43,16 +45,4 @@ | ||
it('iterates through a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, false, done); | ||
@@ -62,18 +52,6 @@ }); | ||
it('iterates through a Readable object stream', function(done) { | ||
var readableStream = new stream.Readable({ | ||
var readableStream = getReadableStream(objData, { | ||
objectMode: true | ||
}); | ||
readableStream._read = (function() { | ||
var d = objData.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, true, done); | ||
@@ -83,16 +61,4 @@ }); | ||
it('returns an error for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data.concat([12])); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
forEachObj(readableStream, _.noop, function(err) { | ||
@@ -107,16 +73,4 @@ expect(arguments).to.have.length(1); | ||
it('iterates through a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, false, done); | ||
@@ -126,18 +80,6 @@ }); | ||
it('iterates through a Duplex object stream', function(done) { | ||
var duplexStream = new stream.Duplex({ | ||
var duplexStream = getDuplexStream(objData, { | ||
objectMode: true | ||
}); | ||
duplexStream._read = (function() { | ||
var d = objData.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, true, done); | ||
@@ -147,16 +89,4 @@ }); | ||
it('returns an error for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data.concat([12])); | ||
duplexStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
forEachObj(duplexStream, _.noop, function(err) { | ||
@@ -163,0 +93,0 @@ expect(arguments).to.have.length(1); |
@@ -11,15 +11,15 @@ /* jshint node:true, mocha: true */ | ||
expect(index).to.be.an('object') | ||
.and.to.have.all.keys('wait', 'forEach'); | ||
.and.to.have.all.keys('first', 'forEach', 'wait'); | ||
expect(index.wait).to.be.a('function') | ||
expect(index.first).to.be.a('function') | ||
.and.to.have.length(2) | ||
.and.to.have.all.keys('obj', 'json'); | ||
expect(index.wait.obj).to.be.a('function') | ||
expect(index.first.obj).to.be.a('function') | ||
.and.to.have.length(2); | ||
expect(_.keys(index.wait.obj)).to.have.length(0); | ||
expect(_.keys(index.first.obj)).to.have.length(0); | ||
expect(index.wait.json).to.be.a('function') | ||
expect(index.first.json).to.be.a('function') | ||
.and.to.have.length(2); | ||
expect(_.keys(index.wait.json)).to.have.length(0); | ||
expect(_.keys(index.first.json)).to.have.length(0); | ||
@@ -37,3 +37,15 @@ expect(index.forEach).to.be.a('function') | ||
expect(_.keys(index.forEach.json)).to.have.length(0); | ||
expect(index.wait).to.be.a('function') | ||
.and.to.have.length(2) | ||
.and.to.have.all.keys('obj', 'json'); | ||
expect(index.wait.obj).to.be.a('function') | ||
.and.to.have.length(2); | ||
expect(_.keys(index.wait.obj)).to.have.length(0); | ||
expect(index.wait.json).to.be.a('function') | ||
.and.to.have.length(2); | ||
expect(_.keys(index.wait.json)).to.have.length(0); | ||
}); | ||
}); |
/* jshint node:true, mocha: true */ | ||
var stream = require('stream'); | ||
var expect = require('chai').expect; | ||
var getReadableStream = require('./_utilities/getReadableStream.js'); | ||
var getDuplexStream = require('./_utilities/getDuplexStream.js'); | ||
var wait = require('../lib/wait.js'); | ||
@@ -29,16 +31,4 @@ | ||
it('waits for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -48,18 +38,6 @@ }); | ||
it('waits for a Readable object stream', function(done) { | ||
var readableStream = new stream.Readable({ | ||
var readableStream = getReadableStream(data, { | ||
objectMode: true | ||
}); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -69,16 +47,4 @@ }); | ||
it('returns an error for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data.concat([12])); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
wait(readableStream, function(err) { | ||
@@ -93,16 +59,4 @@ expect(arguments).to.have.length(1); | ||
it('waits for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -112,18 +66,6 @@ }); | ||
it('waits for a Duplex object stream', function(done) { | ||
var duplexStream = new stream.Duplex({ | ||
var duplexStream = getDuplexStream(data, { | ||
objectMode: true | ||
}); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -133,16 +75,4 @@ }); | ||
it('returns an error for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data.concat([12])); | ||
duplexStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
wait(duplexStream, function(err) { | ||
@@ -149,0 +79,0 @@ expect(arguments).to.have.length(1); |
/* jshint node:true, mocha: true */ | ||
var stream = require('stream'); | ||
var expect = require('chai').expect; | ||
var getReadableStream = require('./_utilities/getReadableStream.js'); | ||
var getDuplexStream = require('./_utilities/getDuplexStream.js'); | ||
var waitJson = require('../lib/waitJson.js'); | ||
@@ -29,16 +31,4 @@ | ||
it('waits for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -48,18 +38,6 @@ }); | ||
it('waits for a Readable object stream', function(done) { | ||
var readableStream = new stream.Readable({ | ||
var readableStream = getReadableStream(data, { | ||
objectMode: true | ||
}); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, done); | ||
@@ -69,15 +47,14 @@ }); | ||
it('returns an error for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data.concat([12])); | ||
readableStream._read = (function() { | ||
var d = data.slice(0, -1).concat([',{"non":"json}', ']']); | ||
waitJson(readableStream, function(err) { | ||
expect(arguments).to.have.length(1); | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.equal('Invalid non-string/buffer chunk'); | ||
done(); | ||
}); | ||
}); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
it('returns an error for invalid JSON on a Readable stream', function(done) { | ||
var readableStream = getReadableStream(data.slice(0, -1).concat([',{"non":"json}', ']'])); | ||
@@ -87,2 +64,3 @@ waitJson(readableStream, function(err) { | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.match(/^Unexpected end of(?: JSON)? input$/); | ||
done(); | ||
@@ -93,16 +71,4 @@ }); | ||
it('waits for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -112,18 +78,6 @@ }); | ||
it('waits for a Duplex object stream', function(done) { | ||
var duplexStream = new stream.Duplex({ | ||
var duplexStream = getDuplexStream(data, { | ||
objectMode: true | ||
}); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, done); | ||
@@ -133,15 +87,14 @@ }); | ||
it('returns an error for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data.concat([12])); | ||
duplexStream._read = (function() { | ||
var d = data.slice(0, -1).concat([',{"non":"json}', ']']); | ||
waitJson(duplexStream, function(err) { | ||
expect(arguments).to.have.length(1); | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.equal('Invalid non-string/buffer chunk'); | ||
done(); | ||
}); | ||
}); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
it('returns an error for invalid JSON on a Duplex stream', function(done) { | ||
var duplexStream = getDuplexStream(data.slice(0, -1).concat([',{"non":"json}', ']'])); | ||
@@ -151,2 +104,3 @@ waitJson(duplexStream, function(err) { | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.match(/^Unexpected end of(?: JSON)? input$/); | ||
done(); | ||
@@ -153,0 +107,0 @@ }); |
/* jshint node:true, mocha: true */ | ||
var stream = require('stream'); | ||
var expect = require('chai').expect; | ||
var getReadableStream = require('./_utilities/getReadableStream.js'); | ||
var getDuplexStream = require('./_utilities/getDuplexStream.js'); | ||
var waitObj = require('../lib/waitObj.js'); | ||
@@ -33,16 +35,4 @@ | ||
it('waits for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data); | ||
readableStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, false, done); | ||
@@ -52,18 +42,6 @@ }); | ||
it('waits for a Readable object stream', function(done) { | ||
var readableStream = new stream.Readable({ | ||
var readableStream = getReadableStream(objData, { | ||
objectMode: true | ||
}); | ||
readableStream._read = (function() { | ||
var d = objData.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(readableStream, true, done); | ||
@@ -73,16 +51,4 @@ }); | ||
it('returns an error for a Readable stream', function(done) { | ||
var readableStream = new stream.Readable(); | ||
var readableStream = getReadableStream(data.concat([12])); | ||
readableStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
waitObj(readableStream, function(err) { | ||
@@ -97,16 +63,4 @@ expect(arguments).to.have.length(1); | ||
it('waits for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data); | ||
duplexStream._read = (function() { | ||
var d = data.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, false, done); | ||
@@ -116,18 +70,6 @@ }); | ||
it('waits for a Duplex object stream', function(done) { | ||
var duplexStream = new stream.Duplex({ | ||
var duplexStream = getDuplexStream(objData, { | ||
objectMode: true | ||
}); | ||
duplexStream._read = (function() { | ||
var d = objData.slice(); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
runTest(duplexStream, true, done); | ||
@@ -137,16 +79,4 @@ }); | ||
it('returns an error for a Duplex stream', function(done) { | ||
var duplexStream = new stream.Duplex(); | ||
var duplexStream = getDuplexStream(data.concat([12])); | ||
duplexStream._read = (function() { | ||
var d = data.slice().concat([12]); | ||
return function() { | ||
if (d.length > 0) { | ||
this.push(d.shift()); | ||
} else { | ||
this.push(null); | ||
} | ||
}; | ||
})(); | ||
waitObj(duplexStream, function(err) { | ||
@@ -153,0 +83,0 @@ expect(arguments).to.have.length(1); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39572
36
172
890
1