Skip to content

Commit a62345e

Browse files
jasnelladuh95
authored andcommitted
test: move hasMultiLocalhost to common/net
Given that `common/net` already exists and hasMultiLocalhost is net specific, let's move it out of common/index to better encapsulate and simplify common/index more PR-URL: #56716 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6edf04e commit a62345e

7 files changed

+19
-21
lines changed

test/common/README.md

-6
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,6 @@ Indicates if [internationalization][] is supported.
238238

239239
Indicates whether `IPv6` is supported on this platform.
240240

241-
### `hasMultiLocalhost`
242-
243-
* [\<boolean>][<boolean>]
244-
245-
Indicates if there are multiple localhosts available.
246-
247241
### `inFreeBSDJail`
248242

249243
* [\<boolean>][<boolean>]

test/common/index.js

-10
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,6 @@ function _mustCallInner(fn, criteria = 1, field) {
489489
return _return;
490490
}
491491

492-
function hasMultiLocalhost() {
493-
const { internalBinding } = require('internal/test/binding');
494-
const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap');
495-
const t = new TCP(TCPConstants.SOCKET);
496-
const ret = t.bind('127.0.0.2', 0);
497-
t.close();
498-
return ret === 0;
499-
}
500-
501492
function skipIfEslintMissing() {
502493
if (!fs.existsSync(
503494
path.join(__dirname, '..', '..', 'tools', 'eslint', 'node_modules', 'eslint'),
@@ -965,7 +956,6 @@ const common = {
965956
hasIntl,
966957
hasCrypto,
967958
hasQuic,
968-
hasMultiLocalhost,
969959
invalidArgTypeHelper,
970960
isAlive,
971961
isASan,

test/common/index.mjs

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const {
2020
hasCrypto,
2121
hasIntl,
2222
hasIPv6,
23-
hasMultiLocalhost,
2423
isAIX,
2524
isAlive,
2625
isDumbTerminal,
@@ -75,7 +74,6 @@ export {
7574
hasCrypto,
7675
hasIntl,
7776
hasIPv6,
78-
hasMultiLocalhost,
7977
isAIX,
8078
isAlive,
8179
isDumbTerminal,

test/common/net.js

+10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ function checkSupportReusePort() {
1717
});
1818
}
1919

20+
function hasMultiLocalhost() {
21+
const { internalBinding } = require('internal/test/binding');
22+
const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap');
23+
const t = new TCP(TCPConstants.SOCKET);
24+
const ret = t.bind('127.0.0.2', 0);
25+
t.close();
26+
return ret === 0;
27+
}
28+
2029
module.exports = {
2130
checkSupportReusePort,
31+
hasMultiLocalhost,
2232
options,
2333
};

test/parallel/test-http-localaddress.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
// Flags: --expose-internals
2323
'use strict';
2424
const common = require('../common');
25-
if (!common.hasMultiLocalhost())
25+
const { hasMultiLocalhost } = require('../common/net');
26+
if (!hasMultiLocalhost()) {
2627
common.skip('platform-specific test.');
28+
}
2729

2830
const http = require('http');
2931
const assert = require('assert');

test/parallel/test-http2-connect-options.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7-
if (!common.hasMultiLocalhost())
7+
const { hasMultiLocalhost } = require('../common/net');
8+
if (!hasMultiLocalhost()) {
89
common.skip('platform-specific test.');
10+
}
911

1012
const http2 = require('http2');
1113
const assert = require('assert');

test/parallel/test-https-localaddress.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ const common = require('../common');
2525
if (!common.hasCrypto)
2626
common.skip('missing crypto');
2727

28-
if (!common.hasMultiLocalhost())
28+
const { hasMultiLocalhost } = require('../common/net');
29+
if (!hasMultiLocalhost()) {
2930
common.skip('platform-specific test.');
31+
}
3032

3133
const fixtures = require('../common/fixtures');
3234
const assert = require('assert');

0 commit comments

Comments
 (0)