From 3f20b00b35d9ce565dac650d857d1ff0a7f759c7 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 18 Apr 2016 21:43:10 -0700 Subject: [PATCH 1/2] benchmark,lib,test,tools: align function arguments In preparation for a lint rule that will enforce alignment of arguments in function calls that span multiple lines, align them in files where they are not currently aligned. --- benchmark/tls/tls-connect.js | 22 +- lib/crypto.js | 19 +- lib/readline.js | 20 +- lib/util.js | 4 +- test/common.js | 4 +- .../test-dgram-multicast-multi-process.js | 2 +- test/parallel/test-assert.js | 36 +- test/parallel/test-buffer-alloc.js | 48 +- test/parallel/test-buffer-bytelength.js | 6 +- test/parallel/test-buffer-includes.js | 8 +- test/parallel/test-buffer-indexof.js | 33 +- test/parallel/test-buffer-inheritance.js | 2 +- test/parallel/test-buffer-swap.js | 22 +- test/parallel/test-buffer.js | 44 +- test/parallel/test-cli-eval.js | 79 +- test/parallel/test-cluster-basic.js | 4 +- test/parallel/test-crypto-authenticated.js | 29 +- test/parallel/test-crypto-binary-default.js | 32 +- test/parallel/test-crypto-ecb.js | 2 +- test/parallel/test-crypto-hash.js | 7 +- test/parallel/test-crypto-hmac.js | 9 +- test/parallel/test-crypto-padding-aes256.js | 3 +- test/parallel/test-crypto-rsa-dsa.js | 8 +- test/parallel/test-crypto.js | 6 +- test/parallel/test-debug-agent.js | 2 +- .../parallel/test-debugger-util-regression.js | 2 +- test/parallel/test-dns.js | 2 +- .../test-domain-exit-dispose-again.js | 2 +- ...tack-empty-in-process-uncaughtexception.js | 4 +- ...n-throw-from-uncaught-exception-handler.js | 50 +- test/parallel/test-domain-timers.js | 4 +- ...in-top-level-error-handler-clears-stack.js | 2 +- ...domain-with-abort-on-uncaught-exception.js | 2 +- test/parallel/test-file-write-stream2.js | 4 +- test/parallel/test-file-write-stream3.js | 4 +- test/parallel/test-fs-realpath.js | 12 +- test/parallel/test-fs-write.js | 35 +- .../parallel/test-http-agent-error-on-idle.js | 2 +- test/parallel/test-http-agent-keepalive.js | 2 +- test/parallel/test-http-agent-maxsockets.js | 2 +- .../test-http-destroyed-socket-write2.js | 6 +- test/parallel/test-http-parser-bad-ref.js | 3 +- test/parallel/test-http-url.parse-post.js | 2 +- test/parallel/test-module-relative-lookup.js | 7 +- test/parallel/test-net-pipe-connect-errors.js | 2 +- .../test-promises-unhandled-rejections.js | 916 ++++++++++-------- test/parallel/test-readline-interface.js | 20 +- test/parallel/test-regress-GH-4948.js | 19 +- test/parallel/test-require-process.js | 7 +- test/parallel/test-require-symlink.js | 22 +- test/parallel/test-stdin-child-proc.js | 6 +- test/parallel/test-tick-processor.js | 30 +- test/parallel/test-timers-ordering.js | 2 +- ...st-timers-reset-process-domain-on-throw.js | 6 +- .../test-timers-throw-when-cb-not-function.js | 36 +- test/parallel/test-timers-unref-leak.js | 3 +- test/parallel/test-tls-peer-certificate.js | 2 +- test/parallel/test-util-inspect.js | 66 +- test/parallel/test-vm-symbols.js | 4 +- .../parallel/test-zlib-convenience-methods.js | 35 +- test/parallel/test-zlib-flush-drain.js | 8 +- .../test-zlib-from-concatenated-gzip.js | 9 +- .../test-zlib-unzip-one-byte-chunks.js | 2 +- test/sequential/test-init.js | 32 +- tools/doc/html.js | 10 +- 65 files changed, 1028 insertions(+), 807 deletions(-) diff --git a/benchmark/tls/tls-connect.js b/benchmark/tls/tls-connect.js index a265989e04db..342c7cb7e37d 100644 --- a/benchmark/tls/tls-connect.js +++ b/benchmark/tls/tls-connect.js @@ -42,16 +42,18 @@ function onConnection(conn) { } function makeConnection() { - var conn = tls.connect({ port: common.PORT, - rejectUnauthorized: false }, function() { - clientConn++; - conn.on('error', function(er) { - console.error('client error', er); - throw er; - }); - conn.end(); - if (running) makeConnection(); - }); + var conn = tls.connect( + { port: common.PORT, rejectUnauthorized: false }, + function() { + clientConn++; + conn.on('error', function(er) { + console.error('client error', er); + throw er; + }); + conn.end(); + if (running) makeConnection(); + } + ); } function done() { diff --git a/lib/crypto.js b/lib/crypto.js index 534ff0391735..f295111d23e8 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -662,13 +662,12 @@ function filterDuplicates(names) { } // Legacy API -exports.__defineGetter__('createCredentials', - internalUtil.deprecate(function() { - return require('tls').createSecureContext; - }, 'crypto.createCredentials is deprecated. ' + - 'Use tls.createSecureContext instead.')); - -exports.__defineGetter__('Credentials', internalUtil.deprecate(function() { - return require('tls').SecureContext; -}, 'crypto.Credentials is deprecated. ' + - 'Use tls.createSecureContext instead.')); +function defineLegacyGetter(legacyName, tlsName) { + function wrapped() { + return require('tls')[tlsName]; + } + const msg = `crypto.${legacyName} is deprecated. Use tls.${tlsName} instead.`; + exports.__defineGetter__(legacyName, internalUtil.deprecate(wrapped, msg)); +} +defineLegacyGetter('createCredentials', 'createSecureContext'); +defineLegacyGetter('Credentials', 'SecureContext'); diff --git a/lib/readline.js b/lib/readline.js index 3948d990539d..2095a1a57a1e 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -1055,17 +1055,23 @@ function codePointAt(str, index) { } return code; } -exports.codePointAt = internalUtil.deprecate(codePointAt, - 'readline.codePointAt is deprecated. ' + - 'Use String.prototype.codePointAt instead.'); +exports.codePointAt = internalUtil.deprecate( + codePointAt, + 'readline.codePointAt is deprecated. ' + + 'Use String.prototype.codePointAt instead.' +); -exports.getStringWidth = internalUtil.deprecate(getStringWidth, - 'getStringWidth is deprecated and will be removed.'); +exports.getStringWidth = internalUtil.deprecate( + getStringWidth, + 'getStringWidth is deprecated and will be removed.' +); -exports.isFullWidthCodePoint = internalUtil.deprecate(isFullWidthCodePoint, - 'isFullWidthCodePoint is deprecated and will be removed.'); +exports.isFullWidthCodePoint = internalUtil.deprecate( + isFullWidthCodePoint, + 'isFullWidthCodePoint is deprecated and will be removed.' +); exports.stripVTControlCharacters = internalUtil.deprecate( diff --git a/lib/util.js b/lib/util.js index 63d6d0f3c865..cb06ea233e44 100644 --- a/lib/util.js +++ b/lib/util.js @@ -541,7 +541,7 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { for (var i = 0, l = value.length; i < l; ++i) { if (hasOwnProperty(value, String(i))) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - String(i), true)); + String(i), true)); } else { output.push(''); } @@ -549,7 +549,7 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { keys.forEach(function(key) { if (typeof key === 'symbol' || !key.match(/^\d+$/)) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, true)); + key, true)); } }); return output; diff --git a/test/common.js b/test/common.js index 48f8ea719c5c..c67e438af760 100644 --- a/test/common.js +++ b/test/common.js @@ -398,7 +398,7 @@ exports.mustCall = function(fn, expected) { var etcServicesFileName = path.join('/etc', 'services'); if (exports.isWindows) { etcServicesFileName = path.join(process.env.SystemRoot, 'System32', 'drivers', - 'etc', 'services'); + 'etc', 'services'); } /* @@ -428,7 +428,7 @@ exports.getServiceName = function getServiceName(port, protocol) { try { var servicesContent = fs.readFileSync(etcServicesFileName, - { encoding: 'utf8'}); + { encoding: 'utf8'}); var regexp = `^(\\w+)\\s+\\s${port}/${protocol}\\s`; var re = new RegExp(regexp, 'm'); diff --git a/test/internet/test-dgram-multicast-multi-process.js b/test/internet/test-dgram-multicast-multi-process.js index 54df63ba7697..b2bed3a4bda0 100644 --- a/test/internet/test-dgram-multicast-multi-process.js +++ b/test/internet/test-dgram-multicast-multi-process.js @@ -91,7 +91,7 @@ function launchChildProcess(index) { worker.pid, count); assert.strictEqual(count, messages.length, - 'A worker received an invalid multicast message'); + 'A worker received an invalid multicast message'); }); clearTimeout(timer); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index cf5b7d4c9933..64d9d61d3969 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -29,7 +29,7 @@ assert.doesNotThrow(makeBlock(a.ok, true), assert.doesNotThrow(makeBlock(a.ok, 'test'), 'ok(\'test\')'); assert.throws(makeBlock(a.equal, true, false), - a.AssertionError, 'equal(true, false)'); + a.AssertionError, 'equal(true, false)'); assert.doesNotThrow(makeBlock(a.equal, null, null), 'equal(null, null)'); @@ -61,9 +61,10 @@ assert.doesNotThrow(makeBlock(a.notStrictEqual, 2, '2'), // deepEquals joy! // 7.2 -assert.doesNotThrow(makeBlock(a.deepEqual, new Date(2000, 3, 14), - new Date(2000, 3, 14)), - 'deepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))'); +assert.doesNotThrow( + makeBlock(a.deepEqual, new Date(2000, 3, 14), new Date(2000, 3, 14)), + 'deepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))' +); assert.throws(makeBlock(a.deepEqual, new Date(), new Date(2000, 3, 14)), a.AssertionError, @@ -163,10 +164,10 @@ assert.doesNotThrow(makeBlock(a.deepEqual, new Boolean(true), {}), a.AssertionError); //deepStrictEqual -assert.doesNotThrow(makeBlock(a.deepStrictEqual, new Date(2000, 3, 14), - new Date(2000, 3, 14)), - 'deepStrictEqual(new Date(2000, 3, 14),\ - new Date(2000, 3, 14))'); +assert.doesNotThrow( + makeBlock(a.deepStrictEqual, new Date(2000, 3, 14), new Date(2000, 3, 14)), + 'deepStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))' +); assert.throws(makeBlock(a.deepStrictEqual, new Date(), new Date(2000, 3, 14)), a.AssertionError, @@ -331,10 +332,13 @@ assert.throws(function() {assert.ifError(new Error('test error'));}); assert.doesNotThrow(function() {assert.ifError(null);}); assert.doesNotThrow(function() {assert.ifError();}); -assert.throws(() => { - assert.doesNotThrow(makeBlock(thrower, Error), 'user message'); -}, /Got unwanted exception. user message/, - 'a.doesNotThrow ignores user message'); +assert.throws( + () => { + assert.doesNotThrow(makeBlock(thrower, Error), 'user message'); + }, + /Got unwanted exception. user message/, + 'a.doesNotThrow ignores user message' +); // make sure that validating using constructor really works threw = false; @@ -376,7 +380,7 @@ try { } catch (e) { threw = true; assert(e instanceof AnotherErrorType, - `expected AnotherErrorType, received ${e}`); + `expected AnotherErrorType, received ${e}`); } assert.ok(threw); @@ -410,7 +414,7 @@ function testAssertionMessage(actual, expected) { assert.equal(actual, ''); } catch (e) { assert.equal(e.toString(), - ['AssertionError:', expected, '==', '\'\''].join(' ')); + ['AssertionError:', expected, '==', '\'\''].join(' ')); assert.ok(e.generatedMessage, 'Message not marked as generated'); } } @@ -436,7 +440,7 @@ testAssertionMessage({}, '{}'); testAssertionMessage(circular, '{ y: 1, x: [Circular] }'); testAssertionMessage({a: undefined, b: null}, '{ a: undefined, b: null }'); testAssertionMessage({a: NaN, b: Infinity, c: -Infinity}, - '{ a: NaN, b: Infinity, c: -Infinity }'); + '{ a: NaN, b: Infinity, c: -Infinity }'); // #2893 try { @@ -462,7 +466,7 @@ try { } catch (e) { assert.equal(e.toString().split('\n')[0], 'AssertionError: oh no'); assert.equal(e.generatedMessage, false, - 'Message incorrectly marked as generated'); + 'Message incorrectly marked as generated'); } // Verify that throws() and doesNotThrow() throw on non-function block diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 85b6abbcdabe..5075875d3887 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -490,8 +490,8 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { { const f = Buffer.from('привет', encoding); console.error('f.length: %d (should be 12)', f.length); - assert.deepStrictEqual(f, - Buffer.from([63, 4, 64, 4, 56, 4, 50, 4, 53, 4, 66, 4])); + const expected = Buffer.from([63, 4, 64, 4, 56, 4, 50, 4, 53, 4, 66, 4]); + assert.deepStrictEqual(f, expected); assert.equal(f.toString(encoding), 'привет'); } @@ -645,18 +645,30 @@ assert.equal(Buffer.from('KioqKioqKioqKioqKioqKioqKio', 'base64').toString(), '********************'); // handle padding graciously, multiple-of-4 or not -assert.equal(Buffer.from('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==', - 'base64').length, 32); -assert.equal(Buffer.from('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=', - 'base64').length, 32); -assert.equal(Buffer.from('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', - 'base64').length, 32); -assert.equal(Buffer.from('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', - 'base64').length, 31); -assert.equal(Buffer.from('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', - 'base64').length, 31); -assert.equal(Buffer.from('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', - 'base64').length, 31); +assert.equal( + Buffer.from('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==', 'base64').length, + 32 +); +assert.equal( + Buffer.from('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=', 'base64').length, + 32 +); +assert.equal( + Buffer.from('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', 'base64').length, + 32 +); +assert.equal( + Buffer.from('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', 'base64').length, + 31 +); +assert.equal( + Buffer.from('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', 'base64').length, + 31 +); +assert.equal( + Buffer.from('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', 'base64').length, + 31 +); // This string encodes single '.' character in UTF-16 var dot = Buffer.from('//4uAA==', 'base64'); @@ -1131,16 +1143,16 @@ assert.throws(function() { var buf = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]); assert.equal(buf['readUInt' + bits + 'BE'](0), - (0xFFFFFFFF >>> (32 - bits))); + 0xFFFFFFFF >>> (32 - bits)); assert.equal(buf['readUInt' + bits + 'LE'](0), - (0xFFFFFFFF >>> (32 - bits))); + 0xFFFFFFFF >>> (32 - bits)); assert.equal(buf['readInt' + bits + 'BE'](0), - (0xFFFFFFFF >> (32 - bits))); + 0xFFFFFFFF >> (32 - bits)); assert.equal(buf['readInt' + bits + 'LE'](0), - (0xFFFFFFFF >> (32 - bits))); + 0xFFFFFFFF >> (32 - bits)); }); // test for common read(U)IntLE/BE diff --git a/test/parallel/test-buffer-bytelength.js b/test/parallel/test-buffer-bytelength.js index 01bf12e54490..c91286318fa2 100644 --- a/test/parallel/test-buffer-bytelength.js +++ b/test/parallel/test-buffer-bytelength.js @@ -71,8 +71,10 @@ assert.equal(Buffer.byteLength('ßœ∑≈', 'unkn0wn enc0ding'), 10); assert.equal(Buffer.byteLength('aGVsbG8gd29ybGQ=', 'base64'), 11); assert.equal(Buffer.byteLength('bm9kZS5qcyByb2NrcyE=', 'base64'), 14); assert.equal(Buffer.byteLength('aGkk', 'base64'), 3); -assert.equal(Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==', - 'base64'), 25); +assert.equal( + Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==', 'base64'), + 25 +); // special padding assert.equal(Buffer.byteLength('aaa=', 'base64'), 2); assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3); diff --git a/test/parallel/test-buffer-includes.js b/test/parallel/test-buffer-includes.js index 2d46e1b6e6f6..f2c9b16579e6 100644 --- a/test/parallel/test-buffer-includes.js +++ b/test/parallel/test-buffer-includes.js @@ -130,11 +130,11 @@ assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2')); assert( 6, mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2')); assert( - 10, mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), - 0, 'ucs2')); + 10, + mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2')); assert( - -1, mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), - 0, 'ucs2')); + -1, + mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2')); twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index 0a20d2ce9af0..40e9e421e6b9 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -81,43 +81,54 @@ assert.equal(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1); // test hex encoding assert.equal( Buffer.from(b.toString('hex'), 'hex') - .indexOf('64', 0, 'hex'), 3); + .indexOf('64', 0, 'hex'), + 3); assert.equal( Buffer.from(b.toString('hex'), 'hex') - .indexOf(Buffer.from('64', 'hex'), 0, 'hex'), 3); + .indexOf(Buffer.from('64', 'hex'), 0, 'hex'), + 3); // test base64 encoding assert.equal( Buffer.from(b.toString('base64'), 'base64') - .indexOf('ZA==', 0, 'base64'), 3); + .indexOf('ZA==', 0, 'base64'), + 3); assert.equal( Buffer.from(b.toString('base64'), 'base64') - .indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'), 3); + .indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'), + 3); // test ascii encoding assert.equal( Buffer.from(b.toString('ascii'), 'ascii') - .indexOf('d', 0, 'ascii'), 3); + .indexOf('d', 0, 'ascii'), + 3); assert.equal( Buffer.from(b.toString('ascii'), 'ascii') - .indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'), 3); + .indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'), + 3); // test binary encoding assert.equal( Buffer.from(b.toString('binary'), 'binary') - .indexOf('d', 0, 'binary'), 3); + .indexOf('d', 0, 'binary'), + 3); assert.equal( Buffer.from(b.toString('binary'), 'binary') - .indexOf(Buffer.from('d', 'binary'), 0, 'binary'), 3); + .indexOf(Buffer.from('d', 'binary'), 0, 'binary'), + 3); assert.equal( Buffer.from('aa\u00e8aa', 'binary') - .indexOf('\u00e8', 'binary'), 2); + .indexOf('\u00e8', 'binary'), + 2); assert.equal( Buffer.from('\u00e8', 'binary') - .indexOf('\u00e8', 'binary'), 0); + .indexOf('\u00e8', 'binary'), + 0); assert.equal( Buffer.from('\u00e8', 'binary') - .indexOf(Buffer.from('\u00e8', 'binary'), 'binary'), 0); + .indexOf(Buffer.from('\u00e8', 'binary'), 'binary'), + 0); // test optional offset with passed encoding diff --git a/test/parallel/test-buffer-inheritance.js b/test/parallel/test-buffer-inheritance.js index be845c66ccf5..913e1806fc8e 100644 --- a/test/parallel/test-buffer-inheritance.js +++ b/test/parallel/test-buffer-inheritance.js @@ -26,7 +26,7 @@ vals.forEach(function(t) { assert.equal(t.constructor, T); assert.equal(Object.getPrototypeOf(t), T.prototype); assert.equal(Object.getPrototypeOf(Object.getPrototypeOf(t)), - Buffer.prototype); + Buffer.prototype); t.fill(5); let cntr = 0; diff --git a/test/parallel/test-buffer-swap.js b/test/parallel/test-buffer-swap.js index c2a6901955ca..8f0c5e2cf700 100644 --- a/test/parallel/test-buffer-swap.js +++ b/test/parallel/test-buffer-swap.js @@ -16,17 +16,19 @@ for (var i = 1; i < 33; i++) buf_array.push(i); const buf2 = Buffer.from(buf_array); buf2.swap32(); -assert.deepStrictEqual(buf2, - Buffer.from([0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05, 0x0c, - 0x0b, 0x0a, 0x09, 0x10, 0x0f, 0x0e, 0x0d, 0x14, 0x13, - 0x12, 0x11, 0x18, 0x17, 0x16, 0x15, 0x1c, 0x1b, 0x1a, - 0x19, 0x20, 0x1f, 0x1e, 0x1d])); +assert.deepStrictEqual( + buf2, + Buffer.from([0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05, 0x0c, + 0x0b, 0x0a, 0x09, 0x10, 0x0f, 0x0e, 0x0d, 0x14, 0x13, + 0x12, 0x11, 0x18, 0x17, 0x16, 0x15, 0x1c, 0x1b, 0x1a, + 0x19, 0x20, 0x1f, 0x1e, 0x1d])); buf2.swap16(); -assert.deepStrictEqual(buf2, - Buffer.from([0x03, 0x04, 0x01, 0x02, 0x07, 0x08, 0x05, 0x06, 0x0b, - 0x0c, 0x09, 0x0a, 0x0f, 0x10, 0x0d, 0x0e, 0x13, 0x14, - 0x11, 0x12, 0x17, 0x18, 0x15, 0x16, 0x1b, 0x1c, 0x19, - 0x1a, 0x1f, 0x20, 0x1d, 0x1e])); +assert.deepStrictEqual( + buf2, + Buffer.from([0x03, 0x04, 0x01, 0x02, 0x07, 0x08, 0x05, 0x06, 0x0b, + 0x0c, 0x09, 0x0a, 0x0f, 0x10, 0x0d, 0x0e, 0x13, 0x14, + 0x11, 0x12, 0x17, 0x18, 0x15, 0x16, 0x1b, 0x1c, 0x19, + 0x1a, 0x1f, 0x20, 0x1d, 0x1e])); const buf3 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7]); buf3.slice(1, 5).swap32(); diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index 791754c71494..60363f71b8fd 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -643,18 +643,30 @@ assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio', 'base64').toString(), '********************'); // handle padding graciously, multiple-of-4 or not -assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==', - 'base64').length, 32); -assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=', - 'base64').length, 32); -assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', - 'base64').length, 32); -assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', - 'base64').length, 31); -assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', - 'base64').length, 31); -assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', - 'base64').length, 31); +assert.equal( + new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==', 'base64').length, + 32 +); +assert.equal( + new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=', 'base64').length, + 32 +); +assert.equal( + new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', 'base64').length, + 32 +); +assert.equal( + new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', 'base64').length, + 31 +); +assert.equal( + new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', 'base64').length, + 31 +); +assert.equal( + new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', 'base64').length, + 31 +); // This string encodes single '.' character in UTF-16 var dot = new Buffer('//4uAA==', 'base64'); @@ -1134,16 +1146,16 @@ assert.throws(function() { var buf = new Buffer([0xFF, 0xFF, 0xFF, 0xFF]); assert.equal(buf['readUInt' + bits + 'BE'](0), - (0xFFFFFFFF >>> (32 - bits))); + 0xFFFFFFFF >>> (32 - bits)); assert.equal(buf['readUInt' + bits + 'LE'](0), - (0xFFFFFFFF >>> (32 - bits))); + 0xFFFFFFFF >>> (32 - bits)); assert.equal(buf['readInt' + bits + 'BE'](0), - (0xFFFFFFFF >> (32 - bits))); + 0xFFFFFFFF >> (32 - bits)); assert.equal(buf['readInt' + bits + 'LE'](0), - (0xFFFFFFFF >> (32 - bits))); + 0xFFFFFFFF >> (32 - bits)); }); // test for common read(U)IntLE/BE diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index a58c023eb6d8..ae9708aae8ca 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -18,53 +18,55 @@ var filename = __filename.replace(/\\/g, '/'); // assert that nothing is written to stdout child.exec(nodejs + ' --eval 42', - function(err, stdout, stderr) { - assert.equal(stdout, ''); - assert.equal(stderr, ''); - }); + function(err, stdout, stderr) { + assert.equal(stdout, ''); + assert.equal(stderr, ''); + }); // assert that "42\n" is written to stderr child.exec(nodejs + ' --eval "console.error(42)"', - function(err, stdout, stderr) { - assert.equal(stdout, ''); - assert.equal(stderr, '42\n'); - }); + function(err, stdout, stderr) { + assert.equal(stdout, ''); + assert.equal(stderr, '42\n'); + }); // assert that the expected output is written to stdout ['--print', '-p -e', '-pe', '-p'].forEach(function(s) { var cmd = nodejs + ' ' + s + ' '; child.exec(cmd + '42', - function(err, stdout, stderr) { - assert.equal(stdout, '42\n'); - assert.equal(stderr, ''); - }); + function(err, stdout, stderr) { + assert.equal(stdout, '42\n'); + assert.equal(stderr, ''); + }); child.exec(cmd + "'[]'", - function(err, stdout, stderr) { - assert.equal(stdout, '[]\n'); - assert.equal(stderr, ''); - }); + function(err, stdout, stderr) { + assert.equal(stdout, '[]\n'); + assert.equal(stderr, ''); + }); }); // assert that module loading works child.exec(nodejs + ' --eval "require(\'' + filename + '\')"', - function(status, stdout, stderr) { - assert.equal(status.code, 42); - }); + function(status, stdout, stderr) { + assert.equal(status.code, 42); + }); // Check that builtin modules are pre-defined. -child.exec(nodejs + ' --print "os.platform()"', - function(status, stdout, stderr) { - assert.strictEqual(stderr, ''); - assert.strictEqual(stdout.trim(), require('os').platform()); - }); +child.exec( + nodejs + ' --print "os.platform()"', + function(status, stdout, stderr) { + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout.trim(), require('os').platform()); + } +); // module path resolve bug, regression test child.exec(nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"', - function(status, stdout, stderr) { - assert.equal(status.code, 42); - }); + function(status, stdout, stderr) { + assert.equal(status.code, 42); + }); // empty program should do nothing child.exec(nodejs + ' -e ""', function(status, stdout, stderr) { @@ -74,20 +76,21 @@ child.exec(nodejs + ' -e ""', function(status, stdout, stderr) { // "\\-42" should be interpreted as an escaped expression, not a switch child.exec(nodejs + ' -p "\\-42"', - function(err, stdout, stderr) { - assert.equal(stdout, '-42\n'); - assert.equal(stderr, ''); - }); + function(err, stdout, stderr) { + assert.equal(stdout, '-42\n'); + assert.equal(stderr, ''); + }); child.exec(nodejs + ' --use-strict -p process.execArgv', - function(status, stdout, stderr) { - assert.equal(stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n"); - }); + function(status, stdout, stderr) { + assert.equal(stdout, + "[ '--use-strict', '-p', 'process.execArgv' ]\n"); + }); // Regression test for https://github.com/nodejs/node/issues/3574 const emptyFile = path.join(common.fixturesDir, 'empty.js'); child.exec(nodejs + ` -e 'require("child_process").fork("${emptyFile}")'`, - function(status, stdout, stderr) { - assert.equal(stdout, ''); - assert.equal(stderr, ''); - }); + function(status, stdout, stderr) { + assert.equal(stdout, ''); + assert.equal(stderr, ''); + }); diff --git a/test/parallel/test-cluster-basic.js b/test/parallel/test-cluster-basic.js index ab9ce13e45c0..076756ab3d64 100644 --- a/test/parallel/test-cluster-basic.js +++ b/test/parallel/test-cluster-basic.js @@ -4,7 +4,7 @@ var assert = require('assert'); var cluster = require('cluster'); assert.equal('NODE_UNIQUE_ID' in process.env, false, - 'NODE_UNIQUE_ID should be removed on startup'); + 'NODE_UNIQUE_ID should be removed on startup'); function forEach(obj, fn) { Object.keys(obj).forEach(function(name, index) { @@ -93,7 +93,7 @@ else if (cluster.isMaster) { worker = cluster.fork(); assert.equal(worker.id, 1); assert.ok(worker instanceof cluster.Worker, - 'the worker is not a instance of the Worker constructor'); + 'the worker is not a instance of the Worker constructor'); //Check event forEach(checks.worker.events, function(bool, name, index) { diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js index b08fb7e01986..11fbe9487161 100644 --- a/test/parallel/test-crypto-authenticated.js +++ b/test/parallel/test-crypto-authenticated.js @@ -62,7 +62,8 @@ for (var i in TEST_CASES) { (function() { var encrypt = crypto.createCipheriv(test.algo, - Buffer.from(test.key, 'hex'), Buffer.from(test.iv, 'hex')); + Buffer.from(test.key, 'hex'), + Buffer.from(test.iv, 'hex')); if (test.aad) encrypt.setAAD(Buffer.from(test.aad, 'hex')); var hex = encrypt.update(test.plain, 'ascii', 'hex'); @@ -77,7 +78,8 @@ for (var i in TEST_CASES) { (function() { var decrypt = crypto.createDecipheriv(test.algo, - Buffer.from(test.key, 'hex'), Buffer.from(test.iv, 'hex')); + Buffer.from(test.key, 'hex'), + Buffer.from(test.iv, 'hex')); decrypt.setAuthTag(Buffer.from(test.tag, 'hex')); if (test.aad) decrypt.setAAD(Buffer.from(test.aad, 'hex')); @@ -144,18 +146,21 @@ for (var i in TEST_CASES) { (function() { // non-authenticating mode: var encrypt = crypto.createCipheriv('aes-128-cbc', - 'ipxp9a6i1Mb4USb4', '6fKjEjR3Vl30EUYC'); + 'ipxp9a6i1Mb4USb4', '6fKjEjR3Vl30EUYC'); encrypt.update('blah', 'ascii'); encrypt.final(); assert.throws(function() { encrypt.getAuthTag(); }, / state/); - assert.throws(function() { - encrypt.setAAD(Buffer.from('123', 'ascii')); }, / state/); + assert.throws( + function() { + encrypt.setAAD(Buffer.from('123', 'ascii')); + }, / state/); })(); (function() { // trying to get tag before inputting all data: var encrypt = crypto.createCipheriv(test.algo, - Buffer.from(test.key, 'hex'), Buffer.from(test.iv, 'hex')); + Buffer.from(test.key, 'hex'), + Buffer.from(test.iv, 'hex')); encrypt.update('blah', 'ascii'); assert.throws(function() { encrypt.getAuthTag(); }, / state/); })(); @@ -163,15 +168,19 @@ for (var i in TEST_CASES) { (function() { // trying to set tag on encryption object: var encrypt = crypto.createCipheriv(test.algo, - Buffer.from(test.key, 'hex'), Buffer.from(test.iv, 'hex')); - assert.throws(function() { - encrypt.setAuthTag(Buffer.from(test.tag, 'hex')); }, / state/); + Buffer.from(test.key, 'hex'), + Buffer.from(test.iv, 'hex')); + assert.throws( + function() { + encrypt.setAuthTag(Buffer.from(test.tag, 'hex')); + }, / state/); })(); (function() { // trying to read tag from decryption object: var decrypt = crypto.createDecipheriv(test.algo, - Buffer.from(test.key, 'hex'), Buffer.from(test.iv, 'hex')); + Buffer.from(test.key, 'hex'), + Buffer.from(test.iv, 'hex')); assert.throws(function() { decrypt.getAuthTag(); }, / state/); })(); } diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js index ee14ddf96623..0f546397bf5b 100644 --- a/test/parallel/test-crypto-binary-default.js +++ b/test/parallel/test-crypto-binary-default.js @@ -23,10 +23,14 @@ var path = require('path'); var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); var certPfx = fs.readFileSync(common.fixturesDir + '/test_cert.pfx'); var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); -var rsaPubPem = fs.readFileSync(common.fixturesDir + '/test_rsa_pubkey.pem', - 'ascii'); -var rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem', - 'ascii'); +var rsaPubPem = fs.readFileSync( + common.fixturesDir + '/test_rsa_pubkey.pem', + 'ascii' +); +var rsaKeyPem = fs.readFileSync( + common.fixturesDir + '/test_rsa_privkey.pem', + 'ascii' +); // PFX tests assert.doesNotThrow(function() { @@ -74,7 +78,8 @@ var rfc4231 = [ { key: Buffer.from('4a656665', 'hex'), // 'Jefe' data: Buffer.from('7768617420646f2079612077616e7420666f72206e6f74686' + - '96e673f', 'hex'), // 'what do ya want for nothing?' + '96e673f', + 'hex'), // 'what do ya want for nothing?' hmac: { sha224: 'a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', sha256: @@ -110,10 +115,10 @@ var rfc4231 = [ }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), - data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'), + data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + + 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', + 'hex'), hmac: { sha224: '6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a', sha256: @@ -234,7 +239,7 @@ var rfc2202_md5 = [ }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), + 'hex'), data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + 'cdcdcdcdcd', @@ -288,7 +293,7 @@ var rfc2202_sha1 = [ }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), + 'hex'), data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + 'cdcdcdcdcd', @@ -347,8 +352,11 @@ var a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); if (!common.hasFipsCrypto) { var a0 = crypto.createHash('md5').update('Test123').digest('binary'); - assert.equal(a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' + - '\u00bd\u008c', 'Test MD5 as binary'); + assert.equal( + a0, + 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', + 'Test MD5 as binary' + ); } assert.equal(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1'); diff --git a/test/parallel/test-crypto-ecb.js b/test/parallel/test-crypto-ecb.js index d47ec8a8091f..047742ecaa3b 100644 --- a/test/parallel/test-crypto-ecb.js +++ b/test/parallel/test-crypto-ecb.js @@ -26,7 +26,7 @@ crypto.DEFAULT_ENCODING = 'buffer'; (function() { var decrypt = crypto.createDecipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR', - ''); + ''); var msg = decrypt.update('6D385F424AAB0CFBF0BB86E07FFB7D71', 'hex', 'ascii'); msg += decrypt.final('ascii'); assert.equal(msg, 'Hello World!'); diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index cedb233d00e3..c7e19ec4e98e 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -39,8 +39,11 @@ a8 = a8.read(); if (!common.hasFipsCrypto) { var a0 = crypto.createHash('md5').update('Test123').digest('binary'); - assert.equal(a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' + - '\u00bd\u008c', 'Test MD5 as binary'); + assert.equal( + a0, + 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', + 'Test MD5 as binary' + ); } assert.equal(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1'); assert.equal(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 91ffc23e34bf..7ebe16046fd5 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -96,7 +96,8 @@ var rfc4231 = [ { key: Buffer.from('4a656665', 'hex'), // 'Jefe' data: Buffer.from('7768617420646f2079612077616e7420666f72206e6f74686' + - '96e673f', 'hex'), // 'what do ya want for nothing?' + '96e673f', + 'hex'), // 'what do ya want for nothing?' hmac: { sha224: 'a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', sha256: @@ -132,7 +133,7 @@ var rfc4231 = [ }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), + 'hex'), data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'), @@ -261,7 +262,7 @@ var rfc2202_md5 = [ }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), + 'hex'), data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + 'cdcdcdcdcd', @@ -315,7 +316,7 @@ var rfc2202_sha1 = [ }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), + 'hex'), data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + 'cdcdcdcdcd', diff --git a/test/parallel/test-crypto-padding-aes256.js b/test/parallel/test-crypto-padding-aes256.js index f5aa63474ed8..dccafd5ff794 100644 --- a/test/parallel/test-crypto-padding-aes256.js +++ b/test/parallel/test-crypto-padding-aes256.js @@ -12,8 +12,7 @@ crypto.DEFAULT_ENCODING = 'buffer'; function aes256(decipherFinal) { var iv = Buffer.from('00000000000000000000000000000000', 'hex'); - var key = Buffer.from('0123456789abcdef0123456789abcdef' + - '0123456789abcdef0123456789abcdef', 'hex'); + var key = Buffer.from('0123456789abcdef0123456789abcdef'.repeat(2), 'hex'); function encrypt(val, pad) { var c = crypto.createCipheriv('aes256', key, iv); diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index e6f2fe6eb251..3c40eb35986c 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -14,15 +14,15 @@ var crypto = require('crypto'); var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); var rsaPubPem = fs.readFileSync(common.fixturesDir + '/test_rsa_pubkey.pem', - 'ascii'); + 'ascii'); var rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem', - 'ascii'); + 'ascii'); var rsaKeyPemEncrypted = fs.readFileSync( common.fixturesDir + '/test_rsa_privkey_encrypted.pem', 'ascii'); var dsaPubPem = fs.readFileSync(common.fixturesDir + '/test_dsa_pubkey.pem', - 'ascii'); + 'ascii'); var dsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_dsa_privkey.pem', - 'ascii'); + 'ascii'); var dsaKeyPemEncrypted = fs.readFileSync( common.fixturesDir + '/test_dsa_privkey_encrypted.pem', 'ascii'); diff --git a/test/parallel/test-crypto.js b/test/parallel/test-crypto.js index f0e9242c0ebd..2a38c2d20b02 100644 --- a/test/parallel/test-crypto.js +++ b/test/parallel/test-crypto.js @@ -133,8 +133,10 @@ assert.throws(function() { // $ openssl pkcs8 -topk8 -inform PEM -outform PEM -in mykey.pem \ // -out private_key.pem -nocrypt; // Then open private_key.pem and change its header and footer. - var sha1_privateKey = fs.readFileSync(common.fixturesDir + - '/test_bad_rsa_privkey.pem', 'ascii'); + var sha1_privateKey = fs.readFileSync( + common.fixturesDir + '/test_bad_rsa_privkey.pem', + 'ascii' + ); // this would inject errors onto OpenSSL's error stack crypto.createSign('sha1').sign(sha1_privateKey); }, /asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag/); diff --git a/test/parallel/test-debug-agent.js b/test/parallel/test-debug-agent.js index 0bb5d7f9be25..6729c47a586d 100644 --- a/test/parallel/test-debug-agent.js +++ b/test/parallel/test-debug-agent.js @@ -3,4 +3,4 @@ require('../common'); const assert = require('assert'); assert.throws(() => { require('_debug_agent').start(); }, - assert.AssertionError); + assert.AssertionError); diff --git a/test/parallel/test-debugger-util-regression.js b/test/parallel/test-debugger-util-regression.js index a2461a480c94..fb6ddb8cd7c3 100644 --- a/test/parallel/test-debugger-util-regression.js +++ b/test/parallel/test-debugger-util-regression.js @@ -65,6 +65,6 @@ proc.stdin.on('error', (err) => { process.on('exit', (code) => { assert.equal(code, 0, 'the program should exit cleanly'); assert.equal(stdout.includes('{ a: \'b\' }'), true, - 'the debugger should print the result of util.inspect'); + 'the debugger should print the result of util.inspect'); assert.equal(stderr, '', 'stderr should be empty'); }); diff --git a/test/parallel/test-dns.js b/test/parallel/test-dns.js index cd5914e026d6..c0d2d152f9d4 100644 --- a/test/parallel/test-dns.js +++ b/test/parallel/test-dns.js @@ -101,7 +101,7 @@ assert.doesNotThrow(function() { */ assert.throws(function() { dns.lookup('www.google.com', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 }, - noop); + noop); }); assert.throws(function() { diff --git a/test/parallel/test-domain-exit-dispose-again.js b/test/parallel/test-domain-exit-dispose-again.js index 7360e7941229..0928addd9ace 100644 --- a/test/parallel/test-domain-exit-dispose-again.js +++ b/test/parallel/test-domain-exit-dispose-again.js @@ -38,7 +38,7 @@ setTimeout(function firstTimer() { d.dispose(); console.error(err); console.error('in domain error handler', - process.domain, process.domain === d); + process.domain, process.domain === d); }); d.run(function() { diff --git a/test/parallel/test-domain-stack-empty-in-process-uncaughtexception.js b/test/parallel/test-domain-stack-empty-in-process-uncaughtexception.js index f4095232f414..0eb94a6d8293 100644 --- a/test/parallel/test-domain-stack-empty-in-process-uncaughtexception.js +++ b/test/parallel/test-domain-stack-empty-in-process-uncaughtexception.js @@ -8,12 +8,12 @@ const d = domain.create(); process.on('uncaughtException', common.mustCall(function onUncaught() { assert.equal(process.domain, null, - 'domains stack should be empty in uncaughtException handler'); + 'domains stack should be empty in uncaughtException handler'); })); process.on('beforeExit', common.mustCall(function onBeforeExit() { assert.equal(process.domain, null, - 'domains stack should be empty in beforeExit handler'); + 'domains stack should be empty in beforeExit handler'); })); d.run(function() { diff --git a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js index 499988107dae..3f968dee1669 100644 --- a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js +++ b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js @@ -49,33 +49,43 @@ if (process.argv[2] === 'child') { } function runTestWithoutAbortOnUncaughtException() { - child_process.exec(createTestCmdLine(), - function onTestDone(err, stdout, stderr) { - // When _not_ passing --abort-on-uncaught-exception, the process' - // uncaughtException handler _must_ be called, and thus the error - // message must include only the message of the error thrown from the - // process' uncaughtException handler. - assert(stderr.includes(uncaughtExceptionHandlerErrMsg), - 'stderr output must include proper uncaughtException handler\'s ' + - 'error\'s message'); - assert(!stderr.includes(domainErrMsg), 'stderr output must not ' + - 'include domain\'s error\'s message'); + child_process.exec( + createTestCmdLine(), + function onTestDone(err, stdout, stderr) { + // When _not_ passing --abort-on-uncaught-exception, the process' + // uncaughtException handler _must_ be called, and thus the error + // message must include only the message of the error thrown from the + // process' uncaughtException handler. + assert( + stderr.includes(uncaughtExceptionHandlerErrMsg), + 'stderr must include uncaughtException handler\'s error message' + ); + assert( + !stderr.includes(domainErrMsg), + 'stderr must not include domain\'s error message' + ); - assert.notEqual(err.code, 0, - 'child process should have exited with a non-zero exit code, ' + - 'but did not'); - }); + assert.notEqual( + err.code, 0, + 'child process should have exited with a non-zero exit code' + ); + } + ); } function runTestWithAbortOnUncaughtException() { child_process.exec(createTestCmdLine({ withAbortOnUncaughtException: true }), function onTestDone(err, stdout, stderr) { - assert.notEqual(err.code, RAN_UNCAUGHT_EXCEPTION_HANDLER_EXIT_CODE, - 'child process should not have run its uncaughtException event ' + - 'handler'); - assert(common.nodeProcessAborted(err.code, err.signal), - 'process should have aborted, but did not'); + assert.notEqual( + err.code, + RAN_UNCAUGHT_EXCEPTION_HANDLER_EXIT_CODE, + 'child process should not have run its uncaughtException event handler' + ); + assert( + common.nodeProcessAborted(err.code, err.signal), + 'process should have aborted, but did not' + ); }); } diff --git a/test/parallel/test-domain-timers.js b/test/parallel/test-domain-timers.js index a97b300da02d..58989e812bba 100644 --- a/test/parallel/test-domain-timers.js +++ b/test/parallel/test-domain-timers.js @@ -34,7 +34,7 @@ timeout = setTimeout(function() {}, 10 * 1000); process.on('exit', function() { assert.equal(timeout_err.message, 'Timeout UNREFd', - 'Domain should catch timer error'); + 'Domain should catch timer error'); assert.equal(immediate_err.message, 'Immediate Error', - 'Domain should catch immediate error'); + 'Domain should catch immediate error'); }); diff --git a/test/parallel/test-domain-top-level-error-handler-clears-stack.js b/test/parallel/test-domain-top-level-error-handler-clears-stack.js index a5fec1f65ef0..f2095f09b783 100644 --- a/test/parallel/test-domain-top-level-error-handler-clears-stack.js +++ b/test/parallel/test-domain-top-level-error-handler-clears-stack.js @@ -23,7 +23,7 @@ d.on('error', common.mustCall(function() { // call to process._fatalException, and so on recursively and // indefinitely. console.error('domains stack length should be 1, but instead is:', - domain._stack.length); + domain._stack.length); process.exit(1); } }); diff --git a/test/parallel/test-domain-with-abort-on-uncaught-exception.js b/test/parallel/test-domain-with-abort-on-uncaught-exception.js index 3165663479fe..a1f14e454670 100644 --- a/test/parallel/test-domain-with-abort-on-uncaught-exception.js +++ b/test/parallel/test-domain-with-abort-on-uncaught-exception.js @@ -121,7 +121,7 @@ if (process.argv[2] === 'child') { if (!options.useTryCatch && options.throwInDomainErrHandler) { if (cmdLineOption === '--abort_on_uncaught_exception') { assert(common.nodeProcessAborted(exitCode, signal), - 'process should have aborted, but did not'); + 'process should have aborted, but did not'); } else { // By default, uncaught exceptions make node exit with an exit // code of 7. diff --git a/test/parallel/test-file-write-stream2.js b/test/parallel/test-file-write-stream2.js index e95760bc2d9a..e11f7e7815f1 100644 --- a/test/parallel/test-file-write-stream2.js +++ b/test/parallel/test-file-write-stream2.js @@ -24,8 +24,8 @@ process.on('exit', function() { console.log(' expected: %j', cb_expected); console.log(' occurred: %j', cb_occurred); assert.strictEqual(cb_occurred, cb_expected, - 'events missing or out of order: "' + - cb_occurred + '" !== "' + cb_expected + '"'); + 'events missing or out of order: "' + + cb_occurred + '" !== "' + cb_expected + '"'); } else { console.log('ok'); } diff --git a/test/parallel/test-file-write-stream3.js b/test/parallel/test-file-write-stream3.js index 2407680d001c..1243460f9f31 100644 --- a/test/parallel/test-file-write-stream3.js +++ b/test/parallel/test-file-write-stream3.js @@ -24,8 +24,8 @@ process.on('exit', function() { console.log(' expected: %j', cb_expected); console.log(' occurred: %j', cb_occurred); assert.strictEqual(cb_occurred, cb_expected, - 'events missing or out of order: "' + - cb_occurred + '" !== "' + cb_expected + '"'); + 'events missing or out of order: "' + + cb_occurred + '" !== "' + cb_expected + '"'); } }); diff --git a/test/parallel/test-fs-realpath.js b/test/parallel/test-fs-realpath.js index b7eb51450890..5a976f0b50b6 100644 --- a/test/parallel/test-fs-realpath.js +++ b/test/parallel/test-fs-realpath.js @@ -141,7 +141,7 @@ function test_deep_relative_file_symlink(callback) { var expected = path.join(common.fixturesDir, 'cycles', 'root.js'); var linkData1 = path.relative(path.join(targetsAbsDir, 'nested-index', 'one'), - expected); + expected); var linkPath1 = path.join(targetsAbsDir, 'nested-index', 'one', 'symlink1.js'); try {fs.unlinkSync(linkPath1);} catch (e) {} @@ -243,7 +243,7 @@ function test_relative_input_cwd(callback) { // we need to calculate the relative path to the tmp dir from cwd var entrydir = process.cwd(); var entry = path.relative(entrydir, - path.join(common.tmpDir + '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/cycles/realpath-3a')); + path.join(common.tmpDir + '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/cycles/realpath-3a')); var expected = common.tmpDir + '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/cycles/root.js'; [ [entry, '../cycles/realpath-3b'], @@ -342,14 +342,14 @@ function test_escape_cwd(cb) { console.log('test_escape_cwd'); asynctest(fs.realpath, ['..'], cb, function(er, uponeActual) { assertEqualPath(upone, uponeActual, - 'realpath("..") expected: ' + path.resolve(upone) + - ' actual:' + uponeActual); + 'realpath("..") expected: ' + path.resolve(upone) + + ' actual:' + uponeActual); }); } var uponeActual = fs.realpathSync('..'); assertEqualPath(upone, uponeActual, - 'realpathSync("..") expected: ' + path.resolve(upone) + - ' actual:' + uponeActual); + 'realpathSync("..") expected: ' + path.resolve(upone) + + ' actual:' + uponeActual); // going up with .. multiple times diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index 5ddd83e026c0..c33244b7d650 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -32,23 +32,24 @@ fs.open(fn, 'w', 0o644, function(err, fd) { fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, 0o644, - function(err, fd) { - if (err) throw err; - console.log('open done'); - fs.write(fd, '', 0, 'utf8', function(err, written) { - assert.equal(0, written); - }); - fs.write(fd, expected, 0, 'utf8', function(err, written) { - console.log('write done'); - if (err) throw err; - assert.equal(Buffer.byteLength(expected), written); - fs.closeSync(fd); - found2 = fs.readFileSync(fn2, 'utf8'); - console.log('expected: "%s"', expected); - console.log('found: "%s"', found2); - fs.unlinkSync(fn2); - }); - }); + function(err, fd) { + if (err) throw err; + console.log('open done'); + fs.write(fd, '', 0, 'utf8', function(err, written) { + assert.equal(0, written); + }); + fs.write(fd, expected, 0, 'utf8', function(err, written) { + console.log('write done'); + if (err) throw err; + assert.equal(Buffer.byteLength(expected), written); + fs.closeSync(fd); + found2 = fs.readFileSync(fn2, 'utf8'); + console.log('expected: "%s"', expected); + console.log('found: "%s"', found2); + fs.unlinkSync(fn2); + }); + } +); process.on('exit', function() { diff --git a/test/parallel/test-http-agent-error-on-idle.js b/test/parallel/test-http-agent-error-on-idle.js index e3388ee0dcbd..f609efc8d59b 100644 --- a/test/parallel/test-http-agent-error-on-idle.js +++ b/test/parallel/test-http-agent-error-on-idle.js @@ -47,7 +47,7 @@ server.listen(common.PORT, function() { function done() { assert.equal(Object.keys(agent.freeSockets).length, 0, - 'expect the freeSockets pool to be empty'); + 'expect the freeSockets pool to be empty'); agent.destroy(); server.close(); diff --git a/test/parallel/test-http-agent-keepalive.js b/test/parallel/test-http-agent-keepalive.js index 0eb87899c5b0..2b939db68d7c 100644 --- a/test/parallel/test-http-agent-keepalive.js +++ b/test/parallel/test-http-agent-keepalive.js @@ -74,7 +74,7 @@ function remoteClose() { setTimeout(function() { assert.equal(agent.sockets[name], undefined); assert.equal(agent.freeSockets[name], undefined, - 'freeSockets is not empty'); + 'freeSockets is not empty'); remoteError(); }, common.platformTimeout(200)); }); diff --git a/test/parallel/test-http-agent-maxsockets.js b/test/parallel/test-http-agent-maxsockets.js index e11aa2addad7..11f8d28a7389 100644 --- a/test/parallel/test-http-agent-maxsockets.js +++ b/test/parallel/test-http-agent-maxsockets.js @@ -30,7 +30,7 @@ function done() { } var freepool = agent.freeSockets[Object.keys(agent.freeSockets)[0]]; assert.equal(freepool.length, 2, - 'expect keep 2 free sockets, but got ' + freepool.length); + 'expect keep 2 free sockets, but got ' + freepool.length); agent.destroy(); server.close(); } diff --git a/test/parallel/test-http-destroyed-socket-write2.js b/test/parallel/test-http-destroyed-socket-write2.js index ac6ab92c17c0..b082dad49f6a 100644 --- a/test/parallel/test-http-destroyed-socket-write2.js +++ b/test/parallel/test-http-destroyed-socket-write2.js @@ -36,9 +36,11 @@ server.listen(common.PORT, function() { case 'EPIPE': break; default: - assert.strictEqual(er.code, + assert.strictEqual( + er.code, 'ECONNRESET', - 'Writing to a torn down client should RESET or ABORT'); + 'Writing to a torn down client should RESET or ABORT' + ); break; } diff --git a/test/parallel/test-http-parser-bad-ref.js b/test/parallel/test-http-parser-bad-ref.js index b7f132a3ea36..2caf28b38bc9 100644 --- a/test/parallel/test-http-parser-bad-ref.js +++ b/test/parallel/test-http-parser-bad-ref.js @@ -76,7 +76,8 @@ demoBug('POST /1', '/22 HTTP/1.1\r\n' + 'pong'); demoBug('POST /1/22 HTTP/1.1\r\n' + - 'Content-Type: tex', 't/plain\r\n' + + 'Content-Type: tex', + 't/plain\r\n' + 'Content-Length: 4\r\n\r\n' + 'pong'); diff --git a/test/parallel/test-http-url.parse-post.js b/test/parallel/test-http-url.parse-post.js index b6a0fdeb2552..7611b0856320 100644 --- a/test/parallel/test-http-url.parse-post.js +++ b/test/parallel/test-http-url.parse-post.js @@ -14,7 +14,7 @@ function check(request) { assert.strictEqual(request.url, '/asdf?qwer=zxcv'); //the host header should use the url.parse.hostname assert.strictEqual(request.headers.host, - testURL.hostname + ':' + testURL.port); + testURL.hostname + ':' + testURL.port); } var server = http.createServer(function(request, response) { diff --git a/test/parallel/test-module-relative-lookup.js b/test/parallel/test-module-relative-lookup.js index 002ae1a8fb77..bb1fdbbdae4e 100644 --- a/test/parallel/test-module-relative-lookup.js +++ b/test/parallel/test-module-relative-lookup.js @@ -6,5 +6,8 @@ const _module = require('module'); // avoid collision with global.module const lookupResults = _module._resolveLookupPaths('./lodash'); const paths = lookupResults[1]; -assert.strictEqual(paths[0], '.', - 'Current directory is prioritized before node_modules for local modules'); +assert.strictEqual( + paths[0], + '.', + 'Current directory is prioritized before node_modules for local modules' +); diff --git a/test/parallel/test-net-pipe-connect-errors.js b/test/parallel/test-net-pipe-connect-errors.js index 8e341015d96b..05216731e8eb 100644 --- a/test/parallel/test-net-pipe-connect-errors.js +++ b/test/parallel/test-net-pipe-connect-errors.js @@ -45,7 +45,7 @@ var notSocketClient = net.createConnection(emptyTxt, function() { notSocketClient.on('error', function(err) { assert(err.code === 'ENOTSOCK' || err.code === 'ECONNREFUSED', - `received ${err.code} instead of ENOTSOCK or ECONNREFUSED`); + `received ${err.code} instead of ENOTSOCK or ECONNREFUSED`); notSocketErrorFired = true; }); diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index 3c7a40380505..cb989a33cfb7 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -106,137 +106,159 @@ function onUnhandledFail(done) { }, 10); } -asyncTest('synchronously rejected promise should trigger' + - ' unhandledRejection', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - }); - Promise.reject(e); -}); - -asyncTest('synchronously rejected promise should trigger' + - ' unhandledRejection', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - }); - new Promise(function(_, reject) { - reject(e); - }); -}); +asyncTest( + 'synchronously rejected promise should trigger unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + Promise.reject(e); + } +); -asyncTest('Promise rejected after setImmediate should trigger' + - ' unhandledRejection', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - }); - new Promise(function(_, reject) { - setImmediate(function() { +asyncTest( + 'synchronously rejected promise should trigger unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + new Promise(function(_, reject) { reject(e); }); - }); -}); + } +); -asyncTest('Promise rejected after setTimeout(,1) should trigger' + - ' unhandled rejection', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - }); - new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); - }); -}); +asyncTest( + 'Promise rejected after setImmediate should trigger unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + new Promise(function(_, reject) { + setImmediate(function() { + reject(e); + }); + }); + } +); -asyncTest('Catching a promise rejection after setImmediate is not' + - ' soon enough to stop unhandledRejection', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - }); - var _reject; - var promise = new Promise(function(_, reject) { - _reject = reject; - }); - _reject(e); - setImmediate(function() { - promise.then(common.fail, function() {}); - }); -}); - -asyncTest('When re-throwing new errors in a promise catch, only the' + - ' re-thrown error should hit unhandledRejection', function(done) { - var e = new Error(); - var e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e2, reason); - assert.strictEqual(promise2, promise); - }); - var promise2 = Promise.reject(e).then(common.fail, function(reason) { - assert.strictEqual(e, reason); - throw e2; - }); -}); - -asyncTest('Test params of unhandledRejection for a synchronously-rejected' + - 'promise', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(promise, promise); - }); - Promise.reject(e); -}); - -asyncTest('When re-throwing new errors in a promise catch, only the ' + - 're-thrown error should hit unhandledRejection: original promise' + - ' rejected async with setTimeout(,1)', function(done) { - var e = new Error(); - var e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e2, reason); - assert.strictEqual(promise2, promise); - }); - var promise2 = new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); - }).then(common.fail, function(reason) { - assert.strictEqual(e, reason); - throw e2; - }); -}); - -asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' + - ' error should hit unhandledRejection: promise catch attached a' + - ' process.nextTick after rejection', function(done) { - var e = new Error(); - var e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e2, reason); - assert.strictEqual(promise2, promise); - }); - var promise = new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - process.nextTick(function() { - promise2 = promise.then(common.fail, function(reason) { - assert.strictEqual(e, reason); - throw e2; +asyncTest( + 'Promise rejected after setTimeout(,1) should trigger unhandled rejection', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }); + } +); + +asyncTest( + 'Catching a promise rejection after setImmediate is not soon enough to ' + + 'stop unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + var _reject; + var promise = new Promise(function(_, reject) { + _reject = reject; + }); + _reject(e); + setImmediate(function() { + promise.then(common.fail, function() {}); + }); + } +); + +asyncTest( + 'When re-throwing new errors in a promise catch, only the re-thrown error ' + + 'should hit unhandledRejection', + function(done) { + var e = new Error(); + var e2 = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e2, reason); + assert.strictEqual(promise2, promise); + }); + var promise2 = Promise.reject(e).then(common.fail, function(reason) { + assert.strictEqual(e, reason); + throw e2; + }); + } +); + +asyncTest( + 'Test params of unhandledRejection for a synchronously-rejected promise', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(promise, promise); + }); + Promise.reject(e); + } +); + +asyncTest( + 'When re-throwing new errors in a promise catch, only the re-thrown error ' + + 'should hit unhandledRejection: original promise rejected async with ' + + 'setTimeout(,1)', + function(done) { + var e = new Error(); + var e2 = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e2, reason); + assert.strictEqual(promise2, promise); + }); + var promise2 = new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }).then(common.fail, function(reason) { + assert.strictEqual(e, reason); + throw e2; + }); + } +); + +asyncTest( + 'When re-throwing new errors in a promise catch, only the re-thrown error ' + + 'should hit unhandledRejection: promise catch attached a ' + + 'process.nextTick after rejection', + function(done) { + var e = new Error(); + var e2 = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e2, reason); + assert.strictEqual(promise2, promise); + }); + var promise = new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + process.nextTick(function() { + promise2 = promise.then(common.fail, function(reason) { + assert.strictEqual(e, reason); + throw e2; + }); }); - }); - }, 1); - }); - var promise2; -}); + }, 1); + }); + var promise2; + } +); asyncTest( 'unhandledRejection should not be triggered if a promise catch is' + - ' attached synchronously upon the promise\'s creation', + ' attached synchronously upon the promise\'s creation', function(done) { var e = new Error(); onUnhandledFail(done); @@ -246,7 +268,7 @@ asyncTest( asyncTest( 'unhandledRejection should not be triggered if a promise catch is' + - ' attached synchronously upon the promise\'s creation', + ' attached synchronously upon the promise\'s creation', function(done) { var e = new Error(); onUnhandledFail(done); @@ -256,117 +278,141 @@ asyncTest( } ); -asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + - ' prevent unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); - var promise = Promise.reject(e); - process.nextTick(function() { - promise.then(common.fail, function() {}); - }); -}); - -asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + - ' prevent unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); - var promise = new Promise(function(_, reject) { - reject(e); - }); - process.nextTick(function() { - promise.then(common.fail, function() {}); - }); -}); - -asyncTest('While inside setImmediate, catching a rejected promise derived ' + - 'from returning a rejected promise in a fulfillment handler ' + - 'prevents unhandledRejection', function(done) { - onUnhandledFail(done); - - setImmediate(function() { - // reproduces on first tick and inside of setImmediate - Promise - .resolve('resolve') - .then(function() { - return Promise.reject('reject'); - }).catch(function(e) {}); - }); -}); +asyncTest( + 'Attaching a promise catch in a process.nextTick is soon enough to' + + ' prevent unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); + var promise = Promise.reject(e); + process.nextTick(function() { + promise.then(common.fail, function() {}); + }); + } +); + +asyncTest( + 'Attaching a promise catch in a process.nextTick is soon enough to' + + ' prevent unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); + var promise = new Promise(function(_, reject) { + reject(e); + }); + process.nextTick(function() { + promise.then(common.fail, function() {}); + }); + } +); + +asyncTest( + 'While inside setImmediate, catching a rejected promise derived ' + + 'from returning a rejected promise in a fulfillment handler ' + + 'prevents unhandledRejection', + function(done) { + onUnhandledFail(done); + + setImmediate(function() { + // reproduces on first tick and inside of setImmediate + Promise + .resolve('resolve') + .then(function() { + return Promise.reject('reject'); + }).catch(function(e) {}); + }); + } +); // State adapation tests -asyncTest('catching a promise which is asynchronously rejected (via' + - 'resolution to an asynchronously-rejected promise) prevents' + - ' unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); - Promise.resolve().then(function() { - return new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); +asyncTest( + 'catching a promise which is asynchronously rejected (via ' + + 'resolution to an asynchronously-rejected promise) prevents ' + + 'unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); + Promise.resolve().then(function() { + return new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }); + }).then(common.fail, function(reason) { + assert.strictEqual(e, reason); }); - }).then(common.fail, function(reason) { - assert.strictEqual(e, reason); - }); -}); - -asyncTest('Catching a rejected promise derived from throwing in a' + - ' fulfillment handler prevents unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); - Promise.resolve().then(function() { - throw e; - }).then(common.fail, function(reason) { - assert.strictEqual(e, reason); - }); -}); - -asyncTest('Catching a rejected promise derived from returning a' + - ' synchronously-rejected promise in a fulfillment handler' + - ' prevents unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); - Promise.resolve().then(function() { - return Promise.reject(e); - }).then(common.fail, function(reason) { - assert.strictEqual(e, reason); - }); -}); - -asyncTest('A rejected promise derived from returning an' + - ' asynchronously-rejected promise in a fulfillment handler' + - ' does trigger unhandledRejection', function(done) { - var e = new Error(); - var _promise; - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(_promise, promise); - }); - _promise = Promise.resolve().then(function() { - return new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); + } +); + +asyncTest( + 'Catching a rejected promise derived from throwing in a' + + ' fulfillment handler prevents unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); + Promise.resolve().then(function() { + throw e; + }).then(common.fail, function(reason) { + assert.strictEqual(e, reason); }); - }); -}); - -asyncTest('A rejected promise derived from throwing in a fulfillment handler' + - ' does trigger unhandledRejection', function(done) { - var e = new Error(); - var _promise; - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(_promise, promise); - }); - _promise = Promise.resolve().then(function() { - throw e; - }); -}); + } +); + +asyncTest( + 'Catching a rejected promise derived from returning a' + + ' synchronously-rejected promise in a fulfillment handler' + + ' prevents unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); + Promise.resolve().then(function() { + return Promise.reject(e); + }).then(common.fail, function(reason) { + assert.strictEqual(e, reason); + }); + } +); + +asyncTest( + 'A rejected promise derived from returning an' + + ' asynchronously-rejected promise in a fulfillment handler' + + ' does trigger unhandledRejection', + function(done) { + var e = new Error(); + var _promise; + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(_promise, promise); + }); + _promise = Promise.resolve().then(function() { + return new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }); + }); + } +); + +asyncTest( + 'A rejected promise derived from throwing in a fulfillment handler' + + ' does trigger unhandledRejection', + function(done) { + var e = new Error(); + var _promise; + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(_promise, promise); + }); + _promise = Promise.resolve().then(function() { + throw e; + }); + } +); asyncTest( 'A rejected promise derived from returning a synchronously-rejected' + - ' promise in a fulfillment handler does trigger unhandledRejection', + ' promise in a fulfillment handler does trigger unhandledRejection', function(done) { var e = new Error(); var _promise; @@ -381,16 +427,19 @@ asyncTest( ); // Combinations with Promise.all -asyncTest('Catching the Promise.all() of a collection that includes a' + - 'rejected promise prevents unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); - Promise.all([Promise.reject(e)]).then(common.fail, function() {}); -}); +asyncTest( + 'Catching the Promise.all() of a collection that includes a' + + 'rejected promise prevents unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); + Promise.all([Promise.reject(e)]).then(common.fail, function() {}); + } +); asyncTest( 'Catching the Promise.all() of a collection that includes a ' + - 'nextTick-async rejected promise prevents unhandledRejection', + 'nextTick-async rejected promise prevents unhandledRejection', function(done) { var e = new Error(); onUnhandledFail(done); @@ -406,69 +455,58 @@ asyncTest( } ); -asyncTest('Failing to catch the Promise.all() of a collection that includes' + - ' a rejected promise triggers unhandledRejection for the returned' + - ' promise, not the passed promise', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(p, promise); - }); - var p = Promise.all([Promise.reject(e)]); -}); - -asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + - ' unhandledRejection + rejectionHandled pair', function(done) { - clean(); - var unhandledPromises = []; - var e = new Error(); - process.on('unhandledRejection', function(reason, promise) { - assert.strictEqual(e, reason); - unhandledPromises.push(promise); - }); - process.on('rejectionHandled', function(promise) { - assert.strictEqual(1, unhandledPromises.length); - assert.strictEqual(unhandledPromises[0], promise); - assert.strictEqual(thePromise, promise); - done(); - }); - - var thePromise = new Promise(function() { - throw e; - }); - setTimeout(function() { - thePromise.then(common.fail, function(reason) { +asyncTest( + 'Failing to catch the Promise.all() of a collection that includes' + + ' a rejected promise triggers unhandledRejection for the returned' + + ' promise, not the passed promise', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); + assert.strictEqual(p, promise); }); - }, 10); -}); - -asyncTest('Waiting for some combination of process.nextTick + promise' + - ' microtasks to attach a catch handler is still soon enough to' + - ' prevent unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); + var p = Promise.all([Promise.reject(e)]); + } +); +asyncTest( + 'Waiting setTimeout(, 10) to catch a promise causes an' + + ' unhandledRejection + rejectionHandled pair', + function(done) { + clean(); + var unhandledPromises = []; + var e = new Error(); + process.on('unhandledRejection', function(reason, promise) { + assert.strictEqual(e, reason); + unhandledPromises.push(promise); + }); + process.on('rejectionHandled', function(promise) { + assert.strictEqual(1, unhandledPromises.length); + assert.strictEqual(unhandledPromises[0], promise); + assert.strictEqual(thePromise, promise); + done(); + }); - var a = Promise.reject(e); - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - a.catch(function() {}); - }); - }); + var thePromise = new Promise(function() { + throw e; }); - }); -}); + setTimeout(function() { + thePromise.then(common.fail, function(reason) { + assert.strictEqual(e, reason); + }); + }, 10); + } +); + +asyncTest( + 'Waiting for some combination of process.nextTick + promise' + + ' microtasks to attach a catch handler is still soon enough to' + + ' prevent unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); -asyncTest('Waiting for some combination of process.nextTick + promise' + - ' microtasks to attach a catch handler is still soon enough to ' + - 'prevent unhandledRejection: inside setImmediate', function(done) { - var e = new Error(); - onUnhandledFail(done); - setImmediate(function() { var a = Promise.reject(e); process.nextTick(function() { Promise.resolve().then(function() { @@ -479,52 +517,81 @@ asyncTest('Waiting for some combination of process.nextTick + promise' + }); }); }); - }); -}); + } +); -asyncTest('Waiting for some combination of process.nextTick + promise ' + - 'microtasks to attach a catch handler is still soon enough to ' + - 'prevent unhandledRejection: inside setTimeout', function(done) { - var e = new Error(); - onUnhandledFail(done); +asyncTest( + 'Waiting for some combination of process.nextTick + promise' + + ' microtasks to attach a catch handler is still soon enough to ' + + 'prevent unhandledRejection: inside setImmediate', + function(done) { + var e = new Error(); + onUnhandledFail(done); - setTimeout(function() { - var a = Promise.reject(e); - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - a.catch(function() {}); + setImmediate(function() { + var a = Promise.reject(e); + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + a.catch(function() {}); + }); }); }); }); }); - }, 0); -}); + } +); -asyncTest('Waiting for some combination of promise microtasks + ' + - 'process.nextTick to attach a catch handler is still soon enough' + - ' to prevent unhandledRejection', function(done) { - var e = new Error(); - onUnhandledFail(done); +asyncTest( + 'Waiting for some combination of process.nextTick + promise ' + + 'microtasks to attach a catch handler is still soon enough to ' + + 'prevent unhandledRejection: inside setTimeout', + function(done) { + var e = new Error(); + onUnhandledFail(done); + setTimeout(function() { + var a = Promise.reject(e); + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + a.catch(function() {}); + }); + }); + }); + }); + }, 0); + } +); - var a = Promise.reject(e); - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - a.catch(function() {}); +asyncTest( + 'Waiting for some combination of promise microtasks + ' + + 'process.nextTick to attach a catch handler is still soon enough' + + ' to prevent unhandledRejection', + function(done) { + var e = new Error(); + onUnhandledFail(done); + + + var a = Promise.reject(e); + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + a.catch(function() {}); + }); }); }); }); - }); -}); + } +); asyncTest( 'Waiting for some combination of promise microtasks +' + - ' process.nextTick to attach a catch handler is still soon enough' + - ' to prevent unhandledRejection: inside setImmediate', + ' process.nextTick to attach a catch handler is still soon enough' + + ' to prevent unhandledRejection: inside setImmediate', function(done) { var e = new Error(); onUnhandledFail(done); @@ -544,87 +611,99 @@ asyncTest( } ); -asyncTest('Waiting for some combination of promise microtasks +' + - ' process.nextTick to attach a catch handler is still soon enough' + - ' to prevent unhandledRejection: inside setTimeout', function(done) { - var e = new Error(); - onUnhandledFail(done); +asyncTest( + 'Waiting for some combination of promise microtasks +' + + ' process.nextTick to attach a catch handler is still soon enough' + + ' to prevent unhandledRejection: inside setTimeout', + function(done) { + var e = new Error(); + onUnhandledFail(done); - setTimeout(function() { - var a = Promise.reject(e); - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - a.catch(function() {}); + setTimeout(function() { + var a = Promise.reject(e); + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + a.catch(function() {}); + }); }); }); }); + }, 0); + } +); + +asyncTest( + 'setImmediate + promise microtasks is too late to attach a catch' + + ' handler; unhandledRejection will be triggered in that case.' + + ' (setImmediate before promise creation/rejection)', + function(done) { + var e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(p, promise); + }); + var p = Promise.reject(e); + setImmediate(function() { + Promise.resolve().then(function() { + p.catch(function() {}); + }); }); - }, 0); -}); + } +); -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + - ' handler; unhandledRejection will be triggered in that case.' + - ' (setImmediate before promise creation/rejection)', function(done) { - var e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(p, promise); - }); - var p = Promise.reject(e); - setImmediate(function() { - Promise.resolve().then(function() { - p.catch(function() {}); +asyncTest( + 'setImmediate + promise microtasks is too late to attach a catch' + + ' handler; unhandledRejection will be triggered in that case' + + ' (setImmediate before promise creation/rejection)', + function(done) { + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(undefined, reason); + assert.strictEqual(p, promise); }); - }); -}); - -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + - ' handler; unhandledRejection will be triggered in that case' + - ' (setImmediate before promise creation/rejection)', function(done) { - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(undefined, reason); - assert.strictEqual(p, promise); - }); - setImmediate(function() { - Promise.resolve().then(function() { + setImmediate(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { - p.catch(function() {}); + Promise.resolve().then(function() { + p.catch(function() {}); + }); }); }); }); }); - }); - var p = Promise.reject(); -}); - -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + - ' handler; unhandledRejection will be triggered in that case' + - ' (setImmediate after promise creation/rejection)', function(done) { - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(undefined, reason); - assert.strictEqual(p, promise); - }); - var p = Promise.reject(); - setImmediate(function() { - Promise.resolve().then(function() { + var p = Promise.reject(); + } +); + +asyncTest( + 'setImmediate + promise microtasks is too late to attach a catch' + + ' handler; unhandledRejection will be triggered in that case' + + ' (setImmediate after promise creation/rejection)', + function(done) { + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(undefined, reason); + assert.strictEqual(p, promise); + }); + var p = Promise.reject(); + setImmediate(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { - p.catch(function() {}); + Promise.resolve().then(function() { + p.catch(function() {}); + }); }); }); }); }); - }); -}); + } +); asyncTest( 'Promise unhandledRejection handler does not interfere with domain' + - ' error handlers being given exceptions thrown from nextTick.', + ' error handlers being given exceptions thrown from nextTick.', function(done) { var d = domain.create(); var domainReceivedError; @@ -647,44 +726,49 @@ asyncTest( } ); -asyncTest('nextTick is immediately scheduled when called inside an event' + - ' handler', function(done) { - clean(); - var e = new Error('error'); - process.on('unhandledRejection', function(reason, promise) { - var order = []; - process.nextTick(function() { - order.push(1); +asyncTest( + 'nextTick is immediately scheduled when called inside an event handler', + function(done) { + clean(); + var e = new Error('error'); + process.on('unhandledRejection', function(reason, promise) { + var order = []; + process.nextTick(function() { + order.push(1); + }); + setTimeout(function() { + order.push(2); + assert.deepStrictEqual([1, 2], order); + done(); + }, 1); }); - setTimeout(function() { - order.push(2); - assert.deepStrictEqual([1, 2], order); + Promise.reject(e); + } +); + +asyncTest( + 'Throwing an error inside a rejectionHandled handler goes to' + + ' unhandledException, and does not cause .catch() to throw an' + + 'exception', + function(done) { + clean(); + var e = new Error(); + var e2 = new Error(); + var tearDownException = setupException(function(err) { + assert.equal(e2, err); + tearDownException(); done(); + }); + process.on('rejectionHandled', function() { + throw e2; + }); + var p = Promise.reject(e); + setTimeout(function() { + try { + p.catch(function() {}); + } catch (e) { + done(new Error('fail')); + } }, 1); - }); - Promise.reject(e); -}); - -asyncTest('Throwing an error inside a rejectionHandled handler goes to' + - ' unhandledException, and does not cause .catch() to throw an' + - 'exception', function(done) { - clean(); - var e = new Error(); - var e2 = new Error(); - var tearDownException = setupException(function(err) { - assert.equal(e2, err); - tearDownException(); - done(); - }); - process.on('rejectionHandled', function() { - throw e2; - }); - var p = Promise.reject(e); - setTimeout(function() { - try { - p.catch(function() {}); - } catch (e) { - done(new Error('fail')); - } - }, 1); -}); + } +); diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 02f6dc980a10..70c6a01951e7 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -311,9 +311,9 @@ function isWarned(emitter) { assert.equal(readline.codePointAt('ABC', 0), 0x41); assert.equal(readline.codePointAt('あいう', 1), 0x3044); assert.equal(readline.codePointAt('\ud800\udc00', 0), // surrogate - 0x10000); + 0x10000); assert.equal(readline.codePointAt('\ud800\udc00A', 2), // surrogate - 0x41); + 0x41); assert.equal(readline.getStringWidth('abcde'), 5); assert.equal(readline.getStringWidth('古池や'), 6); assert.equal(readline.getStringWidth('ノード.js'), 9); @@ -322,14 +322,14 @@ function isWarned(emitter) { assert.equal(readline.getStringWidth('A\ud83c\ude00BC'), 5); // surrogate // check if vt control chars are stripped - assert.equal(readline - .stripVTControlCharacters('\u001b[31m> \u001b[39m'), '> '); - assert.equal(readline - .stripVTControlCharacters('\u001b[31m> \u001b[39m> '), '> > '); - assert.equal(readline - .stripVTControlCharacters('\u001b[31m\u001b[39m'), ''); - assert.equal(readline - .stripVTControlCharacters('> '), '> '); + assert.equal(readline.stripVTControlCharacters('\u001b[31m> \u001b[39m'), + '> '); + assert.equal(readline.stripVTControlCharacters('\u001b[31m> \u001b[39m> '), + '> > '); + assert.equal(readline.stripVTControlCharacters('\u001b[31m\u001b[39m'), + ''); + assert.equal(readline.stripVTControlCharacters('> '), + '> '); assert.equal(readline.getStringWidth('\u001b[31m> \u001b[39m'), 2); assert.equal(readline.getStringWidth('\u001b[31m> \u001b[39m> '), 4); assert.equal(readline.getStringWidth('\u001b[31m\u001b[39m'), 0); diff --git a/test/parallel/test-regress-GH-4948.js b/test/parallel/test-regress-GH-4948.js index c6953eb78fa9..d3bb390818b4 100644 --- a/test/parallel/test-regress-GH-4948.js +++ b/test/parallel/test-regress-GH-4948.js @@ -16,15 +16,16 @@ var server = http.createServer(function(serverReq, serverRes) { // normally the use case would be to call an external site // does not require connecting locally or to itself to fail - var r = http.request({hostname: 'localhost', - port: common.PORT}, function(res) { - // required, just needs to be in the client response somewhere - serverRes.end(); - - // required for test to fail - res.on('data', function(data) { }); - - }); + var r = http.request( + {hostname: 'localhost', port: common.PORT}, + function(res) { + // required, just needs to be in the client response somewhere + serverRes.end(); + + // required for test to fail + res.on('data', function(data) { }); + } + ); r.on('error', function(e) {}); r.end(); diff --git a/test/parallel/test-require-process.js b/test/parallel/test-require-process.js index 33634930b4e6..69828d83a69e 100644 --- a/test/parallel/test-require-process.js +++ b/test/parallel/test-require-process.js @@ -3,5 +3,8 @@ require('../common'); var assert = require('assert'); var nativeProcess = require('process'); -assert.strictEqual(nativeProcess, process, - 'require("process") should return a reference to global process'); +assert.strictEqual( + nativeProcess, + process, + 'require("process") should return a reference to global process' +); diff --git a/test/parallel/test-require-symlink.js b/test/parallel/test-require-symlink.js index 6b716ffa1381..805de583eade 100644 --- a/test/parallel/test-require-symlink.js +++ b/test/parallel/test-require-symlink.js @@ -6,14 +6,20 @@ const fs = require('fs'); const exec = require('child_process').exec; const spawn = require('child_process').spawn; -const linkTarget = path.join(common.fixturesDir, - '/module-require-symlink/node_modules/dep2/'); - -const linkDir = path.join(common.fixturesDir, - '/module-require-symlink/node_modules/dep1/node_modules/dep2'); - -const linkScriptTarget = path.join(common.fixturesDir, - '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/module-require-symlink/symlinked.js'); +const linkTarget = path.join( + common.fixturesDir, + '/module-require-symlink/node_modules/dep2/' +); + +const linkDir = path.join( + common.fixturesDir, + '/module-require-symlink/node_modules/dep1/node_modules/dep2' +); + +const linkScriptTarget = path.join( + common.fixturesDir, + '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/module-require-symlink/symlinked.js' +); const linkScript = path.join(common.tmpDir, 'module-require-symlink.js'); diff --git a/test/parallel/test-stdin-child-proc.js b/test/parallel/test-stdin-child-proc.js index 35ae0c99d3c8..a3ea28f23427 100644 --- a/test/parallel/test-stdin-child-proc.js +++ b/test/parallel/test-stdin-child-proc.js @@ -5,8 +5,10 @@ const common = require('../common'); const assert = require('assert'); const child_process = require('child_process'); const path = require('path'); -const cp = child_process.spawn(process.execPath, - [path.resolve(__dirname, 'test-stdin-pause-resume.js')]); +const cp = child_process.spawn( + process.execPath, + [path.resolve(__dirname, 'test-stdin-pause-resume.js')] +); cp.on('exit', common.mustCall((code) => { assert.equal(code, 0); diff --git a/test/parallel/test-tick-processor.js b/test/parallel/test-tick-processor.js index b22e2ec14a3c..43941b4c1c9f 100644 --- a/test/parallel/test-tick-processor.js +++ b/test/parallel/test-tick-processor.js @@ -19,14 +19,15 @@ process.chdir(common.tmpDir); // Unknown checked for to prevent flakiness, if pattern is not found, // then a large number of unknown ticks should be present runTest(/LazyCompile.*\[eval\]:1|.*% UNKNOWN/, - `function f() { - for (var i = 0; i < 1000000; i++) { - i++; - } - setImmediate(function() { f(); }); - }; - setTimeout(function() { process.exit(0); }, 2000); - f();`); + `function f() { + for (var i = 0; i < 1000000; i++) { + i++; + } + setImmediate(function() { f(); }); + }; + setTimeout(function() { process.exit(0); }, 2000); + f();` +); if (common.isWindows || common.isSunOS || common.isAix || @@ -36,12 +37,13 @@ if (common.isWindows || return; } runTest(/RunInDebugContext/, - `function f() { - require(\'vm\').runInDebugContext(\'Debug\'); - setImmediate(function() { f(); }); - }; - setTimeout(function() { process.exit(0); }, 2000); - f();`); + `function f() { + require(\'vm\').runInDebugContext(\'Debug\'); + setImmediate(function() { f(); }); + }; + setTimeout(function() { process.exit(0); }, 2000); + f();` +); function runTest(pattern, code) { cp.execFileSync(process.execPath, ['-prof', '-pe', code]); diff --git a/test/parallel/test-timers-ordering.js b/test/parallel/test-timers-ordering.js index cef91e58e78c..c23af9d8307e 100644 --- a/test/parallel/test-timers-ordering.js +++ b/test/parallel/test-timers-ordering.js @@ -19,7 +19,7 @@ var f = function(i) { var now = Timer.now(); console.log(i, now); assert(now >= last_ts + 1, - 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1'); + 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1'); last_ts = now; // schedule next iteration diff --git a/test/parallel/test-timers-reset-process-domain-on-throw.js b/test/parallel/test-timers-reset-process-domain-on-throw.js index ab3ffd3596ed..21f04c8e3035 100644 --- a/test/parallel/test-timers-reset-process-domain-on-throw.js +++ b/test/parallel/test-timers-reset-process-domain-on-throw.js @@ -36,8 +36,10 @@ function secondTimer() { // secondTimer was scheduled before any domain had been created, so its // callback should not have any active domain set when it runs. if (process.domain !== null) { - console.log('process.domain should be null in this timer callback, but ' + - 'instead is:', process.domain); + console.log( + 'process.domain should be null in this timer callback, but instead is:', + process.domain + ); // Do not use assert here, as it throws errors and if a domain with an error // handler is active, then asserting wouldn't make the test fail. process.exit(1); diff --git a/test/parallel/test-timers-throw-when-cb-not-function.js b/test/parallel/test-timers-throw-when-cb-not-function.js index 13533107934b..2aff904f06a5 100644 --- a/test/parallel/test-timers-throw-when-cb-not-function.js +++ b/test/parallel/test-timers-throw-when-cb-not-function.js @@ -9,17 +9,17 @@ function doSetTimeout(callback, after) { } assert.throws(doSetTimeout('foo'), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetTimeout({foo: 'bar'}), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetTimeout(), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetTimeout(undefined, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetTimeout(null, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetTimeout(false, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); function doSetInterval(callback, after) { @@ -29,17 +29,17 @@ function doSetInterval(callback, after) { } assert.throws(doSetInterval('foo'), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetInterval({foo: 'bar'}), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetInterval(), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetInterval(undefined, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetInterval(null, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetInterval(false, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); function doSetImmediate(callback, after) { @@ -49,14 +49,14 @@ function doSetImmediate(callback, after) { } assert.throws(doSetImmediate('foo'), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetImmediate({foo: 'bar'}), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetImmediate(), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetImmediate(undefined, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetImmediate(null, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); assert.throws(doSetImmediate(false, 0), - /"callback" argument must be a function/); + /"callback" argument must be a function/); diff --git a/test/parallel/test-timers-unref-leak.js b/test/parallel/test-timers-unref-leak.js index a1b1265763bf..041d7cc1a307 100644 --- a/test/parallel/test-timers-unref-leak.js +++ b/test/parallel/test-timers-unref-leak.js @@ -18,8 +18,7 @@ timeout._handle.close = function() { }; // Just to keep process alive and let previous timer's handle die -setTimeout(function() { -}, 50); +setTimeout(function() {}, 50); process.on('exit', function() { assert.equal(called, 1); diff --git a/test/parallel/test-tls-peer-certificate.js b/test/parallel/test-tls-peer-certificate.js index 357c3f5aa8ab..dfdaf93dbb43 100644 --- a/test/parallel/test-tls-peer-certificate.js +++ b/test/parallel/test-tls-peer-certificate.js @@ -41,7 +41,7 @@ server.listen(common.PORT, function() { assert.equal(peerCert.fingerprint, '8D:06:3A:B3:E5:8B:85:29:72:4F:7D:1B:54:CD:95:19:3C:EF:6F:AA'); assert.deepStrictEqual(peerCert.infoAccess['OCSP - URI'], - [ 'http://ocsp.nodejs.org/' ]); + [ 'http://ocsp.nodejs.org/' ]); var issuer = peerCert.issuerCertificate; assert.ok(issuer.issuerCertificate === issuer); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 9e713cf16c54..d593bad1504f 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -13,7 +13,7 @@ assert.equal(util.inspect(undefined), 'undefined'); assert.equal(util.inspect(null), 'null'); assert.equal(util.inspect(/foo(bar\n)?/gi), '/foo(bar\\n)?/gi'); assert.equal(util.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')), - new Date('2010-02-14T12:48:40+01:00').toISOString()); + new Date('2010-02-14T12:48:40+01:00').toISOString()); assert.equal(util.inspect('\n\u0001'), "'\\n\\u0001'"); @@ -29,18 +29,23 @@ assert.equal(util.inspect({a: 1, b: 2}), '{ a: 1, b: 2 }'); assert.equal(util.inspect({'a': {}}), '{ a: {} }'); assert.equal(util.inspect({'a': {'b': 2}}), '{ a: { b: 2 } }'); assert.equal(util.inspect({'a': {'b': { 'c': { 'd': 2 }}}}), - '{ a: { b: { c: [Object] } } }'); + '{ a: { b: { c: [Object] } } }'); assert.equal(util.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null), - '{ a: { b: { c: { d: 2 } } } }'); + '{ a: { b: { c: { d: 2 } } } }'); assert.equal(util.inspect([1, 2, 3], true), '[ 1, 2, 3, [length]: 3 ]'); assert.equal(util.inspect({'a': {'b': { 'c': 2}}}, false, 0), - '{ a: [Object] }'); + '{ a: [Object] }'); assert.equal(util.inspect({'a': {'b': { 'c': 2}}}, false, 1), - '{ a: { b: [Object] } }'); -assert.equal(util.inspect(Object.create({}, - {visible: {value: 1, enumerable: true}, hidden: {value: 2}})), - '{ visible: 1 }' -); + '{ a: { b: [Object] } }'); + +{ + const out = util.inspect( + Object.create( + {}, {visible: {value: 1, enumerable: true}, hidden: {value: 2}} + ) + ); + assert.equal(out, '{ visible: 1 }'); +} for (const showHidden of [true, false]) { const ab = new ArrayBuffer(4); @@ -161,8 +166,11 @@ for (const showHidden of [true, false]) { // See http://codereview.chromium.org/9124004/ { - const out = util.inspect(Object.create({}, - {visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true); + const out = util.inspect( + Object.create( + {}, + {visible: {value: 1, enumerable: true}, hidden: {value: 2}} + ), true); if (out !== '{ [hidden]: 2, visible: 1 }' && out !== '{ visible: 1, [hidden]: 2 }') { assert.ok(false); @@ -171,32 +179,40 @@ for (const showHidden of [true, false]) { // Objects without prototype { - const out = util.inspect(Object.create(null, - { name: {value: 'Tim', enumerable: true}, - hidden: {value: 'secret'}}), true); + const out = util.inspect( + Object.create( + null, + { name: {value: 'Tim', enumerable: true}, hidden: {value: 'secret'}} + ), true); if (out !== "{ [hidden]: 'secret', name: 'Tim' }" && out !== "{ name: 'Tim', [hidden]: 'secret' }") { assert(false); } } -assert.equal( - util.inspect(Object.create(null, - {name: {value: 'Tim', enumerable: true}, - hidden: {value: 'secret'}})), - '{ name: \'Tim\' }' -); +{ + const out = util.inspect( + Object.create( + null, + {name: {value: 'Tim', enumerable: true}, hidden: {value: 'secret'}} + ) + ); + assert.equal( + out, + '{ name: \'Tim\' }' + ); +} // Dynamic properties assert.equal(util.inspect({get readonly() {}}), - '{ readonly: [Getter] }'); + '{ readonly: [Getter] }'); assert.equal(util.inspect({get readwrite() {}, set readwrite(val) {}}), - '{ readwrite: [Getter/Setter] }'); + '{ readwrite: [Getter/Setter] }'); assert.equal(util.inspect({set writeonly(val) {}}), - '{ writeonly: [Setter] }'); + '{ writeonly: [Setter] }'); var value = {}; value['a'] = value; @@ -509,7 +525,7 @@ if (typeof Symbol !== 'undefined') { assert.equal(util.inspect(subject), '[ 1, 2, 3 ]'); assert.equal(util.inspect(subject, options), - '[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]'); + '[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]'); } // test Set @@ -617,7 +633,7 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; }))); assert.equal(util.inspect(new SetSubclass([1, 2, 3])), 'SetSubclass { 1, 2, 3 }'); assert.equal(util.inspect(new MapSubclass([['foo', 42]])), - 'MapSubclass { \'foo\' => 42 }'); + 'MapSubclass { \'foo\' => 42 }'); assert.equal(util.inspect(new PromiseSubclass(function() {})), 'PromiseSubclass { }'); } diff --git a/test/parallel/test-vm-symbols.js b/test/parallel/test-vm-symbols.js index d3419af559a2..f80609c0101d 100644 --- a/test/parallel/test-vm-symbols.js +++ b/test/parallel/test-vm-symbols.js @@ -19,7 +19,7 @@ var context = new Document(); vm.createContext(context); assert.equal(context.getSymbolValue(), 'foo', - 'should return symbol-keyed value from the outside'); + 'should return symbol-keyed value from the outside'); assert.equal(vm.runInContext('this.getSymbolValue()', context), 'foo', - 'should return symbol-keyed value from the inside'); + 'should return symbol-keyed value from the inside'); diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js index 70c102efd286..ffbc339c651a 100644 --- a/test/parallel/test-zlib-convenience-methods.js +++ b/test/parallel/test-zlib-convenience-methods.js @@ -22,34 +22,45 @@ var opts = { zlib[method[0]](expect, opts, function(err, result) { zlib[method[1]](result, opts, function(err, result) { - assert.equal(result, expect, - 'Should get original string after ' + - method[0] + '/' + method[1] + ' with options.'); + assert.equal( + result, + expect, + `Should get original string after ${method[0]}/${method[1]} with ` + + 'options.' + ); hadRun++; }); }); zlib[method[0]](expect, function(err, result) { zlib[method[1]](result, function(err, result) { - assert.equal(result, expect, - 'Should get original string after ' + - method[0] + '/' + method[1] + ' without options.'); + assert.equal( + result, + expect, + `Should get original string after ${method[0]}/${method[1]} without ` + + 'options.' + ); hadRun++; }); }); var result = zlib[method[0] + 'Sync'](expect, opts); result = zlib[method[1] + 'Sync'](result, opts); - assert.equal(result, expect, - 'Should get original string after ' + - method[0] + '/' + method[1] + ' with options.'); + assert.equal( + result, + expect, + `Should get original string after ${method[0]}/${method[1]} with options.` + ); hadRun++; result = zlib[method[0] + 'Sync'](expect); result = zlib[method[1] + 'Sync'](result); - assert.equal(result, expect, - 'Should get original string after ' + - method[0] + '/' + method[1] + ' without options.'); + assert.equal( + result, + expect, + `Should get original string after ${method[0]}/${method[1]} without ` + + 'options.' + ); hadRun++; }); diff --git a/test/parallel/test-zlib-flush-drain.js b/test/parallel/test-zlib-flush-drain.js index 9ec2f2a786dc..45cca5848583 100644 --- a/test/parallel/test-zlib-flush-drain.js +++ b/test/parallel/test-zlib-flush-drain.js @@ -38,11 +38,11 @@ deflater.on('drain', function() { process.once('exit', function() { assert.equal(beforeFlush, true, - 'before calling flush the writable stream should need to drain'); + 'before calling flush, writable stream should need to drain'); assert.equal(afterFlush, false, - 'after calling flush the writable stream should not need to drain'); + 'after calling flush, writable stream should not need to drain'); assert.equal(drainCount, 1, - 'the deflater should have emitted a single drain event'); + 'the deflater should have emitted a single drain event'); assert.equal(flushCount, 2, - 'flush should be called twice'); + 'flush should be called twice'); }); diff --git a/test/parallel/test-zlib-from-concatenated-gzip.js b/test/parallel/test-zlib-from-concatenated-gzip.js index b5007820c8d0..bee9f4724c61 100644 --- a/test/parallel/test-zlib-from-concatenated-gzip.js +++ b/test/parallel/test-zlib-from-concatenated-gzip.js @@ -53,7 +53,7 @@ fs.createReadStream(pmmFileGz) .on('data', (data) => pmmResultBuffers.push(data)) .on('finish', common.mustCall(() => { assert.deepStrictEqual(Buffer.concat(pmmResultBuffers), pmmExpected, - 'result should match original random garbage'); + 'result should match original random garbage'); })); // test that the next gzip member can wrap around the input buffer boundary @@ -66,8 +66,11 @@ fs.createReadStream(pmmFileGz) }) .on('data', (data) => resultBuffers.push(data)) .on('finish', common.mustCall(() => { - assert.strictEqual(Buffer.concat(resultBuffers).toString(), 'abcdef', - `result should match original input (offset = ${offset})`); + assert.strictEqual( + Buffer.concat(resultBuffers).toString(), + 'abcdef', + `result should match original input (offset = ${offset})` + ); })); // first write: write "abc" + the first bytes of "def" diff --git a/test/parallel/test-zlib-unzip-one-byte-chunks.js b/test/parallel/test-zlib-unzip-one-byte-chunks.js index f1b1c0f5084b..50a383af1832 100644 --- a/test/parallel/test-zlib-unzip-one-byte-chunks.js +++ b/test/parallel/test-zlib-unzip-one-byte-chunks.js @@ -17,7 +17,7 @@ const unzip = zlib.createUnzip() .on('data', (data) => resultBuffers.push(data)) .on('finish', common.mustCall(() => { assert.deepStrictEqual(Buffer.concat(resultBuffers).toString(), 'abcdef', - 'result should match original string'); + 'result should match original string'); })); for (let i = 0; i < data.length; i++) { diff --git a/test/sequential/test-init.js b/test/sequential/test-init.js index 6bb727ea1f61..12dca717c7ac 100644 --- a/test/sequential/test-init.js +++ b/test/sequential/test-init.js @@ -16,24 +16,24 @@ envCopy.TEST_INIT = 1; child.exec('"' + process.execPath + '" test-init', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'Loaded successfully!', - '`node test-init` failed!'); - }); + function(err, stdout, stderr) { + assert.equal(stdout, 'Loaded successfully!', + '`node test-init` failed!'); + }); child.exec('"' + process.execPath + '" test-init.js', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'Loaded successfully!', - '`node test-init.js` failed!'); - }); + function(err, stdout, stderr) { + assert.equal(stdout, 'Loaded successfully!', + '`node test-init.js` failed!'); + }); // test-init-index is in fixtures dir as requested by ry, so go there process.chdir(common.fixturesDir); child.exec('"' + process.execPath + '" test-init-index', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'Loaded successfully!', - '`node test-init-index failed!'); - }); + function(err, stdout, stderr) { + assert.equal(stdout, 'Loaded successfully!', + '`node test-init-index failed!'); + }); // ensures that `node fs` does not mistakenly load the native 'fs' module // instead of the desired file and that the fs module loads as @@ -41,9 +41,9 @@ process.chdir(common.fixturesDir + '/test-init-native/'); child.exec('"' + process.execPath + '" fs', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'fs loaded successfully', - '`node fs` failed!'); - }); + function(err, stdout, stderr) { + assert.equal(stdout, 'fs loaded successfully', + '`node fs` failed!'); + }); } })(); diff --git a/tools/doc/html.js b/tools/doc/html.js index 99a8cbf21a01..68ccf976b6c1 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -11,11 +11,11 @@ module.exports = toHTML; // TODO(chrisdickinson): never stop vomitting / fix this. var gtocPath = path.resolve(path.join( __dirname, - '..', - '..', - 'doc', - 'api', - '_toc.md' + '..', + '..', + 'doc', + 'api', + '_toc.md' )); var gtocLoading = null; var gtocData = null; From 74adfbc1b0a63be280d21f1bda1ee75d167a8052 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 18 Apr 2016 21:44:30 -0700 Subject: [PATCH 2/2] tools: lint for function argument alignment In function calls that span multiple lines, apply a custom lint rule to enforce argument alignment. With this rule, the following code will be flagged as an error by the linter because the arguments on the second line start in a different column than on the first line: myFunction(a, b, c, d); The following code will not be flagged as an error by the linter: myFunction(a, b, c, d); --- .eslintrc | 1 + .../eslint-rules/align-function-arguments.js | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tools/eslint-rules/align-function-arguments.js diff --git a/.eslintrc b/.eslintrc index b48f2277c832..542be9ceaa74 100644 --- a/.eslintrc +++ b/.eslintrc @@ -85,6 +85,7 @@ rules: prefer-const: 2 # Custom rules in tools/eslint-rules + align-function-arguments: 2 align-multiline-assignment: 2 assert-fail-single-argument: 2 new-with-error: [2, "Error", "RangeError", "TypeError", "SyntaxError", "ReferenceError"] diff --git a/tools/eslint-rules/align-function-arguments.js b/tools/eslint-rules/align-function-arguments.js new file mode 100644 index 000000000000..17fa704c6239 --- /dev/null +++ b/tools/eslint-rules/align-function-arguments.js @@ -0,0 +1,44 @@ +/** + * @fileoverview Align arguments in multiline function calls + * @author Rich Trott + */ +'use strict'; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ +function checkArgumentAlignment(context, node) { + if (node.arguments.length === 0) + return; + + var msg = ''; + const first = node.arguments[0]; + var currentLine = first.loc.start.line; + const firstColumn = first.loc.start.column; + + node.arguments.slice(1).forEach((argument) => { + if (argument.loc.start.line > currentLine) { + // Ignore if there are multiple lines between arguments. This happens + // in situations like this: + // setTimeout(function() { + // ... do stuff ... + // }, 1); + if (argument.loc.start.line === currentLine + 1) { + if (argument.loc.start.column !== firstColumn) { + msg = 'Function called with argument in column ' + + `${argument.loc.start.column}, expected in ${firstColumn}`; + } + } + currentLine = argument.loc.start.line; + } + }); + + if (msg) + context.report(node, msg); +} + +module.exports = function(context) { + return { + 'CallExpression': (node) => checkArgumentAlignment(context, node) + }; +};