mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 22:40:57 +00:00

Ensure that the callback of `OutgoingMessage.prototype.write()` is called even when writing empty chunks. Fixes: https://github.com/nodejs/node/issues/22066 PR-URL: https://github.com/nodejs/node/pull/27709 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
38 lines
774 B
JavaScript
38 lines
774 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
// This test ensures that the callback of `OutgoingMessage.prototype.write()` is
|
|
// called also when writing empty chunks.
|
|
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const stream = require('stream');
|
|
|
|
const expected = ['a', 'b', '', Buffer.alloc(0), 'c'];
|
|
const results = [];
|
|
|
|
const writable = new stream.Writable({
|
|
write(chunk, encoding, callback) {
|
|
setImmediate(callback);
|
|
}
|
|
});
|
|
|
|
const res = new http.ServerResponse({
|
|
method: 'GET',
|
|
httpVersionMajor: 1,
|
|
httpVersionMinor: 1
|
|
});
|
|
|
|
res.assignSocket(writable);
|
|
|
|
for (const chunk of expected) {
|
|
res.write(chunk, () => {
|
|
results.push(chunk);
|
|
});
|
|
}
|
|
|
|
res.end(common.mustCall(() => {
|
|
assert.deepStrictEqual(results, expected);
|
|
}));
|