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

+1-1
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

+1-4
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

+2-2
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

+4-4
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

+2-2
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

+1-1
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

+1-1
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

+2-3
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

+2-3
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

+9-10
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)

test/parallel/test-console-async-write-error.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ for (const method of ['dir', 'log', 'warn']) {
1111
});
1212

1313
const c = new Console(out, out, true);
14-
15-
c[method]('abc');
14+
c[method]('abc'); // Should not throw.
1615
}

test/parallel/test-console-instance.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ const Console = require('console').Console;
2828
const out = new Stream();
2929
const err = new Stream();
3030

31-
// ensure the Console instance doesn't write to the
32-
// process' "stdout" or "stderr" streams
31+
// Ensure the Console instance doesn't write to the
32+
// process' "stdout" or "stderr" streams.
3333
process.stdout.write = process.stderr.write = common.mustNotCall();
3434

35-
// make sure that the "Console" function exists
35+
// Make sure that the "Console" function exists.
3636
assert.strictEqual('function', typeof Console);
3737

38-
// make sure that the Console constructor throws
39-
// when not given a writable stream instance
38+
// Make sure that the Console constructor throws
39+
// when not given a writable stream instance.
4040
common.expectsError(
4141
() => { new Console(); },
4242
{
@@ -46,7 +46,7 @@ common.expectsError(
4646
}
4747
);
4848

49-
// Console constructor should throw if stderr exists but is not writable
49+
// Console constructor should throw if stderr exists but is not writable.
5050
common.expectsError(
5151
() => {
5252
out.write = () => {};
@@ -77,7 +77,7 @@ out.write = common.mustCall((d) => {
7777

7878
c.dir({ foo: 1 });
7979

80-
// ensure that the console functions are bound to the console instance
80+
// Ensure that the console functions are bound to the console instance.
8181
let called = 0;
8282
out.write = common.mustCall((d) => {
8383
called++;
@@ -86,7 +86,7 @@ out.write = common.mustCall((d) => {
8686

8787
[1, 2, 3].forEach(c.log);
8888

89-
// Console() detects if it is called without `new` keyword
89+
// Console() detects if it is called without `new` keyword.
9090
Console(out, err);
9191

9292
// Instance that does not ignore the stream errors.

test/parallel/test-console-sync-write-error.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ for (const method of ['dir', 'log', 'warn']) {
1212
});
1313

1414
const c = new Console(out, out, true);
15-
16-
c[method]('abc');
15+
c[method]('abc'); // Should not throw.
1716
}
1817

1918
{
@@ -24,8 +23,7 @@ for (const method of ['dir', 'log', 'warn']) {
2423
});
2524

2625
const c = new Console(out, out, true);
27-
28-
c[method]('abc');
26+
c[method]('abc'); // Should not throw.
2927
}
3028

3129
{
@@ -36,7 +34,6 @@ for (const method of ['dir', 'log', 'warn']) {
3634
});
3735

3836
const c = new Console(out, out, true);
39-
40-
c[method]('abc');
37+
c[method]('abc'); // Should not throw.
4138
}
4239
}

test/parallel/test-crypto-padding.js

+9-27
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ const crypto = require('crypto');
2929

3030
crypto.DEFAULT_ENCODING = 'buffer';
3131

32-
33-
/*
34-
* Input data
35-
*/
36-
32+
// Input data.
3733
const ODD_LENGTH_PLAIN = 'Hello node world!';
3834
const EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi';
3935

@@ -42,10 +38,7 @@ const IV_PLAIN = 'blahFizz2011Buzz';
4238

4339
const CIPHER_NAME = 'aes-128-cbc';
4440

45-
46-
/*
47-
* Expected result data
48-
*/
41+
// Expected result data.
4942

5043
// echo -n 'Hello node world!' | \
5144
// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \
@@ -67,10 +60,7 @@ const EVEN_LENGTH_ENCRYPTED_NOPAD =
6760
'7f57859550d4d2fdb9806da2a750461ab46e71b3d78ebe2d9684dfc87f7575b9';
6861

6962

70-
/*
71-
* Helper wrappers
72-
*/
73-
63+
// Helper wrappers.
7464
function enc(plain, pad) {
7565
const encrypt = crypto.createCipheriv(CIPHER_NAME, KEY_PLAIN, IV_PLAIN);
7666
encrypt.setAutoPadding(pad);
@@ -87,41 +77,33 @@ function dec(encd, pad) {
8777
return plain;
8878
}
8979

90-
91-
/*
92-
* Test encryption
93-
*/
94-
80+
// Test encryption
9581
assert.strictEqual(enc(ODD_LENGTH_PLAIN, true), ODD_LENGTH_ENCRYPTED);
9682
assert.strictEqual(enc(EVEN_LENGTH_PLAIN, true), EVEN_LENGTH_ENCRYPTED);
9783

9884
assert.throws(function() {
99-
// input must have block length %
85+
// Input must have block length %.
10086
enc(ODD_LENGTH_PLAIN, false);
10187
}, /data not multiple of block length/);
10288

10389
assert.strictEqual(
10490
enc(EVEN_LENGTH_PLAIN, false), EVEN_LENGTH_ENCRYPTED_NOPAD
10591
);
10692

107-
108-
/*
109-
* Test decryption
110-
*/
111-
93+
// Test decryption.
11294
assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, true), ODD_LENGTH_PLAIN);
11395
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, true), EVEN_LENGTH_PLAIN);
11496

115-
// returns including original padding
97+
// Returns including original padding.
11698
assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, false).length, 32);
11799
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48);
118100

119101
assert.throws(function() {
120-
// must have at least 1 byte of padding (PKCS):
102+
// Must have at least 1 byte of padding (PKCS):
121103
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN);
122104
}, /bad decrypt/);
123105

124-
// no-pad encrypted string should return the same:
106+
// No-pad encrypted string should return the same:
125107
assert.strictEqual(
126108
dec(EVEN_LENGTH_ENCRYPTED_NOPAD, false), EVEN_LENGTH_PLAIN
127109
);

test/parallel/test-crypto-pbkdf2.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ common.expectsError(
9999

100100
// Should not get FATAL ERROR with empty password and salt
101101
// https://github.com/nodejs/node/issues/8571
102-
crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall((e) => {
103-
assert.ifError(e);
104-
}));
102+
crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall(assert.ifError));
105103

106104
common.expectsError(
107105
() => crypto.pbkdf2('password', 'salt', 8, 8, common.mustNotCall()),

test/parallel/test-crypto-rsa-dsa.js

-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ const input = 'I AM THE WALRUS';
256256
// against
257257
const sign = crypto.createSign('SHA1');
258258
sign.update(input);
259-
260259
const signOptions = { key: dsaKeyPemEncrypted, passphrase: 'password' };
261260
const signature = sign.sign(signOptions, 'hex');
262261

test/parallel/test-domain-load-after-set-uncaught-exception-capture.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ common.expectsError(
1313
);
1414

1515
process.setUncaughtExceptionCaptureCallback(null);
16-
17-
require('domain');
16+
require('domain'); // Should not throw.

test/parallel/test-fs-access.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ common.expectsError(
105105
type: TypeError
106106
});
107107

108+
// Regular access should not throw.
108109
fs.accessSync(__filename);
109-
110110
const mode = fs.F_OK | fs.R_OK | fs.W_OK;
111111
fs.accessSync(readWriteFile, mode);
112112

0 commit comments

Comments
 (0)