mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 10:27:12 +00:00

This test would currently create HTTP requests to localhost:80 and would time out on machines that actually had an server listening there. To address that, `end()` the requests that are generated. PR-URL: https://github.com/nodejs/node/pull/12627 Ref: https://github.com/nodejs/node/pull/12494 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
28 lines
925 B
JavaScript
28 lines
925 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
// All of these values should cause http.request() to throw synchronously
|
|
// when passed as the value of either options.hostname or options.host
|
|
const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];
|
|
|
|
function errCheck(name) {
|
|
return new RegExp(`^TypeError: "options\\.${name}" must either be a ` +
|
|
'string, undefined or null$');
|
|
}
|
|
|
|
vals.forEach((v) => {
|
|
assert.throws(() => http.request({hostname: v}), errCheck('hostname'));
|
|
assert.throws(() => http.request({host: v}), errCheck('host'));
|
|
});
|
|
|
|
// These values are OK and should not throw synchronously
|
|
['', undefined, null].forEach((v) => {
|
|
assert.doesNotThrow(() => {
|
|
http.request({hostname: v}).on('error', common.noop).end();
|
|
http.request({host: v}).on('error', common.noop).end();
|
|
});
|
|
});
|