Skip to content

Commit

Permalink
Build: Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored and actions-user committed Apr 28, 2020
1 parent 25f3090 commit 5a2e6b2
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 86 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ var through = require('through2');
var sink = require('lead');

// Might be used as a Transform or Writeable
var maybeThrough = through(function(chunk, enc, cb) {
var maybeThrough = through(function (chunk, enc, cb) {
// processing
cb(null, chunk);
});

from(['hello', 'world'])
// Sink it to behave like a Writeable
.pipe(sink(maybeThrough))
.pipe(sink(maybeThrough));
```

## API
Expand Down
185 changes: 101 additions & 84 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,37 @@ function noop() {}

function count(value) {
var count = 0;
return through.obj(function(file, enc, cb) {
count++;
cb(null, file);
}, function(cb) {
expect(count).toEqual(value);
cb();
});
return through.obj(
function (file, enc, cb) {
count++;
cb(null, file);
},
function (cb) {
expect(count).toEqual(value);
cb();
}
);
}

function slowCount(value) {
var count = 0;
return to.obj(function(file, enc, cb) {
count++;

setTimeout(function() {
cb(null, file);
}, 250);
}, function(cb) {
expect(count).toEqual(value);
cb();
});
return to.obj(
function (file, enc, cb) {
count++;

setTimeout(function () {
cb(null, file);
}, 250);
},
function (cb) {
expect(count).toEqual(value);
cb();
}
);
}

describe('lead', function() {

it('respects objectMode of wrapped stream', function(done) {
describe('lead', function () {
it('respects objectMode of wrapped stream', function (done) {
var write = sink(through());

function assert(err) {
Expand All @@ -48,15 +53,18 @@ describe('lead', function() {
done();
}

pipe([
from.obj([{}]),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
], assert);
pipe(
[
from.obj([{}]),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
],
assert
);
});

it('does not get clogged by highWaterMark', function(done) {
it('does not get clogged by highWaterMark', function (done) {
var expectedCount = 17;
var highwatermarkObjs = [];
for (var idx = 0; idx < expectedCount; idx++) {
Expand All @@ -65,16 +73,19 @@ describe('lead', function() {

var write = sink(through.obj());

pipe([
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
], done);
pipe(
[
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
],
done
);
});

it('allows backpressure when piped to another, slower stream', function(done) {
it('allows backpressure when piped to another, slower stream', function (done) {
this.timeout(20000);

var expectedCount = 24;
Expand All @@ -85,19 +96,22 @@ describe('lead', function() {

var write = sink(through.obj());

pipe([
from.obj(highwatermarkObjs),
count(expectedCount),
write,
slowCount(expectedCount),
], done);
pipe(
[
from.obj(highwatermarkObjs),
count(expectedCount),
write,
slowCount(expectedCount),
],
done
);
});

it('respects readable listeners on wrapped stream', function(done) {
it('respects readable listeners on wrapped stream', function (done) {
var write = sink(through.obj());

var readables = 0;
write.on('readable', function() {
write.on('readable', function () {
while (write.read()) {
readables++;
}
Expand All @@ -108,17 +122,14 @@ describe('lead', function() {
done(err);
}

pipe([
from.obj([{}]),
write,
], assert);
pipe([from.obj([{}]), write], assert);
});

it('respects data listeners on wrapped stream', function(done) {
it('respects data listeners on wrapped stream', function (done) {
var write = sink(through.obj());

var datas = 0;
write.on('data', function() {
write.on('data', function () {
datas++;
});

Expand All @@ -127,13 +138,10 @@ describe('lead', function() {
done(err);
}

pipe([
from.obj([{}]),
write,
], assert);
pipe([from.obj([{}]), write], assert);
});

it('sinks the stream if all the readable event handlers are removed', function(done) {
it('sinks the stream if all the readable event handlers are removed', function (done) {
var expectedCount = 17;
var highwatermarkObjs = [];
for (var idx = 0; idx < expectedCount; idx++) {
Expand All @@ -144,20 +152,23 @@ describe('lead', function() {

write.on('readable', noop);

pipe([
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
], done);

process.nextTick(function() {
pipe(
[
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
],
done
);

process.nextTick(function () {
write.removeListener('readable', noop);
});
});

it('does not sink the stream if an event handler still exists when one is removed', function(done) {
it('does not sink the stream if an event handler still exists when one is removed', function (done) {
var expectedCount = 17;
var highwatermarkObjs = [];
for (var idx = 0; idx < expectedCount; idx++) {
Expand All @@ -168,7 +179,7 @@ describe('lead', function() {

write.on('readable', noop);
var readables = 0;
write.on('readable', function() {
write.on('readable', function () {
while (write.read()) {
readables++;
}
Expand All @@ -179,20 +190,23 @@ describe('lead', function() {
done(err);
}

pipe([
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
], assert);

process.nextTick(function() {
pipe(
[
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
],
assert
);

process.nextTick(function () {
write.removeListener('readable', noop);
});
});

it('sinks the stream if all the data event handlers are removed', function(done) {
it('sinks the stream if all the data event handlers are removed', function (done) {
var expectedCount = 17;
var highwatermarkObjs = [];
for (var idx = 0; idx < expectedCount; idx++) {
Expand All @@ -203,15 +217,18 @@ describe('lead', function() {

write.on('data', noop);

pipe([
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
], done);

process.nextTick(function() {
pipe(
[
from.obj(highwatermarkObjs),
count(expectedCount),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
],
done
);

process.nextTick(function () {
write.removeListener('data', noop);
});
});
Expand Down

0 comments on commit 5a2e6b2

Please sign in to comment.