0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-information-processing.js
Rich Trott 83ebd77318 test: replace console.error() with debuglog calls
Somehow thought I did this in 8905be2cee
but clearly did not.

PR-URL: https://github.com/nodejs/node/pull/32588
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
2020-04-03 02:42:24 -07:00

51 lines
1.3 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const http = require('http');
const debug = require('util').debuglog('test');
const testResBody = 'other stuff!\n';
const kMessageCount = 2;
const server = http.createServer((req, res) => {
for (let i = 0; i < kMessageCount; i++) {
debug(`Server sending informational message #${i}...`);
res.writeProcessing();
}
debug('Server sending full response...');
res.writeHead(200, {
'Content-Type': 'text/plain',
'ABCD': '1'
});
res.end(testResBody);
});
server.listen(0, function() {
const req = http.request({
port: this.address().port,
path: '/world'
});
req.end();
debug('Client sending request...');
let body = '';
let infoCount = 0;
req.on('information', () => { infoCount++; });
req.on('response', function(res) {
// Check that all 102 Processing received before full response received.
assert.strictEqual(infoCount, kMessageCount);
assert.strictEqual(res.statusCode, 200,
`Final status code was ${res.statusCode}, not 200.`);
res.setEncoding('utf8');
res.on('data', function(chunk) { body += chunk; });
res.on('end', function() {
debug('Got full response.');
assert.strictEqual(body, testResBody);
assert.ok('abcd' in res.headers);
server.close();
});
});
});