Skip to content

Commit 0666f7b

Browse files
committed
wip: fix test after readable-stream upgrade
1 parent 86d7f34 commit 0666f7b

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

test/index.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const test = require('tape');
21
const { PassThrough, Transform, finished, pipeline } = require('readable-stream');
2+
const test = require('tape');
33
// eslint-disable-next-line import/no-unresolved
44
const ObjMultiplex = require('../dist');
55

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

2020
// simulate disconnect
21-
setTimeout(() => inTransport.destroy());
21+
setImmediate(() => inTransport.end(null, () => {}));
2222
});
2323

2424
test('basic - obj', (t) => {
@@ -39,7 +39,7 @@ test('basic - obj', (t) => {
3939
inStream.write({ message: 'wuurl' });
4040

4141
// simulate disconnect
42-
setTimeout(() => inTransport.destroy());
42+
setImmediate(() => inTransport.end(null, () => {}));
4343
});
4444

4545
test('roundtrip', (t) => {
@@ -54,7 +54,7 @@ test('roundtrip', (t) => {
5454
},
5555
});
5656

57-
pipeline(outStream, doubler, outStream);
57+
pipeline(outStream, doubler, outStream, () => {});
5858

5959
bufferToEnd(inStream, (err, results) => {
6060
t.error(err, 'should not error');
@@ -66,7 +66,7 @@ test('roundtrip', (t) => {
6666
inStream.write(12);
6767

6868
// simulate disconnect
69-
setTimeout(() => outTransport.destroy(), 100);
69+
setTimeout(() => outTransport.end(), 100);
7070
});
7171

7272
test('error on createStream if destroyed', (t) => {
@@ -104,7 +104,7 @@ function basicTestSetup() {
104104
const inStream = inMux.createStream('hello');
105105
const outStream = outMux.createStream('hello');
106106

107-
pipeline(inMux, inTransport, outMux, outTransport, inMux);
107+
pipeline(inMux, inTransport, outMux, outTransport, inMux, () => {});
108108

109109
return {
110110
inTransport,
@@ -118,6 +118,20 @@ function basicTestSetup() {
118118

119119
function bufferToEnd(stream, callback) {
120120
const results = [];
121-
finished(stream, (err) => callback(err, results));
122-
stream.on('data', (chunk) => results.push(chunk));
121+
let flushed = false;
122+
function onFinish(err) {
123+
if (flushed) {
124+
return;
125+
}
126+
flushed = true;
127+
return callback(err, results);
128+
}
129+
stream.prependListener('abort', onFinish);
130+
stream.prependListener('close', onFinish);
131+
stream.prependListener('error', onFinish);
132+
stream.prependListener('finish', onFinish);
133+
finished(stream, onFinish);
134+
stream.on('data', (chunk) => {
135+
results.push(chunk);
136+
});
123137
}

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)