mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Replace `Array.prototype.forEach()` with `for...of` loops across 17 tests in `test/parallel`, so each loop body reads as a plain statement rather than an arrow callback. None of the iterated values are sparse arrays, the one case where `forEach` and `for...of` genuinely differ, so both constructs visit the same elements in the same order. No callback relied on `this`, an early return, or async behaviour, and the number of assertions run in each file is unchanged. Signed-off-by: Phillip Markert <phillip@ephisys.com> PR-URL: https://github.com/nodejs/node/pull/65272 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
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()];
|
|
|
|
|
|
for (const v of vals) {
|
|
const received = common.invalidArgTypeHelper(v);
|
|
assert.throws(
|
|
() => http.request({ hostname: v }),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError',
|
|
message: 'The "options.hostname" property must be of ' +
|
|
'type string or one of undefined or null.' +
|
|
received
|
|
}
|
|
);
|
|
|
|
assert.throws(
|
|
() => http.request({ host: v }),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError',
|
|
message: 'The "options.host" property must be of ' +
|
|
'type string or one of undefined or null.' +
|
|
received
|
|
}
|
|
);
|
|
}
|
|
|
|
// These values are OK and should not throw synchronously.
|
|
// Only testing for 'hostname' validation so ignore connection errors.
|
|
const dontCare = () => {};
|
|
const values = ['', undefined, null];
|
|
for (const v of values) {
|
|
http.request({ hostname: v }).on('error', dontCare).end();
|
|
http.request({ host: v }).on('error', dontCare).end();
|
|
}
|