From 9e9f331f43db21c2618943cfc448da27b6b01e0e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 10 Feb 2018 02:33:08 +0100 Subject: [PATCH] test: minor refactoring Add punctuation and comments about code that should not throw. Also remove a obsolete test and refactor some tests. PR-URL: https://github.com/nodejs/node/pull/18669 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Matteo Collina --- test/addons/symlinked-module/test.js | 2 +- test/internet/test-dns.js | 5 +- test/parallel/test-assert-deep.js | 4 +- test/parallel/test-buffer-alloc.js | 8 +- test/parallel/test-buffer-bad-overload.js | 4 +- test/parallel/test-buffer-constants.js | 2 +- test/parallel/test-buffer-copy.js | 2 +- .../parallel/test-buffer-sharedarraybuffer.js | 5 +- test/parallel/test-buffer-slice.js | 5 +- .../test-child-process-spawn-typeerror.js | 19 ++- .../test-console-async-write-error.js | 3 +- test/parallel/test-console-instance.js | 16 +-- .../parallel/test-console-sync-write-error.js | 9 +- test/parallel/test-crypto-padding.js | 36 ++---- test/parallel/test-crypto-pbkdf2.js | 4 +- test/parallel/test-crypto-rsa-dsa.js | 1 - ...ad-after-set-uncaught-exception-capture.js | 3 +- test/parallel/test-fs-access.js | 2 +- test/parallel/test-fs-buffer.js | 8 +- .../test-fs-read-stream-throw-type-error.js | 2 +- .../test-fs-write-stream-throw-type-error.js | 2 +- test/parallel/test-http-invalidheaderfield.js | 1 + test/parallel/test-http2-binding.js | 2 - ...t-http2-client-rststream-before-connect.js | 4 +- ...-http2-compat-serverresponse-statuscode.js | 1 + test/parallel/test-http2-getpackedsettings.js | 9 +- test/parallel/test-http2-server-startup.js | 10 +- test/parallel/test-http2-socket-proxy.js | 1 + test/parallel/test-http2-withflag.js | 7 -- test/parallel/test-https-agent-constructor.js | 1 - test/parallel/test-icu-punycode.js | 4 +- test/parallel/test-internal-fs.js | 2 + ...test-internal-util-decorate-error-stack.js | 11 +- .../test-module-symlinked-peer-modules.js | 2 +- test/parallel/test-net-after-close.js | 2 + test/parallel/test-net-during-close.js | 6 +- test/parallel/test-process-geteuid-getegid.js | 1 + test/parallel/test-process-setuid-setgid.js | 1 + test/parallel/test-querystring.js | 2 +- test/parallel/test-readline-csi.js | 1 + test/parallel/test-stream-writable-null.js | 30 ++--- test/parallel/test-timers-unref.js | 1 + test/parallel/test-util-inspect.js | 113 +++++++++--------- test/parallel/test-vm-create-context-arg.js | 1 + test/parallel/test-vm-cross-context.js | 1 + test/pummel/test-fs-largefile.js | 1 + test/pummel/test-fs-watch-file.js | 7 +- test/sequential/test-inspector-module.js | 1 + test/sequential/test-performance.js | 2 +- 49 files changed, 163 insertions(+), 204 deletions(-) delete mode 100644 test/parallel/test-http2-withflag.js diff --git a/test/addons/symlinked-module/test.js b/test/addons/symlinked-module/test.js index 98eec17d0c8c95..cbd01e938fe25f 100644 --- a/test/addons/symlinked-module/test.js +++ b/test/addons/symlinked-module/test.js @@ -30,5 +30,5 @@ const sub = require('./submodule'); const mod = require(path.join(i, 'binding.node')); assert.notStrictEqual(mod, null); assert.strictEqual(mod.hello(), 'world'); - sub.test(i); + sub.test(i); // Should not throw. }); diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index dadf14c0be36b1..f1b7b4ff056833 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -579,11 +579,8 @@ process.on('exit', function() { assert.ok(getaddrinfoCallbackCalled); }); - +// Should not throw. dns.lookup(addresses.INET6_HOST, 6, common.mustCall()); - dns.lookup(addresses.INET_HOST, {}, common.mustCall()); - dns.lookupService('0.0.0.0', '0', common.mustCall()); - dns.lookupService('0.0.0.0', 0, common.mustCall()); diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index d9c9df5bb2c875..d0aacfdf516f4c 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -492,8 +492,8 @@ assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); // Handle NaN assert.throws(() => { assert.deepEqual(NaN, NaN); }, assert.AssertionError); -{ assert.deepStrictEqual(NaN, NaN); } -{ assert.deepStrictEqual({ a: NaN }, { a: NaN }); } +assert.deepStrictEqual(NaN, NaN); +assert.deepStrictEqual({ a: NaN }, { a: NaN }); assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]); // Handle boxed primitives diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 7f062f6b58c68c..20e91377cd7fdf 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -62,7 +62,7 @@ assert.throws(() => b.write('test', 'utf8', 0), /is no longer supported/); -// try to create 0-length buffers +// Try to create 0-length buffers. Should not throw. Buffer.from(''); Buffer.from('', 'ascii'); Buffer.from('', 'latin1'); @@ -107,7 +107,7 @@ b.copy(Buffer.alloc(1), 0, 2048, 2048); assert.strictEqual(writeTest.toString(), 'nodejs'); } -// Offset points to the end of the buffer +// Offset points to the end of the buffer and does not throw. // (see https://github.com/nodejs/node/issues/8127). Buffer.alloc(1).write('', 1, 0); @@ -992,10 +992,10 @@ common.expectsError(() => { assert.strictEqual(ubuf.buffer.byteLength, 10); } -// Regression test +// Regression test to verify that an empty ArrayBuffer does not throw. Buffer.from(new ArrayBuffer()); -// Test that ArrayBuffer from a different context is detected correctly +// Test that ArrayBuffer from a different context is detected correctly. const arrayBuf = vm.runInNewContext('new ArrayBuffer()'); Buffer.from(arrayBuf); Buffer.from({ buffer: arrayBuf }); diff --git a/test/parallel/test-buffer-bad-overload.js b/test/parallel/test-buffer-bad-overload.js index ec2703341b2f38..63acb8ebfb6d49 100644 --- a/test/parallel/test-buffer-bad-overload.js +++ b/test/parallel/test-buffer-bad-overload.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -Buffer.allocUnsafe(10); +Buffer.allocUnsafe(10); // Should not throw. const err = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', @@ -14,4 +14,4 @@ assert.throws(function() { Buffer.from(10, 'hex'); }, err); -Buffer.from('deadbeaf', 'hex'); +Buffer.from('deadbeaf', 'hex'); // Should not throw. diff --git a/test/parallel/test-buffer-constants.js b/test/parallel/test-buffer-constants.js index dbb6186b6de5ce..f6f0dbddc39d3e 100644 --- a/test/parallel/test-buffer-constants.js +++ b/test/parallel/test-buffer-constants.js @@ -11,7 +11,7 @@ assert(MAX_STRING_LENGTH <= MAX_LENGTH); assert.throws(() => ' '.repeat(MAX_STRING_LENGTH + 1), /^RangeError: Invalid string length$/); -' '.repeat(MAX_STRING_LENGTH); +' '.repeat(MAX_STRING_LENGTH); // Should not throw. // Legacy values match: assert.strictEqual(kMaxLength, MAX_LENGTH); diff --git a/test/parallel/test-buffer-copy.js b/test/parallel/test-buffer-copy.js index 324613a04fe525..5c82f4de28dbee 100644 --- a/test/parallel/test-buffer-copy.js +++ b/test/parallel/test-buffer-copy.js @@ -92,7 +92,7 @@ const bb = Buffer.allocUnsafe(10); bb.fill('hello crazy world'); -// try to copy from before the beginning of b +// Try to copy from before the beginning of b. Should not throw. b.copy(c, 0, 100, 10); // copy throws at negative sourceStart diff --git a/test/parallel/test-buffer-sharedarraybuffer.js b/test/parallel/test-buffer-sharedarraybuffer.js index 536c3939365d98..0252847c054c1d 100644 --- a/test/parallel/test-buffer-sharedarraybuffer.js +++ b/test/parallel/test-buffer-sharedarraybuffer.js @@ -22,8 +22,7 @@ arr2[1] = 6000; assert.deepStrictEqual(arr_buf, ar_buf); -// Checks for calling Buffer.byteLength on a SharedArrayBuffer - +// Checks for calling Buffer.byteLength on a SharedArrayBuffer. assert.strictEqual(Buffer.byteLength(sab), sab.byteLength); -Buffer.from({ buffer: sab }); +Buffer.from({ buffer: sab }); // Should not throw. diff --git a/test/parallel/test-buffer-slice.js b/test/parallel/test-buffer-slice.js index b55d082783cc28..6175370a9bccee 100644 --- a/test/parallel/test-buffer-slice.js +++ b/test/parallel/test-buffer-slice.js @@ -77,9 +77,8 @@ expectedSameBufs.forEach(([buf1, buf2]) => { const utf16Buf = Buffer.from('0123456789', 'utf16le'); assert.deepStrictEqual(utf16Buf.slice(0, 6), Buffer.from('012', 'utf16le')); -// try to slice a zero length Buffer -// see https://github.com/joyent/node/issues/5881 -Buffer.alloc(0).slice(0, 1); +// Try to slice a zero length Buffer. +// See https://github.com/joyent/node/issues/5881 assert.strictEqual(Buffer.alloc(0).slice(0, 1).length, 0); { diff --git a/test/parallel/test-child-process-spawn-typeerror.js b/test/parallel/test-child-process-spawn-typeerror.js index eede5fdd15d5c0..9855c0cfd99fa6 100644 --- a/test/parallel/test-child-process-spawn-typeerror.js +++ b/test/parallel/test-child-process-spawn-typeerror.js @@ -38,13 +38,13 @@ assert.throws(function() { child.on('error', common.mustNotCall()); }, TypeError); -// verify that valid argument combinations do not throw +// Verify that valid argument combinations do not throw. spawn(cmd); spawn(cmd, []); spawn(cmd, {}); spawn(cmd, [], {}); -// verify that invalid argument combinations throw +// Verify that invalid argument combinations throw. assert.throws(function() { spawn(); }, invalidFileMsg); @@ -74,7 +74,7 @@ assert.throws(function() { spawn(cmd, [], 1); }, invalidOptionsMsg); -// Argument types for combinatorics +// Argument types for combinatorics. const a = []; const o = {}; function c() {} @@ -92,7 +92,7 @@ spawn(cmd, a); spawn(cmd, a, o); spawn(cmd, o); -// Variants of undefined as explicit 'no argument' at a position +// Variants of undefined as explicit 'no argument' at a position. spawn(cmd, u, o); spawn(cmd, a, u); @@ -103,7 +103,7 @@ assert.throws(function() { spawn(cmd, s); }, TypeError); assert.throws(function() { spawn(cmd, a, s); }, TypeError); -// verify that execFile has same argument parsing behavior as spawn +// Verify that execFile has same argument parsing behavior as spawn. // // function execFile(file=f [,args=a] [, options=o] [, callback=c]) has valid // combinations: @@ -124,7 +124,7 @@ execFile(cmd, o); execFile(cmd, o, c); execFile(cmd, c); -// Variants of undefined as explicit 'no argument' at a position +// Variants of undefined as explicit 'no argument' at a position. execFile(cmd, u, o, c); execFile(cmd, a, u, c); execFile(cmd, a, o, u); @@ -146,7 +146,7 @@ execFile(cmd, o, n); execFile(cmd, c, u); execFile(cmd, c, n); -// string is invalid in arg position (this may seem strange, but is +// String is invalid in arg position (this may seem strange, but is // consistent across node API, cf. `net.createServer('not options', 'not // callback')` assert.throws(function() { execFile(cmd, s, o, c); }, TypeError); @@ -160,10 +160,9 @@ assert.throws(function() { execFile(cmd, a, u, s); }, TypeError); assert.throws(function() { execFile(cmd, a, n, s); }, TypeError); assert.throws(function() { execFile(cmd, u, o, s); }, TypeError); assert.throws(function() { execFile(cmd, n, o, s); }, TypeError); -execFile(cmd, c, s); +execFile(cmd, c, s); // Should not throw. - -// verify that fork has same argument parsing behavior as spawn +// Verify that fork has same argument parsing behavior as spawn. // // function fork(file=f [,args=a] [, options=o]) has valid combinations: // (f) diff --git a/test/parallel/test-console-async-write-error.js b/test/parallel/test-console-async-write-error.js index 139c02d64bff4b..be76c89832f611 100644 --- a/test/parallel/test-console-async-write-error.js +++ b/test/parallel/test-console-async-write-error.js @@ -11,6 +11,5 @@ for (const method of ['dir', 'log', 'warn']) { }); const c = new Console(out, out, true); - - c[method]('abc'); + c[method]('abc'); // Should not throw. } diff --git a/test/parallel/test-console-instance.js b/test/parallel/test-console-instance.js index aa35afc648a432..2fd07ac41219a9 100644 --- a/test/parallel/test-console-instance.js +++ b/test/parallel/test-console-instance.js @@ -28,15 +28,15 @@ const Console = require('console').Console; const out = new Stream(); const err = new Stream(); -// ensure the Console instance doesn't write to the -// process' "stdout" or "stderr" streams +// Ensure the Console instance doesn't write to the +// process' "stdout" or "stderr" streams. process.stdout.write = process.stderr.write = common.mustNotCall(); -// make sure that the "Console" function exists +// Make sure that the "Console" function exists. assert.strictEqual('function', typeof Console); -// make sure that the Console constructor throws -// when not given a writable stream instance +// Make sure that the Console constructor throws +// when not given a writable stream instance. common.expectsError( () => { new Console(); }, { @@ -46,7 +46,7 @@ common.expectsError( } ); -// Console constructor should throw if stderr exists but is not writable +// Console constructor should throw if stderr exists but is not writable. common.expectsError( () => { out.write = () => {}; @@ -77,7 +77,7 @@ out.write = common.mustCall((d) => { c.dir({ foo: 1 }); -// ensure that the console functions are bound to the console instance +// Ensure that the console functions are bound to the console instance. let called = 0; out.write = common.mustCall((d) => { called++; @@ -86,7 +86,7 @@ out.write = common.mustCall((d) => { [1, 2, 3].forEach(c.log); -// Console() detects if it is called without `new` keyword +// Console() detects if it is called without `new` keyword. Console(out, err); // Instance that does not ignore the stream errors. diff --git a/test/parallel/test-console-sync-write-error.js b/test/parallel/test-console-sync-write-error.js index 4d6c52e0dabca5..bf916ff5b84e8d 100644 --- a/test/parallel/test-console-sync-write-error.js +++ b/test/parallel/test-console-sync-write-error.js @@ -12,8 +12,7 @@ for (const method of ['dir', 'log', 'warn']) { }); const c = new Console(out, out, true); - - c[method]('abc'); + c[method]('abc'); // Should not throw. } { @@ -24,8 +23,7 @@ for (const method of ['dir', 'log', 'warn']) { }); const c = new Console(out, out, true); - - c[method]('abc'); + c[method]('abc'); // Should not throw. } { @@ -36,7 +34,6 @@ for (const method of ['dir', 'log', 'warn']) { }); const c = new Console(out, out, true); - - c[method]('abc'); + c[method]('abc'); // Should not throw. } } diff --git a/test/parallel/test-crypto-padding.js b/test/parallel/test-crypto-padding.js index ae85f7d2c3614a..00b600efb735e8 100644 --- a/test/parallel/test-crypto-padding.js +++ b/test/parallel/test-crypto-padding.js @@ -29,11 +29,7 @@ const crypto = require('crypto'); crypto.DEFAULT_ENCODING = 'buffer'; - -/* - * Input data - */ - +// Input data. const ODD_LENGTH_PLAIN = 'Hello node world!'; const EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi'; @@ -42,10 +38,7 @@ const IV_PLAIN = 'blahFizz2011Buzz'; const CIPHER_NAME = 'aes-128-cbc'; - -/* - * Expected result data - */ +// Expected result data. // echo -n 'Hello node world!' | \ // openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \ @@ -67,10 +60,7 @@ const EVEN_LENGTH_ENCRYPTED_NOPAD = '7f57859550d4d2fdb9806da2a750461ab46e71b3d78ebe2d9684dfc87f7575b9'; -/* - * Helper wrappers - */ - +// Helper wrappers. function enc(plain, pad) { const encrypt = crypto.createCipheriv(CIPHER_NAME, KEY_PLAIN, IV_PLAIN); encrypt.setAutoPadding(pad); @@ -87,16 +77,12 @@ function dec(encd, pad) { return plain; } - -/* - * Test encryption - */ - +// Test encryption assert.strictEqual(enc(ODD_LENGTH_PLAIN, true), ODD_LENGTH_ENCRYPTED); assert.strictEqual(enc(EVEN_LENGTH_PLAIN, true), EVEN_LENGTH_ENCRYPTED); assert.throws(function() { - // input must have block length % + // Input must have block length %. enc(ODD_LENGTH_PLAIN, false); }, /data not multiple of block length/); @@ -104,24 +90,20 @@ assert.strictEqual( enc(EVEN_LENGTH_PLAIN, false), EVEN_LENGTH_ENCRYPTED_NOPAD ); - -/* - * Test decryption - */ - +// Test decryption. assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, true), ODD_LENGTH_PLAIN); assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, true), EVEN_LENGTH_PLAIN); -// returns including original padding +// Returns including original padding. assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, false).length, 32); assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48); assert.throws(function() { - // must have at least 1 byte of padding (PKCS): + // Must have at least 1 byte of padding (PKCS): assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN); }, /bad decrypt/); -// no-pad encrypted string should return the same: +// No-pad encrypted string should return the same: assert.strictEqual( dec(EVEN_LENGTH_ENCRYPTED_NOPAD, false), EVEN_LENGTH_PLAIN ); diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index 1bb1c6cd71215e..a9a23e155ffb2f 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -99,9 +99,7 @@ common.expectsError( // Should not get FATAL ERROR with empty password and salt // https://github.com/nodejs/node/issues/8571 -crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall((e) => { - assert.ifError(e); -})); +crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall(assert.ifError)); common.expectsError( () => crypto.pbkdf2('password', 'salt', 8, 8, common.mustNotCall()), diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index 5a6ecdd66f41bf..744dc5657b089d 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -256,7 +256,6 @@ const input = 'I AM THE WALRUS'; // against const sign = crypto.createSign('SHA1'); sign.update(input); - const signOptions = { key: dsaKeyPemEncrypted, passphrase: 'password' }; const signature = sign.sign(signOptions, 'hex'); diff --git a/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js b/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js index c2fa523cc17019..697d4d30806ee7 100644 --- a/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js +++ b/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js @@ -13,5 +13,4 @@ common.expectsError( ); process.setUncaughtExceptionCaptureCallback(null); - -require('domain'); +require('domain'); // Should not throw. diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index a55f75f649f383..9d5160f6170cad 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -105,8 +105,8 @@ common.expectsError( type: TypeError }); +// Regular access should not throw. fs.accessSync(__filename); - const mode = fs.F_OK | fs.R_OK | fs.W_OK; fs.accessSync(readWriteFile, mode); diff --git a/test/parallel/test-fs-buffer.js b/test/parallel/test-fs-buffer.js index 0b7b67cefe4d86..f1c3484ce3a8d0 100644 --- a/test/parallel/test-fs-buffer.js +++ b/test/parallel/test-fs-buffer.js @@ -9,17 +9,13 @@ const path = require('path'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); -fs.access(Buffer.from(tmpdir.path), common.mustCall((err) => { - assert.ifError(err); -})); +fs.access(Buffer.from(tmpdir.path), common.mustCall(assert.ifError)); const buf = Buffer.from(path.join(tmpdir.path, 'a.txt')); fs.open(buf, 'w+', common.mustCall((err, fd) => { assert.ifError(err); assert(fd); - fs.close(fd, common.mustCall((err) => { - assert.ifError(err); - })); + fs.close(fd, common.mustCall(assert.ifError)); })); assert.throws(() => { diff --git a/test/parallel/test-fs-read-stream-throw-type-error.js b/test/parallel/test-fs-read-stream-throw-type-error.js index b01a0a588f5699..c2b0d5452c55e3 100644 --- a/test/parallel/test-fs-read-stream-throw-type-error.js +++ b/test/parallel/test-fs-read-stream-throw-type-error.js @@ -4,7 +4,7 @@ const fixtures = require('../common/fixtures'); const fs = require('fs'); const example = fixtures.path('x.txt'); - +// Should not throw. fs.createReadStream(example, undefined); fs.createReadStream(example, null); fs.createReadStream(example, 'utf8'); diff --git a/test/parallel/test-fs-write-stream-throw-type-error.js b/test/parallel/test-fs-write-stream-throw-type-error.js index 553d399e238508..c80f647b3d622e 100644 --- a/test/parallel/test-fs-write-stream-throw-type-error.js +++ b/test/parallel/test-fs-write-stream-throw-type-error.js @@ -8,7 +8,7 @@ const tmpdir = require('../common/tmpdir'); const example = path.join(tmpdir.path, 'dummy'); tmpdir.refresh(); - +// Should not throw. fs.createWriteStream(example, undefined); fs.createWriteStream(example, null); fs.createWriteStream(example, 'utf8'); diff --git a/test/parallel/test-http-invalidheaderfield.js b/test/parallel/test-http-invalidheaderfield.js index 528fc825868ed7..01315ba69044a2 100644 --- a/test/parallel/test-http-invalidheaderfield.js +++ b/test/parallel/test-http-invalidheaderfield.js @@ -35,6 +35,7 @@ server.listen(0, function() { } ); + // Should not throw. const options = { port: server.address().port, headers: { 'testing_123': 123 } diff --git a/test/parallel/test-http2-binding.js b/test/parallel/test-http2-binding.js index 1b8501dcbeca2f..f267e2e6c1481e 100644 --- a/test/parallel/test-http2-binding.js +++ b/test/parallel/test-http2-binding.js @@ -5,8 +5,6 @@ if (!common.hasCrypto) common.skip('missing crypto'); const assert = require('assert'); -process.binding('http2'); - const binding = process.binding('http2'); const http2 = require('http2'); diff --git a/test/parallel/test-http2-client-rststream-before-connect.js b/test/parallel/test-http2-client-rststream-before-connect.js index 177b13a16eed98..10d7520ac125fe 100644 --- a/test/parallel/test-http2-client-rststream-before-connect.js +++ b/test/parallel/test-http2-client-rststream-before-connect.js @@ -19,10 +19,10 @@ server.listen(0, common.mustCall(() => { req.close(1); assert.strictEqual(req.closed, true); - // make sure that destroy is called + // Make sure that destroy is called. req._destroy = common.mustCall(req._destroy.bind(req)); - // second call doesn't do anything + // Second call doesn't do anything. req.close(8); req.on('close', common.mustCall((code) => { diff --git a/test/parallel/test-http2-compat-serverresponse-statuscode.js b/test/parallel/test-http2-compat-serverresponse-statuscode.js index 4c51616ef618fc..dd92db8d96597a 100644 --- a/test/parallel/test-http2-compat-serverresponse-statuscode.js +++ b/test/parallel/test-http2-compat-serverresponse-statuscode.js @@ -27,6 +27,7 @@ server.listen(0, common.mustCall(function() { assert.strictEqual(response.statusCode, expectedDefaultStatusCode); + // Setting the response.statusCode should not throw. response.statusCode = realStatusCodes.ok; response.statusCode = realStatusCodes.multipleChoices; response.statusCode = realStatusCodes.badRequest; diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js index b02d6b4933bbfa..56b96321139630 100644 --- a/test/parallel/test-http2-getpackedsettings.js +++ b/test/parallel/test-http2-getpackedsettings.js @@ -26,6 +26,7 @@ assert.deepStrictEqual(val, check); ['maxHeaderListSize', 0], ['maxHeaderListSize', 2 ** 32 - 1] ].forEach((i) => { + // Valid options should not throw. http2.getPackedSettings({ [i[0]]: i[1] }); }); @@ -85,7 +86,7 @@ http2.getPackedSettings({ enablePush: false }); assert.deepStrictEqual(packed, check); } -// check for not passing settings +// Check for not passing settings. { const packed = http2.getPackedSettings(); assert.strictEqual(packed.length, 0); @@ -143,7 +144,7 @@ http2.getPackedSettings({ enablePush: false }); assert.strictEqual(settings.enablePush, true); } -//check for what happens if passing {validate: true} and no errors happen +// Verify that passing {validate: true} does not throw. { const packed = Buffer.from([ 0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00, @@ -154,7 +155,7 @@ http2.getPackedSettings({ enablePush: false }); http2.getUnpackedSettings(packed, { validate: true }); } -// check for maxFrameSize failing the max number +// Check for maxFrameSize failing the max number. { const packed = Buffer.from([0x00, 0x05, 0x01, 0x00, 0x00, 0x00]); @@ -167,7 +168,7 @@ http2.getPackedSettings({ enablePush: false }); }); } -// check for maxConcurrentStreams failing the max number +// Check for maxConcurrentStreams failing the max number. { const packed = Buffer.from([0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF]); diff --git a/test/parallel/test-http2-server-startup.js b/test/parallel/test-http2-server-startup.js index 12b9cd72cba147..4ebcc21c27aa8e 100644 --- a/test/parallel/test-http2-server-startup.js +++ b/test/parallel/test-http2-server-startup.js @@ -19,20 +19,20 @@ const options = { cert: commonFixtures.readKey('agent2-cert.pem') }; -// There should not be any throws +// There should not be any throws. const serverTLS = http2.createSecureServer(options, () => {}); serverTLS.listen(0, common.mustCall(() => serverTLS.close())); -// There should not be an error event reported either +// There should not be an error event reported either. serverTLS.on('error', common.mustNotCall()); const server = http2.createServer(options, common.mustNotCall()); server.listen(0, common.mustCall(() => server.close())); -// There should not be an error event reported either +// There should not be an error event reported either. server.on('error', common.mustNotCall()); -// Test the plaintext server socket timeout +// Test the plaintext server socket timeout. { let client; const server = http2.createServer(); @@ -48,7 +48,7 @@ server.on('error', common.mustNotCall()); })); } -// Test the secure server socket timeout +// Test the secure server socket timeout. { let client; const server = http2.createSecureServer(options); diff --git a/test/parallel/test-http2-socket-proxy.js b/test/parallel/test-http2-socket-proxy.js index e954439d78c07c..912ec673ba79cc 100644 --- a/test/parallel/test-http2-socket-proxy.js +++ b/test/parallel/test-http2-socket-proxy.js @@ -47,6 +47,7 @@ server.on('stream', common.mustCall(function(stream, headers) { common.expectsError(() => (socket.resume = undefined), errMsg); common.expectsError(() => (socket.write = undefined), errMsg); + // Resetting the socket listeners to their own value should not throw. socket.on = socket.on; socket.once = socket.once; diff --git a/test/parallel/test-http2-withflag.js b/test/parallel/test-http2-withflag.js deleted file mode 100644 index 3cc5c69c681c50..00000000000000 --- a/test/parallel/test-http2-withflag.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -const common = require('../common'); -if (!common.hasCrypto) - common.skip('missing crypto'); - -require('http2'); diff --git a/test/parallel/test-https-agent-constructor.js b/test/parallel/test-https-agent-constructor.js index 571160bbb845dd..69156ba0f64de9 100644 --- a/test/parallel/test-https-agent-constructor.js +++ b/test/parallel/test-https-agent-constructor.js @@ -6,5 +6,4 @@ if (!common.hasCrypto) const assert = require('assert'); const https = require('https'); -https.Agent(); assert.ok(https.Agent() instanceof https.Agent); diff --git a/test/parallel/test-icu-punycode.js b/test/parallel/test-icu-punycode.js index 3ca30a6d168ba9..82c15287982631 100644 --- a/test/parallel/test-icu-punycode.js +++ b/test/parallel/test-icu-punycode.js @@ -34,12 +34,12 @@ const wptToASCIITests = require('../fixtures/url-toascii.js'); if (output === null) { assert.throws(() => icu.toASCII(input), errMessage, `ToASCII ${caseComment}`); - icu.toASCII(input, true); + icu.toASCII(input, true); // Should not throw. } else { assert.strictEqual(icu.toASCII(input), output, `ToASCII ${caseComment}`); assert.strictEqual(icu.toASCII(input, true), output, `ToASCII ${caseComment} in lenient mode`); } - icu.toUnicode(input); + icu.toUnicode(input); // Should not throw. } } diff --git a/test/parallel/test-internal-fs.js b/test/parallel/test-internal-fs.js index 3f270f93d5359b..9bc0a98b099f75 100644 --- a/test/parallel/test-internal-fs.js +++ b/test/parallel/test-internal-fs.js @@ -4,8 +4,10 @@ const common = require('../common'); const fs = require('internal/fs'); +// Valid encodings and no args should not throw. fs.assertEncoding(); fs.assertEncoding('utf8'); + common.expectsError( () => fs.assertEncoding('foo'), { code: 'ERR_INVALID_OPT_VALUE_ENCODING', type: TypeError } diff --git a/test/parallel/test-internal-util-decorate-error-stack.js b/test/parallel/test-internal-util-decorate-error-stack.js index 155a2718f90c55..5694d746c667f4 100644 --- a/test/parallel/test-internal-util-decorate-error-stack.js +++ b/test/parallel/test-internal-util-decorate-error-stack.js @@ -12,12 +12,13 @@ const kDecoratedPrivateSymbolIndex = binding.decorated_private_symbol; const decorateErrorStack = internalUtil.decorateErrorStack; +// Verify that decorateErrorStack does not throw with non-objects. decorateErrorStack(); decorateErrorStack(null); decorateErrorStack(1); decorateErrorStack(true); -// Verify that a stack property is not added to non-Errors +// Verify that a stack property is not added to non-Errors. const obj = {}; decorateErrorStack(obj); assert.strictEqual(obj.stack, undefined); @@ -46,12 +47,12 @@ try { assert(typeof err, 'object'); checkStack(err.stack); -// Verify that the stack is only decorated once +// Verify that the stack is only decorated once. decorateErrorStack(err); decorateErrorStack(err); checkStack(err.stack); -// Verify that the stack is only decorated once for uncaught exceptions +// Verify that the stack is only decorated once for uncaught exceptions. const args = [ '-e', `require('${badSyntaxPath}')` @@ -59,14 +60,14 @@ const args = [ const result = spawnSync(process.argv[0], args, { encoding: 'utf8' }); checkStack(result.stderr); -// Verify that the stack is unchanged when there is no arrow message +// Verify that the stack is unchanged when there is no arrow message. err = new Error('foo'); let originalStack = err.stack; decorateErrorStack(err); assert.strictEqual(originalStack, err.stack); // Verify that the arrow message is added to the start of the stack when it -// exists +// exists. const arrowMessage = 'arrow_message'; err = new Error('foo'); originalStack = err.stack; diff --git a/test/parallel/test-module-symlinked-peer-modules.js b/test/parallel/test-module-symlinked-peer-modules.js index 09ba4b17b55f3b..fb02a8a94d5d66 100644 --- a/test/parallel/test-module-symlinked-peer-modules.js +++ b/test/parallel/test-module-symlinked-peer-modules.js @@ -59,4 +59,4 @@ fs.writeFileSync(path.join(moduleB, 'package.json'), fs.writeFileSync(path.join(moduleB, 'index.js'), 'module.exports = 1;', 'utf8'); -require(path.join(app, 'index')); +require(path.join(app, 'index')); // Should not throw. diff --git a/test/parallel/test-net-after-close.js b/test/parallel/test-net-after-close.js index 23e265c09a954a..0750ba0f435512 100644 --- a/test/parallel/test-net-after-close.js +++ b/test/parallel/test-net-after-close.js @@ -34,6 +34,8 @@ server.listen(0, common.mustCall(function() { c.on('close', common.mustCall(function() { console.error('connection closed'); assert.strictEqual(c._handle, null); + // Calling functions / accessing properties of a closed socket should not + // throw. c.setNoDelay(); c.setKeepAlive(); c.bufferSize; diff --git a/test/parallel/test-net-during-close.js b/test/parallel/test-net-during-close.js index 11c3dab00f2ec6..7bceb64041f2cc 100644 --- a/test/parallel/test-net-during-close.js +++ b/test/parallel/test-net-during-close.js @@ -30,11 +30,11 @@ const server = net.createServer(function(socket) { server.listen(0, common.mustCall(function() { const client = net.createConnection(this.address().port); server.close(); - // server connection event has not yet fired - // client is still attempting to connect + // Server connection event has not yet fired client is still attempting to + // connect. Accessing properties should not throw in this case. client.remoteAddress; client.remoteFamily; client.remotePort; - // exit now, do not wait for the client error event + // Exit now, do not wait for the client error event. process.exit(0); })); diff --git a/test/parallel/test-process-geteuid-getegid.js b/test/parallel/test-process-geteuid-getegid.js index 96e8765eb99015..41e37874a41b59 100644 --- a/test/parallel/test-process-geteuid-getegid.js +++ b/test/parallel/test-process-geteuid-getegid.js @@ -21,6 +21,7 @@ assert.throws(() => { // If we're not running as super user... if (process.getuid() !== 0) { + // Should not throw. process.getegid(); process.geteuid(); diff --git a/test/parallel/test-process-setuid-setgid.js b/test/parallel/test-process-setuid-setgid.js index 0060e3b1ca4af4..41fef8c9c819fa 100644 --- a/test/parallel/test-process-setuid-setgid.js +++ b/test/parallel/test-process-setuid-setgid.js @@ -39,6 +39,7 @@ assert.throws(() => { // If we're not running as super user... if (process.getuid() !== 0) { + // Should not throw. process.getgid(); process.getuid(); diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index b0ed9c4ea1d30c..2090d76b75ee34 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -300,7 +300,7 @@ assert.strictEqual('foo=', qs.stringify({ foo: Infinity })); assert.strictEqual(f, 'a=b&q=x%3Dy%26y%3Dz'); } -qs.parse(undefined); +qs.parse(undefined); // Should not throw. // nested in colon { diff --git a/test/parallel/test-readline-csi.js b/test/parallel/test-readline-csi.js index 54ca6bde97bbe9..f5c2d3044c5cdf 100644 --- a/test/parallel/test-readline-csi.js +++ b/test/parallel/test-readline-csi.js @@ -61,6 +61,7 @@ assert.deepStrictEqual(writable.data, CSI.kClearLine); assert.deepStrictEqual(writable.data, set[2]); }); +// Undefined or null as stream should not throw. readline.cursorTo(null); readline.cursorTo(); diff --git a/test/parallel/test-stream-writable-null.js b/test/parallel/test-stream-writable-null.js index 706141821be175..63e122a3b496e1 100644 --- a/test/parallel/test-stream-writable-null.js +++ b/test/parallel/test-stream-writable-null.js @@ -27,13 +27,9 @@ common.expectsError( } ); -{ - const m = new MyWritable({ objectMode: true }).on('error', (e) => { - assert.ok(e); - }); - m.write(null, (err) => { - assert.ok(err); - }); +{ // Should not throw. + const m = new MyWritable({ objectMode: true }).on('error', assert); + m.write(null, assert); } common.expectsError( @@ -47,25 +43,19 @@ common.expectsError( } ); -{ - const m = new MyWritable().on('error', (e) => { - assert.ok(e); - }); - m.write(false, (err) => { - assert.ok(err); - }); +{ // Should not throw. + const m = new MyWritable().on('error', assert); + m.write(false, assert); } -{ +{ // Should not throw. const m = new MyWritable({ objectMode: true }); - m.write(false, (err) => assert.ifError(err)); + m.write(false, assert.ifError); } -{ +{ // Should not throw. const m = new MyWritable({ objectMode: true }).on('error', (e) => { assert.ifError(e || new Error('should not get here')); }); - m.write(false, (err) => { - assert.ifError(err); - }); + m.write(false, assert.ifError); } diff --git a/test/parallel/test-timers-unref.js b/test/parallel/test-timers-unref.js index d8624d8d9c9099..8c4891f1ed6459 100644 --- a/test/parallel/test-timers-unref.js +++ b/test/parallel/test-timers-unref.js @@ -30,6 +30,7 @@ let checks = 0; const LONG_TIME = 10 * 1000; const SHORT_TIME = 100; +// Should not throw. setTimeout(() => {}, 10).unref().ref().unref(); setInterval(() => {}, 10).unref().ref().unref(); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 9133887a7570a7..ec9afc677b67bc 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -146,7 +146,7 @@ for (const showHidden of [true, false]) { ' y: 1337 }'); } -// Now do the same checks but from a different context +// Now do the same checks but from a different context. for (const showHidden of [true, false]) { const ab = vm.runInNewContext('new ArrayBuffer(4)'); const dv = vm.runInNewContext('new DataView(ab, 1, 2)', { ab }); @@ -211,7 +211,7 @@ for (const showHidden of [true, false]) { ); }); -// Now check that declaring a TypedArray in a different context works the same +// Now check that declaring a TypedArray in a different context works the same. [ Float32Array, Float64Array, Int16Array, @@ -252,7 +252,7 @@ assert.strictEqual( }), { showHidden: true }), '{ visible: 1, [hidden]: 2 }' ); -// Objects without prototype +// Objects without prototype. assert.strictEqual( util.inspect(Object.create(null, { name: { value: 'Tim', enumerable: true }, @@ -269,7 +269,7 @@ assert.strictEqual( '{ name: \'Tim\' }' ); -// Dynamic properties +// Dynamic properties. { assert.strictEqual( util.inspect({ get readonly() {} }), @@ -288,7 +288,7 @@ assert.strictEqual( assert.strictEqual(util.inspect(value), '{ a: [Circular] }'); } -// Array with dynamic properties +// Array with dynamic properties. { const value = [1, 2, 3]; Object.defineProperty( @@ -311,7 +311,7 @@ assert.strictEqual( '[ 1, 2, 3, growingLength: [Getter], \'-1\': -1 ]'); } -// Array with inherited number properties +// Array with inherited number properties. { class CustomArray extends Array {} CustomArray.prototype[5] = 'foo'; @@ -319,7 +319,7 @@ assert.strictEqual( assert.strictEqual(util.inspect(arr), 'CustomArray [ <50 empty items> ]'); } -// Array with extra properties +// Array with extra properties. { const arr = [1, 2, 3, , ]; arr.foo = 'bar'; @@ -351,10 +351,10 @@ assert.strictEqual( assert.strictEqual(util.inspect(arr3), "[ '-1': -1 ]"); } -// Indices out of bounds +// Indices out of bounds. { const arr = []; - arr[2 ** 32] = true; // not a valid array index + arr[2 ** 32] = true; // Not a valid array index. assert.strictEqual(util.inspect(arr), "[ '4294967296': true ]"); arr[0] = true; arr[10] = true; @@ -374,28 +374,28 @@ assert.strictEqual( ].join('\n ')); } -// Function with properties +// Function with properties. { const value = () => {}; value.aprop = 42; assert.strictEqual(util.inspect(value), '{ [Function: value] aprop: 42 }'); } -// Anonymous function with properties +// Anonymous function with properties. { const value = (() => function() {})(); value.aprop = 42; assert.strictEqual(util.inspect(value), '{ [Function] aprop: 42 }'); } -// Regular expressions with properties +// Regular expressions with properties. { const value = /123/ig; value.aprop = 42; assert.strictEqual(util.inspect(value), '{ /123/gi aprop: 42 }'); } -// Dates with properties +// Dates with properties. { const value = new Date('Sun, 14 Feb 2010 11:48:40 GMT'); value.aprop = 42; @@ -403,7 +403,7 @@ assert.strictEqual( '{ 2010-02-14T11:48:40.000Z aprop: 42 }'); } -// test the internal isDate implementation +// Test the internal isDate implementation. { const Date2 = vm.runInNewContext('Date'); const d = new Date2(); @@ -413,13 +413,13 @@ assert.strictEqual( assert.strictEqual(orig, after); } -// test positive/negative zero +// Test positive/negative zero. assert.strictEqual(util.inspect(0), '0'); assert.strictEqual(util.inspect(-0), '-0'); -// edge case from check +// Edge case from check. assert.strictEqual(util.inspect(-5e-324), '-5e-324'); -// test for sparse array +// Test for sparse array. { const a = ['foo', 'bar', 'baz']; assert.strictEqual(util.inspect(a), '[ \'foo\', \'bar\', \'baz\' ]'); @@ -443,7 +443,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); ); } -// test for Array constructor in different context +// Test for Array constructor in different context. { const Debug = vm.runInDebugContext('Debug'); const map = new Map(); @@ -458,7 +458,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]'); } -// test for other constructors in different context +// Test for other constructors in different context. { let obj = vm.runInNewContext('(function(){return {}})()', {}); assert.strictEqual(util.inspect(obj), '{}'); @@ -470,7 +470,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); assert.strictEqual(util.inspect(obj), 'Promise { }'); } -// test for property descriptors +// Test for property descriptors. { const getter = Object.create(null, { a: { @@ -496,7 +496,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); ); } -// exceptions should print the error message, not '{}' +// Exceptions should print the error message, not '{}'. { const errors = []; errors.push(new Error()); @@ -517,7 +517,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); assert(ex.includes('[message]')); } -// Doesn't capture stack trace +// Doesn't capture stack trace. { function BadCustomError(msg) { Error.call(this); @@ -534,7 +534,6 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); } // GH-1941 -// should not throw: assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}'); // GH-1944 @@ -544,20 +543,20 @@ assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}'); util.inspect(d); } +// Should not throw. { const d = new Date(); d.toISOString = null; util.inspect(d); } +// Should not throw. const r = /regexp/; r.toString = null; util.inspect(r); -// bug with user-supplied inspect function returns non-string -util.inspect([{ - inspect: () => 123 -}]); +// Bug with user-supplied inspect function returns non-string. +util.inspect([{ inspect: () => 123 }]); // GH-2225 { @@ -593,7 +592,7 @@ util.inspect([{ ); } -// util.inspect.styles and util.inspect.colors +// Test util.inspect.styles and util.inspect.colors. { function testColorStyle(style, input, implicit) { const colorName = util.inspect.styles[style]; @@ -620,12 +619,10 @@ util.inspect([{ testColorStyle('regexp', /regexp/); } -// an object with "hasOwnProperty" overwritten should not throw -util.inspect({ - hasOwnProperty: null -}); +// An object with "hasOwnProperty" overwritten should not throw. +util.inspect({ hasOwnProperty: null }); -// new API, accepts an "options" object +// New API, accepts an "options" object. { const subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } }; Object.defineProperty(subject, 'hidden', { enumerable: false, value: null }); @@ -665,7 +662,7 @@ util.inspect({ } { - // "customInspect" option can enable/disable calling inspect() on objects + // "customInspect" option can enable/disable calling inspect() on objects. const subject = { inspect: () => 123 }; assert.strictEqual( @@ -685,7 +682,7 @@ util.inspect({ true ); - // custom inspect() functions should be able to return other Objects + // Custom inspect() functions should be able to return other Objects. subject.inspect = () => ({ foo: 'bar' }); assert.strictEqual(util.inspect(subject), '{ foo: \'bar\' }'); @@ -698,7 +695,7 @@ util.inspect({ } { - // "customInspect" option can enable/disable calling [util.inspect.custom]() + // "customInspect" option can enable/disable calling [util.inspect.custom](). const subject = { [util.inspect.custom]: () => 123 }; assert.strictEqual( @@ -710,7 +707,7 @@ util.inspect({ false ); - // a custom [util.inspect.custom]() should be able to return other Objects + // A custom [util.inspect.custom]() should be able to return other Objects. subject[util.inspect.custom] = () => ({ foo: 'bar' }); assert.strictEqual(util.inspect(subject), '{ foo: \'bar\' }'); @@ -723,7 +720,7 @@ util.inspect({ } { - // [util.inspect.custom] takes precedence over inspect + // [util.inspect.custom] takes precedence over inspect. const subject = { [util.inspect.custom]() { return 123; }, inspect() { return 456; } @@ -758,7 +755,7 @@ util.inspect({ `{ a: 123,\n [Symbol(${UIC})]: [Function: [${UIC}]] }`); } -// util.inspect with "colors" option should produce as many lines as without it +// util.inspect with "colors" option should produce as many lines as without it. { function testLines(input) { const countLines = (str) => (str.match(/\n/g) || []).length; @@ -782,7 +779,7 @@ util.inspect({ }); } -// test boxed primitives output the correct values +// Test boxed primitives output the correct values. assert.strictEqual(util.inspect(new String('test')), '[String: \'test\']'); assert.strictEqual( util.inspect(Object(Symbol('test'))), @@ -795,7 +792,7 @@ assert.strictEqual(util.inspect(new Number(-0)), '[Number: -0]'); assert.strictEqual(util.inspect(new Number(-1.1)), '[Number: -1.1]'); assert.strictEqual(util.inspect(new Number(13.37)), '[Number: 13.37]'); -// test boxed primitives with own properties +// Test boxed primitives with own properties. { const str = new String('baz'); str.foo = 'bar'; @@ -810,7 +807,7 @@ assert.strictEqual(util.inspect(new Number(13.37)), '[Number: 13.37]'); assert.strictEqual(util.inspect(num), '{ [Number: 13.37] foo: \'bar\' }'); } -// test es6 Symbol +// Test es6 Symbol. if (typeof Symbol !== 'undefined') { assert.strictEqual(util.inspect(Symbol()), 'Symbol()'); assert.strictEqual(util.inspect(Symbol(123)), 'Symbol(123)'); @@ -846,7 +843,7 @@ if (typeof Symbol !== 'undefined') { '[ 1, 2, 3, [Symbol(symbol)]: 42 ]'); } -// test Set +// Test Set. { assert.strictEqual(util.inspect(new Set()), 'Set {}'); assert.strictEqual(util.inspect(new Set([1, 2, 3])), 'Set { 1, 2, 3 }'); @@ -858,14 +855,14 @@ if (typeof Symbol !== 'undefined') { ); } -// Test circular Set +// Test circular Set. { const set = new Set(); set.add(set); assert.strictEqual(util.inspect(set), 'Set { [Circular] }'); } -// test Map +// Test Map. { assert.strictEqual(util.inspect(new Map()), 'Map {}'); assert.strictEqual(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), @@ -876,7 +873,7 @@ if (typeof Symbol !== 'undefined') { 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); } -// Test circular Map +// Test circular Map. { const map = new Map(); map.set(map, 'map'); @@ -888,14 +885,14 @@ if (typeof Symbol !== 'undefined') { assert.strictEqual(util.inspect(map), "Map { 'map' => [Circular] }"); } -// test Promise +// Test Promise. { const resolved = Promise.resolve(3); assert.strictEqual(util.inspect(resolved), 'Promise { 3 }'); const rejected = Promise.reject(3); assert.strictEqual(util.inspect(rejected), 'Promise { 3 }'); - // squelch UnhandledPromiseRejection + // Squelch UnhandledPromiseRejection. rejected.catch(() => {}); const pending = new Promise(() => {}); @@ -917,33 +914,33 @@ if (typeof Symbol !== 'undefined') { global.Promise = oldPromise; } -// Test Map iterators +// Test Map iterators. { const map = new Map([['foo', 'bar']]); assert.strictEqual(util.inspect(map.keys()), 'MapIterator { \'foo\' }'); assert.strictEqual(util.inspect(map.values()), 'MapIterator { \'bar\' }'); assert.strictEqual(util.inspect(map.entries()), 'MapIterator { [ \'foo\', \'bar\' ] }'); - // make sure the iterator doesn't get consumed + // Make sure the iterator doesn't get consumed. const keys = map.keys(); assert.strictEqual(util.inspect(keys), 'MapIterator { \'foo\' }'); assert.strictEqual(util.inspect(keys), 'MapIterator { \'foo\' }'); } -// Test Set iterators +// Test Set iterators. { const aSet = new Set([1, 3]); assert.strictEqual(util.inspect(aSet.keys()), 'SetIterator { 1, 3 }'); assert.strictEqual(util.inspect(aSet.values()), 'SetIterator { 1, 3 }'); assert.strictEqual(util.inspect(aSet.entries()), 'SetIterator { [ 1, 1 ], [ 3, 3 ] }'); - // make sure the iterator doesn't get consumed + // Make sure the iterator doesn't get consumed. const keys = aSet.keys(); assert.strictEqual(util.inspect(keys), 'SetIterator { 1, 3 }'); assert.strictEqual(util.inspect(keys), 'SetIterator { 1, 3 }'); } -// Test alignment of items in container +// Test alignment of items in container. // Assumes that the first numeric character is the start of an item. { function checkAlignment(container) { @@ -978,7 +975,7 @@ if (typeof Symbol !== 'undefined') { } -// Test display of constructors +// Test display of constructors. { class ObjectSubclass {} class ArraySubclass extends Array {} @@ -1004,7 +1001,7 @@ if (typeof Symbol !== 'undefined') { ); } -// Empty and circular before depth +// Empty and circular before depth. { const arr = [[[[]]]]; assert.strictEqual(util.inspect(arr), '[ [ [ [] ] ] ]'); @@ -1100,14 +1097,14 @@ if (typeof Symbol !== 'undefined') { assert.strictEqual(twoLines, '{ foo: \'abc\',\n bar: \'xyz\' }'); } -// util.inspect.defaultOptions tests +// util.inspect.defaultOptions tests. { const arr = new Array(101).fill(); const obj = { a: { a: { a: { a: 1 } } } }; const oldOptions = Object.assign({}, util.inspect.defaultOptions); - // Set single option through property assignment + // Set single option through property assignment. util.inspect.defaultOptions.maxArrayLength = null; assert(!/1 more item/.test(util.inspect(arr))); util.inspect.defaultOptions.maxArrayLength = oldOptions.maxArrayLength; @@ -1121,7 +1118,7 @@ if (typeof Symbol !== 'undefined') { JSON.stringify(oldOptions) ); - // Set multiple options through object assignment + // Set multiple options through object assignment. util.inspect.defaultOptions = { maxArrayLength: null, depth: null }; assert(!/1 more item/.test(util.inspect(arr))); assert(!/Object/.test(util.inspect(obj))); diff --git a/test/parallel/test-vm-create-context-arg.js b/test/parallel/test-vm-create-context-arg.js index f5497153815de3..2bcdc8573fe311 100644 --- a/test/parallel/test-vm-create-context-arg.js +++ b/test/parallel/test-vm-create-context-arg.js @@ -28,6 +28,7 @@ assert.throws(function() { vm.createContext('string is not supported'); }, /^TypeError: sandbox must be an object$/); +// Should not throw. vm.createContext({ a: 1 }); vm.createContext([0, 1, 2, 3]); diff --git a/test/parallel/test-vm-cross-context.js b/test/parallel/test-vm-cross-context.js index 785cc9d7bd06bb..b7cf1309d3689f 100644 --- a/test/parallel/test-vm-cross-context.js +++ b/test/parallel/test-vm-cross-context.js @@ -25,4 +25,5 @@ require('../common'); const vm = require('vm'); const ctx = vm.createContext(global); +// Should not throw. vm.runInContext('!function() { var x = console.log; }()', ctx); diff --git a/test/pummel/test-fs-largefile.js b/test/pummel/test-fs-largefile.js index 369f8311925474..2e9dda0495bd6e 100644 --- a/test/pummel/test-fs-largefile.js +++ b/test/pummel/test-fs-largefile.js @@ -44,6 +44,7 @@ assert.strictEqual(readBuf.toString(), message); fs.readSync(fd, readBuf, 0, 1, 0); assert.strictEqual(readBuf[0], 0); +// Verify that floating point positions do not throw. fs.writeSync(fd, writeBuf, 0, writeBuf.length, 42.000001); fs.close(fd); diff --git a/test/pummel/test-fs-watch-file.js b/test/pummel/test-fs-watch-file.js index 62abf0c18fc969..e9d208778faf3f 100644 --- a/test/pummel/test-fs-watch-file.js +++ b/test/pummel/test-fs-watch-file.js @@ -68,6 +68,7 @@ assert.throws( } ); +// Does not throw. fs.watchFile(filepathOne, function() { fs.unwatchFile(filepathOne); ++watchSeenOne; @@ -91,7 +92,7 @@ assert.throws( } ); -{ +{ // Does not throw. function a() { fs.unwatchFile(filepathTwo, a); ++watchSeenTwo; @@ -108,7 +109,7 @@ setTimeout(function() { fs.writeFileSync(filepathTwoAbs, 'pardner'); }, 1000); -{ +{ // Does not throw. function b() { fs.unwatchFile(filenameThree, b); ++watchSeenThree; @@ -130,7 +131,7 @@ setTimeout(function() { fs.writeFileSync(filenameFour, 'hey'); }, 500); -{ +{ // Does not throw. function a() { ++watchSeenFour; assert.strictEqual(1, watchSeenFour); diff --git a/test/sequential/test-inspector-module.js b/test/sequential/test-inspector-module.js index 5b793bf3b43d55..f97d71297971f7 100644 --- a/test/sequential/test-inspector-module.js +++ b/test/sequential/test-inspector-module.js @@ -56,4 +56,5 @@ common.expectsError( ); session.disconnect(); +// Calling disconnect twice should not throw. session.disconnect(); diff --git a/test/sequential/test-performance.js b/test/sequential/test-performance.js index 80bfe217a0518e..770ca7bf6407be 100644 --- a/test/sequential/test-performance.js +++ b/test/sequential/test-performance.js @@ -70,7 +70,7 @@ assert(inited < 20000); { performance.mark('A'); [undefined, null, 'foo', 'initialize', 1].forEach((i) => { - performance.measure('test', i, 'A'); + performance.measure('test', i, 'A'); // Should not throw. }); [undefined, null, 'foo', 1].forEach((i) => {