node/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js
Tobias Nießen 981a1ef0c2
test: use ES6 classes instead of util.inherits
PR-URL: https://github.com/nodejs/node/pull/16938
Backport-PR-URL: https://github.com/nodejs/node/pull/16946
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2017-11-14 16:40:20 +00:00

37 lines
988 B
JavaScript

'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');
const stream = require('stream');
// Verify that when piping a stream to an `OutgoingMessage` (or a type that
// inherits from `OutgoingMessage`), if data is emitted after the
// `OutgoingMessage` was closed - a `write after end` error is raised
class MyStream extends stream {}
const server = http.createServer(common.mustCall(function(req, res) {
const myStream = new MyStream();
myStream.pipe(res);
process.nextTick(common.mustCall(() => {
res.end();
myStream.emit('data', 'some data');
res.on('error', common.mustCall(function(err) {
assert.strictEqual(err.message, 'write after end');
}));
process.nextTick(common.mustCall(() => server.close()));
}));
}));
server.listen(0);
server.on('listening', common.mustCall(function() {
http.request({
port: server.address().port,
method: 'GET',
path: '/'
}).end();
}));