Skip to content

Commit

Permalink
chore: Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Sep 1, 2022
1 parent f095480 commit 29463b4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 67 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ var maybeTransform = toThrough(readable);

from(['hi', ' ', 'there', ','])
.pipe(maybeTransform)
.pipe(concat(function(result) {
// result.toString() === 'hi there, hello world'
}));
.pipe(
concat(function (result) {
// result.toString() === 'hi there, hello world'
})
);
```

## API
Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function forward(chunk, enc, cb) {
}

function toThrough(readable) {

var opts = {
objectMode: readable._readableState.objectMode,
highWaterMark: readable._readableState.highWaterMark,
Expand Down
86 changes: 23 additions & 63 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,54 @@ var from = miss.from;
var pipe = miss.pipe;
var concat = miss.concat;

describe('toThrough (buffer mode)', function() {

describe('toThrough (buffer mode)', function () {
// These tests ensure it automatically detects buffer mode

var preContents = ['from', ' ', 'upstream', ' '];
var contents = ['hello', ' ', 'world', ' ', '123'];

it('can wrap a Readable and be used as a Readable', function(done) {
it('can wrap a Readable and be used as a Readable', function (done) {
var readable = from(contents);

function assert(result) {
expect(result.toString()).toEqual(contents.join(''));
}

pipe([
toThrough(readable),
concat(assert),
], done);
pipe([toThrough(readable), concat(assert)], done);
});

it('can wrap a Readable and be used as a Transform', function(done) {
it('can wrap a Readable and be used as a Transform', function (done) {
var readable = from(contents);

function assert(result) {
expect(result.toString()).toEqual(contents.join(''));
}

pipe([
from([]),
toThrough(readable),
concat(assert),
], done);
pipe([from([]), toThrough(readable), concat(assert)], done);
});

it('passes through all upstream before readable', function(done) {
it('passes through all upstream before readable', function (done) {
var readable = from(contents);

function assert(result) {
expect(result.toString()).toEqual(preContents.concat(contents).join(''));
}

pipe([
from(preContents),
toThrough(readable),
concat(assert),
], done);
pipe([from(preContents), toThrough(readable), concat(assert)], done);
});

it('re-emits errors from readable', function(done) {
it('re-emits errors from readable', function (done) {
var readable = from([new Error('boom')]);

function assert(err) {
expect(err.message).toEqual('boom');
done();
}

pipe([
from(preContents),
toThrough(readable),
concat(),
], assert);
pipe([from(preContents), toThrough(readable), concat()], assert);
});

it('does not flush the stream if not piped before nextTick', function(done) {
it('does not flush the stream if not piped before nextTick', function (done) {
var readable = from(contents);

var wrapped = toThrough(readable);
Expand All @@ -82,25 +66,16 @@ describe('toThrough (buffer mode)', function() {
expect(result.toString()).toEqual(preContents.concat(contents).join(''));
}

process.nextTick(function() {
pipe([
from(preContents),
wrapped,
concat(assert),
], done);
process.nextTick(function () {
pipe([from(preContents), wrapped, concat(assert)], done);
});
});
});

describe('toThrough (object mode)', function() {

describe('toThrough (object mode)', function () {
// These tests ensure it automatically detects objectMode

var preContents = [
{ value: -2 },
{ value: -1 },
{ value: 0 },
];
var preContents = [{ value: -2 }, { value: -1 }, { value: 0 }];
var contents = [
{ value: 1 },
{ value: 2 },
Expand All @@ -124,48 +99,37 @@ describe('toThrough (object mode)', function() {
{ value: 20 },
];

it('can wrap a Readable and be used as a Readable', function(done) {
it('can wrap a Readable and be used as a Readable', function (done) {
var readable = from.obj(contents);

function assert(result) {
expect(result).toEqual(contents);
}

pipe([
toThrough(readable),
concat(assert),
], done);
pipe([toThrough(readable), concat(assert)], done);
});

it('can wrap a Readable and be used as a Transform', function(done) {
it('can wrap a Readable and be used as a Transform', function (done) {
var readable = from.obj(contents);

function assert(result) {
expect(result).toEqual(contents);
}

pipe([
from.obj([]),
toThrough(readable),
concat(assert),
], done);
pipe([from.obj([]), toThrough(readable), concat(assert)], done);
});

it('passes through all upstream before readable', function(done) {
it('passes through all upstream before readable', function (done) {
var readable = from.obj(contents);

function assert(result) {
expect(result).toEqual(preContents.concat(contents));
}

pipe([
from.obj(preContents),
toThrough(readable),
concat(assert),
], done);
pipe([from.obj(preContents), toThrough(readable), concat(assert)], done);
});

it('does not flush the stream if not piped before nextTick', function(done) {
it('does not flush the stream if not piped before nextTick', function (done) {
var readable = from.obj(contents);

var wrapped = toThrough(readable);
Expand All @@ -174,12 +138,8 @@ describe('toThrough (object mode)', function() {
expect(result).toEqual(preContents.concat(contents));
}

process.nextTick(function() {
pipe([
from.obj(preContents),
wrapped,
concat(assert),
], done);
process.nextTick(function () {
pipe([from.obj(preContents), wrapped, concat(assert)], done);
});
});
});

0 comments on commit 29463b4

Please sign in to comment.