Skip to content

Commit 53c554a

Browse files
committed
fix test after readable-stream upgrade
1 parent 86d7f34 commit 53c554a

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

test/index.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
const {
2+
PassThrough,
3+
Transform,
4+
finished,
5+
pipeline,
6+
} = require('readable-stream');
17
const test = require('tape');
2-
const { PassThrough, Transform, finished, pipeline } = require('readable-stream');
38
// eslint-disable-next-line import/no-unresolved
49
const ObjMultiplex = require('../dist');
510

@@ -18,7 +23,7 @@ test('basic - string', (t) => {
1823
inStream.write('wuurl');
1924

2025
// simulate disconnect
21-
setTimeout(() => inTransport.destroy());
26+
setImmediate(() => inTransport.end(null, () => undefined));
2227
});
2328

2429
test('basic - obj', (t) => {
@@ -39,7 +44,7 @@ test('basic - obj', (t) => {
3944
inStream.write({ message: 'wuurl' });
4045

4146
// simulate disconnect
42-
setTimeout(() => inTransport.destroy());
47+
setImmediate(() => inTransport.end(null, () => undefined));
4348
});
4449

4550
test('roundtrip', (t) => {
@@ -54,7 +59,7 @@ test('roundtrip', (t) => {
5459
},
5560
});
5661

57-
pipeline(outStream, doubler, outStream);
62+
pipeline(outStream, doubler, outStream, () => undefined);
5863

5964
bufferToEnd(inStream, (err, results) => {
6065
t.error(err, 'should not error');
@@ -66,7 +71,7 @@ test('roundtrip', (t) => {
6671
inStream.write(12);
6772

6873
// simulate disconnect
69-
setTimeout(() => outTransport.destroy(), 100);
74+
setTimeout(() => outTransport.end(), 100);
7075
});
7176

7277
test('error on createStream if destroyed', (t) => {
@@ -104,7 +109,7 @@ function basicTestSetup() {
104109
const inStream = inMux.createStream('hello');
105110
const outStream = outMux.createStream('hello');
106111

107-
pipeline(inMux, inTransport, outMux, outTransport, inMux);
112+
pipeline(inMux, inTransport, outMux, outTransport, inMux, () => undefined);
108113

109114
return {
110115
inTransport,
@@ -118,6 +123,17 @@ function basicTestSetup() {
118123

119124
function bufferToEnd(stream, callback) {
120125
const results = [];
121-
finished(stream, (err) => callback(err, results));
122-
stream.on('data', (chunk) => results.push(chunk));
126+
let flushed = false;
127+
function onFinish(err) {
128+
if (flushed) {
129+
return;
130+
}
131+
flushed = true;
132+
callback(err, results);
133+
}
134+
stream.prependListener('close', onFinish);
135+
finished(stream, onFinish);
136+
stream.on('data', (chunk) => {
137+
results.push(chunk);
138+
});
123139
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ ansi-colors@^4.1.1:
338338
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
339339
integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==
340340

341-
ansi-regex@^5.0.0, ansi-regex@^5.0.1:
341+
ansi-regex@^5.0.1:
342342
version "5.0.1"
343343
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
344344
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==

0 commit comments

Comments
 (0)