-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
test-set-process-debug-port.js
60 lines (52 loc) · 1.26 KB
/
test-set-process-debug-port.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
common.skipIfWorker();
const assert = require('assert');
const kMinPort = 1024;
const kMaxPort = 65535;
function check(value, expected) {
process.debugPort = value;
assert.strictEqual(process.debugPort, expected);
}
// Expected usage with numbers.
check(0, 0);
check(kMinPort, kMinPort);
check(kMinPort + 1, kMinPort + 1);
check(kMaxPort - 1, kMaxPort - 1);
check(kMaxPort, kMaxPort);
// Numeric strings coerce.
check('0', 0);
check(`${kMinPort}`, kMinPort);
check(`${kMinPort + 1}`, kMinPort + 1);
check(`${kMaxPort - 1}`, kMaxPort - 1);
check(`${kMaxPort}`, kMaxPort);
// Most other values are coerced to 0.
check('', 0);
check(false, 0);
check(NaN, 0);
check(Infinity, 0);
check(-Infinity, 0);
check(function() {}, 0);
check({}, 0);
check([], 0);
// Symbols do not coerce.
assert.throws(() => {
process.debugPort = Symbol();
}, /^TypeError: Cannot convert a Symbol value to a number$/);
// Verify port bounds checking.
[
true,
-1,
1,
kMinPort - 1,
kMaxPort + 1,
'-1',
'1',
`${kMinPort - 1}`,
`${kMaxPort + 1}`,
].forEach((value) => {
assert.throws(() => {
process.debugPort = value;
}, /^RangeError: process\.debugPort must be 0 or in range 1024 to 65535$/);
});