Skip to content

Commit 1eac1d7

Browse files
BridgeARMylesBorins
authored andcommitted
test: minor refactoring
Add punctuation and comments about code that should not throw. Also remove a obsolete test and refactor some tests. Backport-PR-URL: #19244 PR-URL: #18669 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 574d061 commit 1eac1d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+163
-204
lines changed

test/addons/symlinked-module/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ const sub = require('./submodule');
3030
const mod = require(path.join(i, 'binding.node'));
3131
assert.notStrictEqual(mod, null);
3232
assert.strictEqual(mod.hello(), 'world');
33-
sub.test(i);
33+
sub.test(i); // Should not throw.
3434
});

test/internet/test-dns.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,8 @@ process.on('exit', function() {
579579
assert.ok(getaddrinfoCallbackCalled);
580580
});
581581

582-
582+
// Should not throw.
583583
dns.lookup(addresses.INET6_HOST, 6, common.mustCall());
584-
585584
dns.lookup(addresses.INET_HOST, {}, common.mustCall());
586-
587585
dns.lookupService('0.0.0.0', '0', common.mustCall());
588-
589586
dns.lookupService('0.0.0.0', 0, common.mustCall());

test/parallel/test-assert-deep.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]);
492492

493493
// Handle NaN
494494
assert.throws(() => { assert.deepEqual(NaN, NaN); }, assert.AssertionError);
495-
{ assert.deepStrictEqual(NaN, NaN); }
496-
{ assert.deepStrictEqual({ a: NaN }, { a: NaN }); }
495+
assert.deepStrictEqual(NaN, NaN);
496+
assert.deepStrictEqual({ a: NaN }, { a: NaN });
497497
assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]);
498498

499499
// Handle boxed primitives

test/parallel/test-buffer-alloc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ assert.throws(() => b.write('test', 'utf8', 0),
6262
/is no longer supported/);
6363

6464

65-
// try to create 0-length buffers
65+
// Try to create 0-length buffers. Should not throw.
6666
Buffer.from('');
6767
Buffer.from('', 'ascii');
6868
Buffer.from('', 'latin1');
@@ -107,7 +107,7 @@ b.copy(Buffer.alloc(1), 0, 2048, 2048);
107107
assert.strictEqual(writeTest.toString(), 'nodejs');
108108
}
109109

110-
// Offset points to the end of the buffer
110+
// Offset points to the end of the buffer and does not throw.
111111
// (see https://github.com/nodejs/node/issues/8127).
112112
Buffer.alloc(1).write('', 1, 0);
113113

@@ -992,10 +992,10 @@ common.expectsError(() => {
992992
assert.strictEqual(ubuf.buffer.byteLength, 10);
993993
}
994994

995-
// Regression test
995+
// Regression test to verify that an empty ArrayBuffer does not throw.
996996
Buffer.from(new ArrayBuffer());
997997

998-
// Test that ArrayBuffer from a different context is detected correctly
998+
// Test that ArrayBuffer from a different context is detected correctly.
999999
const arrayBuf = vm.runInNewContext('new ArrayBuffer()');
10001000
Buffer.from(arrayBuf);
10011001
Buffer.from({ buffer: arrayBuf });

test/parallel/test-buffer-bad-overload.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const common = require('../common');
33
const assert = require('assert');
44

5-
Buffer.allocUnsafe(10);
5+
Buffer.allocUnsafe(10); // Should not throw.
66

77
const err = common.expectsError({
88
code: 'ERR_INVALID_ARG_TYPE',
@@ -14,4 +14,4 @@ assert.throws(function() {
1414
Buffer.from(10, 'hex');
1515
}, err);
1616

17-
Buffer.from('deadbeaf', 'hex');
17+
Buffer.from('deadbeaf', 'hex'); // Should not throw.

test/parallel/test-buffer-constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ assert(MAX_STRING_LENGTH <= MAX_LENGTH);
1111
assert.throws(() => ' '.repeat(MAX_STRING_LENGTH + 1),
1212
/^RangeError: Invalid string length$/);
1313

14-
' '.repeat(MAX_STRING_LENGTH);
14+
' '.repeat(MAX_STRING_LENGTH); // Should not throw.
1515

1616
// Legacy values match:
1717
assert.strictEqual(kMaxLength, MAX_LENGTH);

test/parallel/test-buffer-copy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const bb = Buffer.allocUnsafe(10);
9292
bb.fill('hello crazy world');
9393

9494

95-
// try to copy from before the beginning of b
95+
// Try to copy from before the beginning of b. Should not throw.
9696
b.copy(c, 0, 100, 10);
9797

9898
// copy throws at negative sourceStart

test/parallel/test-buffer-sharedarraybuffer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ arr2[1] = 6000;
2222

2323
assert.deepStrictEqual(arr_buf, ar_buf);
2424

25-
// Checks for calling Buffer.byteLength on a SharedArrayBuffer
26-
25+
// Checks for calling Buffer.byteLength on a SharedArrayBuffer.
2726
assert.strictEqual(Buffer.byteLength(sab), sab.byteLength);
2827

29-
Buffer.from({ buffer: sab });
28+
Buffer.from({ buffer: sab }); // Should not throw.

test/parallel/test-buffer-slice.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ expectedSameBufs.forEach(([buf1, buf2]) => {
7777

7878
const utf16Buf = Buffer.from('0123456789', 'utf16le');
7979
assert.deepStrictEqual(utf16Buf.slice(0, 6), Buffer.from('012', 'utf16le'));
80-
// try to slice a zero length Buffer
81-
// see https://github.com/joyent/node/issues/5881
82-
Buffer.alloc(0).slice(0, 1);
80+
// Try to slice a zero length Buffer.
81+
// See https://github.com/joyent/node/issues/5881
8382
assert.strictEqual(Buffer.alloc(0).slice(0, 1).length, 0);
8483

8584
{

test/parallel/test-child-process-spawn-typeerror.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ assert.throws(function() {
3838
child.on('error', common.mustNotCall());
3939
}, TypeError);
4040

41-
// verify that valid argument combinations do not throw
41+
// Verify that valid argument combinations do not throw.
4242
spawn(cmd);
4343
spawn(cmd, []);
4444
spawn(cmd, {});
4545
spawn(cmd, [], {});
4646

47-
// verify that invalid argument combinations throw
47+
// Verify that invalid argument combinations throw.
4848
assert.throws(function() {
4949
spawn();
5050
}, invalidFileMsg);
@@ -74,7 +74,7 @@ assert.throws(function() {
7474
spawn(cmd, [], 1);
7575
}, invalidOptionsMsg);
7676

77-
// Argument types for combinatorics
77+
// Argument types for combinatorics.
7878
const a = [];
7979
const o = {};
8080
function c() {}
@@ -92,7 +92,7 @@ spawn(cmd, a);
9292
spawn(cmd, a, o);
9393
spawn(cmd, o);
9494

95-
// Variants of undefined as explicit 'no argument' at a position
95+
// Variants of undefined as explicit 'no argument' at a position.
9696
spawn(cmd, u, o);
9797
spawn(cmd, a, u);
9898

@@ -103,7 +103,7 @@ assert.throws(function() { spawn(cmd, s); }, TypeError);
103103
assert.throws(function() { spawn(cmd, a, s); }, TypeError);
104104

105105

106-
// verify that execFile has same argument parsing behavior as spawn
106+
// Verify that execFile has same argument parsing behavior as spawn.
107107
//
108108
// function execFile(file=f [,args=a] [, options=o] [, callback=c]) has valid
109109
// combinations:
@@ -124,7 +124,7 @@ execFile(cmd, o);
124124
execFile(cmd, o, c);
125125
execFile(cmd, c);
126126

127-
// Variants of undefined as explicit 'no argument' at a position
127+
// Variants of undefined as explicit 'no argument' at a position.
128128
execFile(cmd, u, o, c);
129129
execFile(cmd, a, u, c);
130130
execFile(cmd, a, o, u);
@@ -146,7 +146,7 @@ execFile(cmd, o, n);
146146
execFile(cmd, c, u);
147147
execFile(cmd, c, n);
148148

149-
// string is invalid in arg position (this may seem strange, but is
149+
// String is invalid in arg position (this may seem strange, but is
150150
// consistent across node API, cf. `net.createServer('not options', 'not
151151
// callback')`
152152
assert.throws(function() { execFile(cmd, s, o, c); }, TypeError);
@@ -160,10 +160,9 @@ assert.throws(function() { execFile(cmd, a, u, s); }, TypeError);
160160
assert.throws(function() { execFile(cmd, a, n, s); }, TypeError);
161161
assert.throws(function() { execFile(cmd, u, o, s); }, TypeError);
162162
assert.throws(function() { execFile(cmd, n, o, s); }, TypeError);
163-
execFile(cmd, c, s);
163+
execFile(cmd, c, s); // Should not throw.
164164

165-
166-
// verify that fork has same argument parsing behavior as spawn
165+
// Verify that fork has same argument parsing behavior as spawn.
167166
//
168167
// function fork(file=f [,args=a] [, options=o]) has valid combinations:
169168
// (f)

0 commit comments

Comments
 (0)