Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
rickyes committed Jul 8, 2020
commit 97ee87b08fb60dfaf07f9920a269dd5a78d48805
58 changes: 58 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,43 @@ const net = require('net');
}));
}

// Set destroyDestOnError is false with 3 streams
{
const server = http.createServer(common.mustCall((req, res) => {
const r = fs.createReadStream('./notfound');
const transform = new PassThrough();
pipeline(r, transform, res, { destroyDestOnError: false }, common.mustCall((err) => {
assert.ok(!res.destroyed);
assert.ok(r.destroyed);
assert.ok(transform.destroyed);
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.message,
'ENOENT: no such file or directory, ' +
'open \'./notfound\'');
res.end(err.message);
}));
}));

server.listen(0, common.mustCall(() => {
http.request({
port: server.address().port
}, common.mustCall((res) => {
res.setEncoding('utf8');
let responseData = '';
res.on('data', (chunk) => { responseData += chunk; });
res.on('end', common.mustCall(() => {
assert.strictEqual(responseData,
'ENOENT: no such file or directory, ' +
'open \'./notfound\'');
setImmediate(() => {
res.destroy();
server.close();
});
}));
})).end();
}));
}

// Set destroyDestOnError is true
{
let res = '';
Expand Down Expand Up @@ -1307,3 +1344,24 @@ const net = require('net');
assert.strictEqual(res, 'helloworld');
}));
}

// Set destroyDestOnError is true with 3 streams
{
let res = '';
const w = new Writable({
write(chunk, encoding, callback) {
res += chunk;
callback();
}
});
const transform = new PassThrough();
pipeline(function*() {
yield 'hello';
yield 'world';
}(), transform, w, { destroyDestOnError: true }, common.mustCall((err) => {
assert.ok(!err);
assert.ok(w.destroyed);
assert.ok(transform.destroyed);
assert.strictEqual(res, 'helloworld');
}));
}