Skip to content

Commit

Permalink
fix test after readable-stream upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Sep 28, 2023
1 parent 86d7f34 commit 53c554a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
32 changes: 24 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const {
PassThrough,
Transform,
finished,
pipeline,
} = require('readable-stream');
const test = require('tape');
const { PassThrough, Transform, finished, pipeline } = require('readable-stream');
// eslint-disable-next-line import/no-unresolved
const ObjMultiplex = require('../dist');

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

// simulate disconnect
setTimeout(() => inTransport.destroy());
setImmediate(() => inTransport.end(null, () => undefined));
});

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

// simulate disconnect
setTimeout(() => inTransport.destroy());
setImmediate(() => inTransport.end(null, () => undefined));
});

test('roundtrip', (t) => {
Expand All @@ -54,7 +59,7 @@ test('roundtrip', (t) => {
},
});

pipeline(outStream, doubler, outStream);
pipeline(outStream, doubler, outStream, () => undefined);

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

// simulate disconnect
setTimeout(() => outTransport.destroy(), 100);
setTimeout(() => outTransport.end(), 100);
});

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

pipeline(inMux, inTransport, outMux, outTransport, inMux);
pipeline(inMux, inTransport, outMux, outTransport, inMux, () => undefined);

return {
inTransport,
Expand All @@ -118,6 +123,17 @@ function basicTestSetup() {

function bufferToEnd(stream, callback) {
const results = [];
finished(stream, (err) => callback(err, results));
stream.on('data', (chunk) => results.push(chunk));
let flushed = false;
function onFinish(err) {
if (flushed) {
return;
}
flushed = true;
callback(err, results);
}
stream.prependListener('close', onFinish);
finished(stream, onFinish);
stream.on('data', (chunk) => {
results.push(chunk);
});
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ ansi-colors@^4.1.1:
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==

ansi-regex@^5.0.0, ansi-regex@^5.0.1:
ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
Expand Down

0 comments on commit 53c554a

Please sign in to comment.