From 7ff5dfd0b9afde3dcf7a3a2c19d86b6f8ef42ed9 Mon Sep 17 00:00:00 2001 From: Dany Shaanan Date: Sat, 17 Sep 2016 12:32:33 +0200 Subject: [PATCH 1/5] temp: add eslint rule prefer-assert-strictequal --- test/.eslintrc | 1 + .../eslint-rules/prefer-assert-strictequal.js | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tools/eslint-rules/prefer-assert-strictequal.js diff --git a/test/.eslintrc b/test/.eslintrc index d20e21aa27f2a3..5aa53a1eb9f38f 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -3,3 +3,4 @@ rules: ## common module is mandatory in tests required-modules: [2, common] + prefer-assert-strictequal: 2 diff --git a/tools/eslint-rules/prefer-assert-strictequal.js b/tools/eslint-rules/prefer-assert-strictequal.js new file mode 100644 index 00000000000000..2be677ec2124b3 --- /dev/null +++ b/tools/eslint-rules/prefer-assert-strictequal.js @@ -0,0 +1,32 @@ +'use strict'; + +function isAssert(node) { + return node.expression && + node.expression.type === 'CallExpression' && + node.expression.callee.name === 'assert'; +} + +function getFirstArg(expression) { + return expression.arguments && expression.arguments[0]; +} + +const strictEqualError = '`assert.strictEqual` should be used instead if `!==`'; + +module.exports = function(context) { + return { + ExpressionStatement(node) { + try { + if (isAssert(node)) { + const arg = getFirstArg(node.expression); + if (arg) { + if (arg.type === 'BinaryExpression' && arg.operator === '!==') { + context.report(node, strictEqualError); + } + } + } + } catch (e) { + context.report(node, `${e.toString()} ${e.stack}`); + } + } + }; +}; From da192c61f5e675e62770e2dde5e03531504b4546 Mon Sep 17 00:00:00 2001 From: Dany Shaanan Date: Sat, 17 Sep 2016 13:02:41 +0200 Subject: [PATCH 2/5] temp: expand and rename prefer-assert-strictequal --- test/.eslintrc | 2 +- tools/eslint-rules/prefer-assert-methods.js | 37 +++++++++++++++++++ .../eslint-rules/prefer-assert-strictequal.js | 32 ---------------- 3 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 tools/eslint-rules/prefer-assert-methods.js delete mode 100644 tools/eslint-rules/prefer-assert-strictequal.js diff --git a/test/.eslintrc b/test/.eslintrc index 5aa53a1eb9f38f..90bf5f6d88d4e5 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -3,4 +3,4 @@ rules: ## common module is mandatory in tests required-modules: [2, common] - prefer-assert-strictequal: 2 + prefer-assert-methods: 2 diff --git a/tools/eslint-rules/prefer-assert-methods.js b/tools/eslint-rules/prefer-assert-methods.js new file mode 100644 index 00000000000000..2675600a13b843 --- /dev/null +++ b/tools/eslint-rules/prefer-assert-methods.js @@ -0,0 +1,37 @@ +'use strict'; + +function isAssert(node) { + return node.expression && + node.expression.type === 'CallExpression' && + node.expression.callee && + node.expression.callee.name === 'assert'; +} + +function getFirstArg(expression) { + return expression.arguments && expression.arguments[0]; +} + +function parseError(method, op) { + return `'assert.${method}' should be used instead of '${op}'`; +} + +const preferedAssertMethod = { + '===': 'strictEqual', + '!==': 'notStrictEqual', + '==': 'equal', + '!=': 'notEqual' +} + +module.exports = function(context) { + return { + ExpressionStatement(node) { + if (isAssert(node)) { + const arg = getFirstArg(node.expression); + if (arg && arg.type === 'BinaryExpression') { + const assertMethod = preferedAssertMethod[arg.operator]; + if (assertMethod) context.report(node, parseError(assertMethod, arg.operator)); + } + } + } + }; +}; diff --git a/tools/eslint-rules/prefer-assert-strictequal.js b/tools/eslint-rules/prefer-assert-strictequal.js deleted file mode 100644 index 2be677ec2124b3..00000000000000 --- a/tools/eslint-rules/prefer-assert-strictequal.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; - -function isAssert(node) { - return node.expression && - node.expression.type === 'CallExpression' && - node.expression.callee.name === 'assert'; -} - -function getFirstArg(expression) { - return expression.arguments && expression.arguments[0]; -} - -const strictEqualError = '`assert.strictEqual` should be used instead if `!==`'; - -module.exports = function(context) { - return { - ExpressionStatement(node) { - try { - if (isAssert(node)) { - const arg = getFirstArg(node.expression); - if (arg) { - if (arg.type === 'BinaryExpression' && arg.operator === '!==') { - context.report(node, strictEqualError); - } - } - } - } catch (e) { - context.report(node, `${e.toString()} ${e.stack}`); - } - } - }; -}; From da1565dcdddfbac894cf2060cd46775d9d0fc532 Mon Sep 17 00:00:00 2001 From: Dany Shaanan Date: Sat, 17 Sep 2016 13:59:13 +0200 Subject: [PATCH 3/5] temp: missing ; --- tools/eslint-rules/prefer-assert-methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/eslint-rules/prefer-assert-methods.js b/tools/eslint-rules/prefer-assert-methods.js index 2675600a13b843..6d6d03011301c8 100644 --- a/tools/eslint-rules/prefer-assert-methods.js +++ b/tools/eslint-rules/prefer-assert-methods.js @@ -20,7 +20,7 @@ const preferedAssertMethod = { '!==': 'notStrictEqual', '==': 'equal', '!=': 'notEqual' -} +}; module.exports = function(context) { return { From da237031f9e94981972c32e53b0e1e0c9e4956a3 Mon Sep 17 00:00:00 2001 From: Dany Shaanan Date: Sat, 17 Sep 2016 14:48:37 +0200 Subject: [PATCH 4/5] temp: fix max-len eslint error --- tools/eslint-rules/prefer-assert-methods.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/eslint-rules/prefer-assert-methods.js b/tools/eslint-rules/prefer-assert-methods.js index 6d6d03011301c8..fa345eb7c3fc33 100644 --- a/tools/eslint-rules/prefer-assert-methods.js +++ b/tools/eslint-rules/prefer-assert-methods.js @@ -29,7 +29,9 @@ module.exports = function(context) { const arg = getFirstArg(node.expression); if (arg && arg.type === 'BinaryExpression') { const assertMethod = preferedAssertMethod[arg.operator]; - if (assertMethod) context.report(node, parseError(assertMethod, arg.operator)); + if (assertMethod) { + context.report(node, parseError(assertMethod, arg.operator)); + } } } } From dada443d9821a52bc01d2cb7744de9692e298006 Mon Sep 17 00:00:00 2001 From: Dany Shaanan Date: Sat, 17 Sep 2016 15:16:54 +0200 Subject: [PATCH 5/5] temp: fix prefer-assert-methods violations --- test/addons/load-long-path/test.js | 4 ++-- test/gc/test-http-client-connaborted.js | 2 +- test/gc/test-http-client-timeout.js | 3 +-- test/gc/test-http-client.js | 3 +-- test/gc/test-net-timeout.js | 2 +- test/parallel/test-child-process-detached.js | 3 +-- .../test-child-process-fork-regr-gh-2847.js | 2 +- .../test-cluster-setup-master-argv.js | 2 +- test/parallel/test-domain-http-server.js | 2 +- ...st-domain-top-level-error-handler-throw.js | 7 +++++-- ...st-event-emitter-listeners-side-effects.js | 20 +++++++++---------- test/parallel/test-file-write-stream2.js | 2 +- test/parallel/test-fs-access.js | 8 ++++---- test/parallel/test-fs-mkdtemp.js | 2 +- test/parallel/test-fs-readfile-pipe-large.js | 4 ++-- test/parallel/test-fs-readfile-pipe.js | 4 ++-- test/parallel/test-fs-readfile-unlink.js | 2 +- .../test-fs-readfilesync-pipe-large.js | 4 ++-- test/parallel/test-fs-stat.js | 8 ++++---- .../test-fs-write-stream-autoclose-option.js | 2 +- .../test-http-agent-destroyed-socket.js | 6 +++--- test/parallel/test-http-byteswritten.js | 2 +- .../test-http-client-default-headers-exist.js | 14 +++++++++---- test/parallel/test-http-methods.js | 6 +++--- test/parallel/test-http-write-head.js | 2 +- test/parallel/test-https-byteswritten.js | 2 +- test/parallel/test-internal-modules.js | 5 ++++- test/parallel/test-process-config.js | 2 +- test/parallel/test-process-getgroups.js | 2 +- test/parallel/test-repl-context.js | 2 +- test/parallel/test-require-json.js | 2 +- test/parallel/test-stream-duplex.js | 4 ++-- .../test-stream-transform-split-objectmode.js | 12 +++++------ test/parallel/test-stream2-writable.js | 2 +- test/parallel/test-timers-active.js | 2 +- test/parallel/test-tls-alert-handling.js | 2 +- test/parallel/test-tls-pfx-gh-5100-regr.js | 6 +++++- .../test-tls-server-connection-server.js | 2 +- test/parallel/test-url.js | 4 ++-- test/parallel/test-vm-harmony-symbols.js | 8 ++++---- test/parallel/test-vm-proxies.js | 8 ++++---- test/pummel/test-net-connect-memleak.js | 6 +++++- test/pummel/test-tls-connect-memleak.js | 6 +++++- test/pummel/test-tls-session-timeout.js | 6 +++--- test/sequential/test-child-process-emfile.js | 2 +- .../test-child-process-fork-getconnections.js | 2 +- 46 files changed, 112 insertions(+), 91 deletions(-) diff --git a/test/addons/load-long-path/test.js b/test/addons/load-long-path/test.js index a4f3cb12dc0480..36eb2199e7a63e 100644 --- a/test/addons/load-long-path/test.js +++ b/test/addons/load-long-path/test.js @@ -30,5 +30,5 @@ fs.writeFileSync(addonDestinationPath, contents); // Attempt to load at long path destination var addon = require(addonDestinationPath); -assert(addon != null); -assert(addon.hello() == 'world'); +assert.notEqual(addon, null); +assert.equal(addon.hello(), 'world'); diff --git a/test/gc/test-http-client-connaborted.js b/test/gc/test-http-client-connaborted.js index bc3308bf07d908..071baf738ee9d3 100644 --- a/test/gc/test-http-client-connaborted.js +++ b/test/gc/test-http-client-connaborted.js @@ -64,7 +64,7 @@ function status() { console.log('Collected: %d/%d', countGC, count); if (done === todo) { console.log('All should be collected now.'); - assert(count === countGC); + assert.strictEqual(count, countGC); process.exit(0); } } diff --git a/test/gc/test-http-client-timeout.js b/test/gc/test-http-client-timeout.js index 5a1175f3b05b10..27baf837ca8282 100644 --- a/test/gc/test-http-client-timeout.js +++ b/test/gc/test-http-client-timeout.js @@ -73,8 +73,7 @@ function status() { console.log('Collected: %d/%d', countGC, count); if (done === todo) { console.log('All should be collected now.'); - assert(count === countGC); + assert.strictEqual(count, countGC); process.exit(0); } } - diff --git a/test/gc/test-http-client.js b/test/gc/test-http-client.js index a0ffab34867138..06bd08b2651d1b 100644 --- a/test/gc/test-http-client.js +++ b/test/gc/test-http-client.js @@ -62,8 +62,7 @@ function status() { console.log('Collected: %d/%d', countGC, count); if (done === todo) { console.log('All should be collected now.'); - assert(count === countGC); + assert.strictEqual(count, countGC); process.exit(0); } } - diff --git a/test/gc/test-net-timeout.js b/test/gc/test-net-timeout.js index 5618cab5b39d73..2d9bc134a30347 100644 --- a/test/gc/test-net-timeout.js +++ b/test/gc/test-net-timeout.js @@ -69,7 +69,7 @@ function status() { global.gc(); console.log('All should be collected now.'); console.log('Collected: %d/%d', countGC, count); - assert(count === countGC); + assert.strictEqual(count, countGC); process.exit(0); }, 200); } diff --git a/test/parallel/test-child-process-detached.js b/test/parallel/test-child-process-detached.js index 97de4881eb691a..01861cff40c375 100644 --- a/test/parallel/test-child-process-detached.js +++ b/test/parallel/test-child-process-detached.js @@ -15,7 +15,7 @@ child.stdout.on('data', function(data) { }); process.on('exit', function() { - assert(persistentPid !== -1); + assert.notStrictEqual(persistentPid, -1); assert.throws(function() { process.kill(child.pid); }); @@ -23,4 +23,3 @@ process.on('exit', function() { process.kill(persistentPid); }); }); - diff --git a/test/parallel/test-child-process-fork-regr-gh-2847.js b/test/parallel/test-child-process-fork-regr-gh-2847.js index dba33259403cff..e7815db1b471c1 100644 --- a/test/parallel/test-child-process-fork-regr-gh-2847.js +++ b/test/parallel/test-child-process-fork-regr-gh-2847.js @@ -45,7 +45,7 @@ var server = net.createServer(function(s) { worker.process.once('close', common.mustCall(function() { // Otherwise the crash on `_channel.fd` access may happen - assert(worker.process._channel === null); + assert.strictEqual(worker.process._channel, null); server.close(); })); diff --git a/test/parallel/test-cluster-setup-master-argv.js b/test/parallel/test-cluster-setup-master-argv.js index e111ba9ffa1548..c42291417f9e79 100644 --- a/test/parallel/test-cluster-setup-master-argv.js +++ b/test/parallel/test-cluster-setup-master-argv.js @@ -12,7 +12,7 @@ cluster.on('setup', function() { realArgs[realArgs.length - 1]); }); -assert(process.argv[process.argv.length - 1] !== 'OMG,OMG'); +assert.notStrictEqual(process.argv[process.argv.length - 1], 'OMG,OMG'); process.argv.push('OMG,OMG'); process.argv.push('OMG,OMG'); cluster.setupMaster(); diff --git a/test/parallel/test-domain-http-server.js b/test/parallel/test-domain-http-server.js index e131e02ea4d74b..e6e4b294cfef2e 100644 --- a/test/parallel/test-domain-http-server.js +++ b/test/parallel/test-domain-http-server.js @@ -30,7 +30,7 @@ var server = http.createServer(function(req, res) { var data = JSON.stringify(objects[req.url.replace(/[^a-z]/g, '')]); // this line will throw if you pick an unknown key - assert(data !== undefined, 'Data should not be undefined'); + assert.notStrictEqual(data, undefined, 'Data should not be undefined'); res.writeHead(200); res.end(data); diff --git a/test/parallel/test-domain-top-level-error-handler-throw.js b/test/parallel/test-domain-top-level-error-handler-throw.js index 7933c5d052fe11..c98dfc3f1f1b7b 100644 --- a/test/parallel/test-domain-top-level-error-handler-throw.js +++ b/test/parallel/test-domain-top-level-error-handler-throw.js @@ -37,8 +37,11 @@ if (process.argv[2] === 'child') { }); child.on('close', function onChildClosed() { - assert(stderrOutput.indexOf(domainErrHandlerExMessage) !== -1); - assert(stderrOutput.indexOf(internalExMessage) === -1); + assert.notStrictEqual( + stderrOutput.indexOf(domainErrHandlerExMessage), + -1 + ); + assert.strictEqual(stderrOutput.indexOf(internalExMessage), -1); }); child.on('exit', function onChildExited(exitCode, signal) { diff --git a/test/parallel/test-event-emitter-listeners-side-effects.js b/test/parallel/test-event-emitter-listeners-side-effects.js index 1bed99f3641e98..906138af2367c3 100644 --- a/test/parallel/test-event-emitter-listeners-side-effects.js +++ b/test/parallel/test-event-emitter-listeners-side-effects.js @@ -10,16 +10,16 @@ var fl; // foo listeners fl = e.listeners('foo'); assert(Array.isArray(fl)); -assert(fl.length === 0); +assert.strictEqual(fl.length, 0); assert(!(e._events instanceof Object)); assert.deepStrictEqual(Object.keys(e._events), []); e.on('foo', common.fail); fl = e.listeners('foo'); -assert(e._events.foo === common.fail); +assert.strictEqual(e._events.foo, common.fail); assert(Array.isArray(fl)); -assert(fl.length === 1); -assert(fl[0] === common.fail); +assert.strictEqual(fl.length, 1); +assert.strictEqual(fl[0], common.fail); e.listeners('bar'); @@ -27,13 +27,13 @@ e.on('foo', assert.ok); fl = e.listeners('foo'); assert(Array.isArray(e._events.foo)); -assert(e._events.foo.length === 2); -assert(e._events.foo[0] === common.fail); -assert(e._events.foo[1] === assert.ok); +assert.strictEqual(e._events.foo.length, 2); +assert.strictEqual(e._events.foo[0], common.fail); +assert.strictEqual(e._events.foo[1], assert.ok); assert(Array.isArray(fl)); -assert(fl.length === 2); -assert(fl[0] === common.fail); -assert(fl[1] === assert.ok); +assert.strictEqual(fl.length, 2); +assert.strictEqual(fl[0], common.fail); +assert.strictEqual(fl[1], assert.ok); console.log('ok'); diff --git a/test/parallel/test-file-write-stream2.js b/test/parallel/test-file-write-stream2.js index e11f7e7815f1d0..6f0ccedb07aea1 100644 --- a/test/parallel/test-file-write-stream2.js +++ b/test/parallel/test-file-write-stream2.js @@ -85,6 +85,6 @@ for (var i = 0; i < 11; i++) { console.error('%d %j', i, ret); // return false when i hits 10 - assert(ret === (i != 10)); + assert.strictEqual(ret, i != 10); } cb_occurred += 'write '; diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index 6b82b4bbf312c3..6da26fe47beb92 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -58,10 +58,10 @@ if (!common.isWindows && process.getuid() === 0) { } } -assert(typeof fs.F_OK === 'number'); -assert(typeof fs.R_OK === 'number'); -assert(typeof fs.W_OK === 'number'); -assert(typeof fs.X_OK === 'number'); +assert.strictEqual(typeof fs.F_OK, 'number'); +assert.strictEqual(typeof fs.R_OK, 'number'); +assert.strictEqual(typeof fs.W_OK, 'number'); +assert.strictEqual(typeof fs.X_OK, 'number'); fs.access(__filename, function(err) { assert.strictEqual(err, null, 'error should not exist'); diff --git a/test/parallel/test-fs-mkdtemp.js b/test/parallel/test-fs-mkdtemp.js index dd4ab75c22c7aa..c387090989c882 100644 --- a/test/parallel/test-fs-mkdtemp.js +++ b/test/parallel/test-fs-mkdtemp.js @@ -10,7 +10,7 @@ common.refreshTmpDir(); const tmpFolder = fs.mkdtempSync(path.join(common.tmpDir, 'foo.')); -assert(path.basename(tmpFolder).length === 'foo.XXXXXX'.length); +assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length); assert(common.fileExists(tmpFolder)); const utf8 = fs.mkdtempSync(path.join(common.tmpDir, '\u0222abc.')); diff --git a/test/parallel/test-fs-readfile-pipe-large.js b/test/parallel/test-fs-readfile-pipe-large.js index a39f66ef80234f..5ebdcb211ca3f3 100644 --- a/test/parallel/test-fs-readfile-pipe-large.js +++ b/test/parallel/test-fs-readfile-pipe-large.js @@ -32,8 +32,8 @@ var cmd = 'cat ' + filename + ' | ' + node + ' ' + f + ' child'; exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) { if (err) console.error(err); assert(!err, 'it exits normally'); - assert(stdout === dataExpected, 'it reads the file and outputs it'); - assert(stderr === '', 'it does not write to stderr'); + assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it'); + assert.strictEqual(stderr, '', 'it does not write to stderr'); console.log('ok'); }); diff --git a/test/parallel/test-fs-readfile-pipe.js b/test/parallel/test-fs-readfile-pipe.js index d4db43db6edbb9..6542175a9060a9 100644 --- a/test/parallel/test-fs-readfile-pipe.js +++ b/test/parallel/test-fs-readfile-pipe.js @@ -28,7 +28,7 @@ var cmd = 'cat ' + f + ' | ' + node + ' ' + f + ' child'; exec(cmd, function(err, stdout, stderr) { if (err) console.error(err); assert(!err, 'it exits normally'); - assert(stdout === dataExpected, 'it reads the file and outputs it'); - assert(stderr === '', 'it does not write to stderr'); + assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it'); + assert.strictEqual(stderr, '', 'it does not write to stderr'); console.log('ok'); }); diff --git a/test/parallel/test-fs-readfile-unlink.js b/test/parallel/test-fs-readfile-unlink.js index e0539fa100b1f5..1be81b824c5468 100644 --- a/test/parallel/test-fs-readfile-unlink.js +++ b/test/parallel/test-fs-readfile-unlink.js @@ -19,7 +19,7 @@ fs.writeFileSync(fileName, buf); fs.readFile(fileName, function(err, data) { assert.ifError(err); - assert(data.length == buf.length); + assert.equal(data.length, buf.length); assert.strictEqual(buf[0], 42); fs.unlinkSync(fileName); diff --git a/test/parallel/test-fs-readfilesync-pipe-large.js b/test/parallel/test-fs-readfilesync-pipe-large.js index ce667094d14fe0..0aa33a110bf67a 100644 --- a/test/parallel/test-fs-readfilesync-pipe-large.js +++ b/test/parallel/test-fs-readfilesync-pipe-large.js @@ -29,8 +29,8 @@ var cmd = 'cat ' + filename + ' | ' + node + ' ' + f + ' child'; exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) { if (err) console.error(err); assert(!err, 'it exits normally'); - assert(stdout === dataExpected, 'it reads the file and outputs it'); - assert(stderr === '', 'it does not write to stderr'); + assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it'); + assert.strictEqual(stderr, '', 'it does not write to stderr'); console.log('ok'); }); diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index ac68a9ae42c389..2c844452f05540 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -6,7 +6,7 @@ var fs = require('fs'); fs.stat('.', common.mustCall(function(err, stats) { assert.ifError(err); assert.ok(stats.mtime instanceof Date); - assert(this === global); + assert.strictEqual(this, global); })); fs.stat('.', common.mustCall(function(err, stats) { @@ -17,7 +17,7 @@ fs.stat('.', common.mustCall(function(err, stats) { fs.lstat('.', common.mustCall(function(err, stats) { assert.ifError(err); assert.ok(stats.mtime instanceof Date); - assert(this === global); + assert.strictEqual(this, global); })); // fstat @@ -29,10 +29,10 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { assert.ifError(err); assert.ok(stats.mtime instanceof Date); fs.close(fd); - assert(this === global); + assert.strictEqual(this, global); })); - assert(this === global); + assert.strictEqual(this, global); })); // fstatSync diff --git a/test/parallel/test-fs-write-stream-autoclose-option.js b/test/parallel/test-fs-write-stream-autoclose-option.js index 0706ed6485888b..c7d21db2b4b531 100644 --- a/test/parallel/test-fs-write-stream-autoclose-option.js +++ b/test/parallel/test-fs-write-stream-autoclose-option.js @@ -12,7 +12,7 @@ stream.end(); stream.on('finish', common.mustCall(function() { process.nextTick(common.mustCall(function() { assert.strictEqual(stream.closed, undefined); - assert(stream.fd !== null); + assert.notStrictEqual(stream.fd, null); next(); })); })); diff --git a/test/parallel/test-http-agent-destroyed-socket.js b/test/parallel/test-http-agent-destroyed-socket.js index 34772f7d3e3081..a2693637728439 100644 --- a/test/parallel/test-http-agent-destroyed-socket.js +++ b/test/parallel/test-http-agent-destroyed-socket.js @@ -23,7 +23,7 @@ var server = http.createServer(function(req, res) { var request1 = http.get(requestOptions, function(response) { // assert request2 is queued in the agent var key = agent.getName(requestOptions); - assert(agent.requests[key].length === 1); + assert.strictEqual(agent.requests[key].length, 1); console.log('got response1'); request1.socket.on('close', function() { console.log('request1 socket closed'); @@ -51,7 +51,7 @@ var server = http.createServer(function(req, res) { process.nextTick(function() { // assert that the same socket was not assigned to request2, // since it was destroyed. - assert(request1.socket !== request2.socket); + assert.notStrictEqual(request1.socket, request2.socket); assert(!request2.socket.destroyed, 'the socket is destroyed'); }); }); @@ -62,7 +62,7 @@ var server = http.createServer(function(req, res) { assert(!request2.socket.destroyed); assert(request1.socket.destroyed); // assert not reusing the same socket, since it was destroyed. - assert(request1.socket !== request2.socket); + assert.notStrictEqual(request1.socket, request2.socket); console.log('got response2'); var gotClose = false; var gotResponseEnd = false; diff --git a/test/parallel/test-http-byteswritten.js b/test/parallel/test-http-byteswritten.js index 27ca84b166f425..bb914439a76b78 100644 --- a/test/parallel/test-http-byteswritten.js +++ b/test/parallel/test-http-byteswritten.js @@ -9,7 +9,7 @@ var httpServer = http.createServer(common.mustCall(function(req, res) { httpServer.close(); res.on('finish', common.mustCall(function() { - assert(typeof req.connection.bytesWritten === 'number'); + assert.strictEqual(typeof req.connection.bytesWritten, 'number'); assert(req.connection.bytesWritten > 0); })); res.writeHead(200, { 'Content-Type': 'text/plain' }); diff --git a/test/parallel/test-http-client-default-headers-exist.js b/test/parallel/test-http-client-default-headers-exist.js index ec96002399ecdb..9b73f2db32aad6 100644 --- a/test/parallel/test-http-client-default-headers-exist.js +++ b/test/parallel/test-http-client-default-headers-exist.js @@ -25,12 +25,18 @@ var server = http.createServer(function(req, res) { var requestHeaders = Object.keys(req.headers); requestHeaders.forEach(function(header) { - assert(expectedHeaders[req.method].indexOf(header.toLowerCase()) !== -1, - header + ' shoud not exist for method ' + req.method); + assert.notStrictEqual( + expectedHeaders[req.method].indexOf(header.toLowerCase()), + -1, + header + ' shoud not exist for method ' + req.method + ); }); - assert(requestHeaders.length === expectedHeaders[req.method].length, - 'some headers were missing for method: ' + req.method); + assert.strictEqual( + requestHeaders.length, + expectedHeaders[req.method].length, + 'some headers were missing for method: ' + req.method + ); if (expectedMethods.length === requestCount) server.close(); diff --git a/test/parallel/test-http-methods.js b/test/parallel/test-http-methods.js index 7babb714a433ea..d3d4fedd46361b 100644 --- a/test/parallel/test-http-methods.js +++ b/test/parallel/test-http-methods.js @@ -6,7 +6,7 @@ var util = require('util'); assert(Array.isArray(http.METHODS)); assert(http.METHODS.length > 0); -assert(http.METHODS.indexOf('GET') !== -1); -assert(http.METHODS.indexOf('HEAD') !== -1); -assert(http.METHODS.indexOf('POST') !== -1); +assert.notStrictEqual(http.METHODS.indexOf('GET'), -1); +assert.notStrictEqual(http.METHODS.indexOf('HEAD'), -1); +assert.notStrictEqual(http.METHODS.indexOf('POST'), -1); assert.deepStrictEqual(util._extend([], http.METHODS), http.METHODS.sort()); diff --git a/test/parallel/test-http-write-head.js b/test/parallel/test-http-write-head.js index e55ae14eb61c2b..32fff6042e7178 100644 --- a/test/parallel/test-http-write-head.js +++ b/test/parallel/test-http-write-head.js @@ -40,7 +40,7 @@ function runTest() { http.get({ port: this.address().port }, function(response) { response.on('end', function() { assert.equal(response.headers['test'], '2'); - assert(response.rawHeaders.indexOf('Test') !== -1); + assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1); s.close(); }); response.resume(); diff --git a/test/parallel/test-https-byteswritten.js b/test/parallel/test-https-byteswritten.js index 0ca4bca95cc012..58dfb12dbe2eda 100644 --- a/test/parallel/test-https-byteswritten.js +++ b/test/parallel/test-https-byteswritten.js @@ -18,7 +18,7 @@ var body = 'hello world\n'; var httpsServer = https.createServer(options, function(req, res) { res.on('finish', function() { - assert(typeof req.connection.bytesWritten === 'number'); + assert.strictEqual(typeof req.connection.bytesWritten, 'number'); assert(req.connection.bytesWritten > 0); httpsServer.close(); console.log('ok'); diff --git a/test/parallel/test-internal-modules.js b/test/parallel/test-internal-modules.js index 5880801ce280b1..ea300d5c5fb85c 100644 --- a/test/parallel/test-internal-modules.js +++ b/test/parallel/test-internal-modules.js @@ -7,4 +7,7 @@ assert.throws(function() { require('internal/freelist'); }); -assert(require(path.join(common.fixturesDir, 'internal-modules')) === 42); +assert.strictEqual( + require(path.join(common.fixturesDir, 'internal-modules')), + 42 +); diff --git a/test/parallel/test-process-config.js b/test/parallel/test-process-config.js index 538a067f589827..ab38a48e5aacdd 100644 --- a/test/parallel/test-process-config.js +++ b/test/parallel/test-process-config.js @@ -8,7 +8,7 @@ var path = require('path'); assert(process.hasOwnProperty('config')); // ensure that `process.config` is an Object -assert(Object(process.config) === process.config); +assert.strictEqual(Object(process.config), process.config); var configPath = path.resolve(__dirname, '..', '..', 'config.gypi'); var config = fs.readFileSync(configPath, 'utf8'); diff --git a/test/parallel/test-process-getgroups.js b/test/parallel/test-process-getgroups.js index 7910eb3e292fc3..002ec7c1ab4c7c 100644 --- a/test/parallel/test-process-getgroups.js +++ b/test/parallel/test-process-getgroups.js @@ -22,5 +22,5 @@ if (typeof process.getgroups === 'function') { } function check(a, b) { - for (var i = 0; i < a.length; ++i) assert(b.indexOf(a[i]) !== -1); + for (var i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1); } diff --git a/test/parallel/test-repl-context.js b/test/parallel/test-repl-context.js index 1b319a036fa256..2287a247d81bb2 100644 --- a/test/parallel/test-repl-context.js +++ b/test/parallel/test-repl-context.js @@ -19,7 +19,7 @@ function testContext(repl) { assert(context.console instanceof require('console').Console); // ensure that the repl's global property is the context - assert(context.global === context); + assert.strictEqual(context.global, context); // ensure that the repl console instance does not have a setter assert.throws(() => context.console = 'foo'); diff --git a/test/parallel/test-require-json.js b/test/parallel/test-require-json.js index ac70381c0566de..be9f5f0aaad19e 100644 --- a/test/parallel/test-require-json.js +++ b/test/parallel/test-require-json.js @@ -8,5 +8,5 @@ try { } catch (err) { var re = /test[\/\\]fixtures[\/\\]invalid.json: Unexpected string/; var i = err.message.match(re); - assert(null !== i, 'require() json error should include path'); + assert.notStrictEqual(null, i, 'require() json error should include path'); } diff --git a/test/parallel/test-stream-duplex.js b/test/parallel/test-stream-duplex.js index 200de24877bf79..a59eeb1a2ac590 100644 --- a/test/parallel/test-stream-duplex.js +++ b/test/parallel/test-stream-duplex.js @@ -27,6 +27,6 @@ stream.push({ val: 1 }); stream.end({ val: 2 }); process.on('exit', function() { - assert(read.val === 1); - assert(written.val === 2); + assert.strictEqual(read.val, 1); + assert.strictEqual(written.val, 2); }); diff --git a/test/parallel/test-stream-transform-split-objectmode.js b/test/parallel/test-stream-transform-split-objectmode.js index 9db2fa51d8bf51..610f234bead901 100644 --- a/test/parallel/test-stream-transform-split-objectmode.js +++ b/test/parallel/test-stream-transform-split-objectmode.js @@ -8,8 +8,8 @@ var parser = new Transform({ readableObjectMode: true }); assert(parser._readableState.objectMode); assert(!parser._writableState.objectMode); -assert(parser._readableState.highWaterMark === 16); -assert(parser._writableState.highWaterMark === (16 * 1024)); +assert.strictEqual(parser._readableState.highWaterMark, 16); +assert.strictEqual(parser._writableState.highWaterMark, 16 * 1024); parser._transform = function(chunk, enc, callback) { callback(null, { val: chunk[0] }); @@ -24,7 +24,7 @@ parser.on('data', function(obj) { parser.end(Buffer.from([42])); process.on('exit', function() { - assert(parsed.val === 42); + assert.strictEqual(parsed.val, 42); }); @@ -32,8 +32,8 @@ var serializer = new Transform({ writableObjectMode: true }); assert(!serializer._readableState.objectMode); assert(serializer._writableState.objectMode); -assert(serializer._readableState.highWaterMark === (16 * 1024)); -assert(serializer._writableState.highWaterMark === 16); +assert.strictEqual(serializer._readableState.highWaterMark, 16 * 1024); +assert.strictEqual(serializer._writableState.highWaterMark, 16); serializer._transform = function(obj, _, callback) { callback(null, Buffer.from([obj.val])); @@ -48,5 +48,5 @@ serializer.on('data', function(chunk) { serializer.write({ val: 42 }); process.on('exit', function() { - assert(serialized[0] === 42); + assert.strictEqual(serialized[0], 42); }); diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index a9d526f8c0a7e4..57877b048bef42 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -168,7 +168,7 @@ test('write no bufferize', function(t) { }); tw._write = function(chunk, encoding, cb) { - assert(typeof chunk === 'string'); + assert.strictEqual(typeof chunk, 'string'); chunk = Buffer.from(chunk, encoding); return TestWriter.prototype._write.call(this, chunk, encoding, cb); }; diff --git a/test/parallel/test-timers-active.js b/test/parallel/test-timers-active.js index d8faa1f5a33483..8677e43971ac89 100644 --- a/test/parallel/test-timers-active.js +++ b/test/parallel/test-timers-active.js @@ -13,7 +13,7 @@ legitTimers.forEach(function(legit) { const savedTimeout = legit._idleTimeout; active(legit); // active() should mutate these objects - assert(legit._idleTimeout === savedTimeout); + assert.strictEqual(legit._idleTimeout, savedTimeout); assert(Number.isInteger(legit._idleStart)); assert(legit._idleNext); assert(legit._idlePrev); diff --git a/test/parallel/test-tls-alert-handling.js b/test/parallel/test-tls-alert-handling.js index 3f3ddd1955a94a..284a32ea0d11ac 100644 --- a/test/parallel/test-tls-alert-handling.js +++ b/test/parallel/test-tls-alert-handling.js @@ -86,6 +86,6 @@ function sendBADTLSRecord() { } process.on('exit', function() { - assert(iter === max_iter); + assert.strictEqual(iter, max_iter); assert(success); }); diff --git a/test/parallel/test-tls-pfx-gh-5100-regr.js b/test/parallel/test-tls-pfx-gh-5100-regr.js index 385c09208ebd67..4670d9ea3da740 100644 --- a/test/parallel/test-tls-pfx-gh-5100-regr.js +++ b/test/parallel/test-tls-pfx-gh-5100-regr.js @@ -21,7 +21,11 @@ const server = tls.createServer({ requestCert: true, rejectUnauthorized: false }, common.mustCall(function(c) { - assert(c.authorizationError === null, 'authorizationError must be null'); + assert.strictEqual( + c.authorizationError, + null, + 'authorizationError must be null' + ); c.end(); })).listen(0, function() { var client = tls.connect({ diff --git a/test/parallel/test-tls-server-connection-server.js b/test/parallel/test-tls-server-connection-server.js index ee4bcbebfd31cd..e33c80be07dd8f 100644 --- a/test/parallel/test-tls-server-connection-server.js +++ b/test/parallel/test-tls-server-connection-server.js @@ -24,7 +24,7 @@ const server = tls.createServer(options, function(s) { }; server.on('connection', common.mustCall(function(socket) { - assert(socket.server === server); + assert.strictEqual(socket.server, server); server.close(); })); diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index b9f1e7b62f0a64..5530d285c8b94f 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1663,5 +1663,5 @@ var throws = [ for (let i = 0; i < throws.length; i++) { assert.throws(function() { url.format(throws[i]); }, TypeError); } -assert(url.format('') === ''); -assert(url.format({}) === ''); +assert.strictEqual(url.format(''), ''); +assert.strictEqual(url.format({}), ''); diff --git a/test/parallel/test-vm-harmony-symbols.js b/test/parallel/test-vm-harmony-symbols.js index 456a28f4d54215..1c1274ef3543f6 100644 --- a/test/parallel/test-vm-harmony-symbols.js +++ b/test/parallel/test-vm-harmony-symbols.js @@ -6,11 +6,11 @@ var vm = require('vm'); // The sandbox should have its own Symbol constructor. var sandbox = {}; vm.runInNewContext('this.Symbol = Symbol', sandbox); -assert(typeof sandbox.Symbol === 'function'); -assert(sandbox.Symbol !== Symbol); +assert.strictEqual(typeof sandbox.Symbol, 'function'); +assert.notStrictEqual(sandbox.Symbol, Symbol); // Unless we copy the Symbol constructor explicitly, of course. sandbox = { Symbol: Symbol }; vm.runInNewContext('this.Symbol = Symbol', sandbox); -assert(typeof sandbox.Symbol === 'function'); -assert(sandbox.Symbol === Symbol); +assert.strictEqual(typeof sandbox.Symbol, 'function'); +assert.strictEqual(sandbox.Symbol, Symbol); diff --git a/test/parallel/test-vm-proxies.js b/test/parallel/test-vm-proxies.js index d789293e1ce980..d47f7508213534 100644 --- a/test/parallel/test-vm-proxies.js +++ b/test/parallel/test-vm-proxies.js @@ -8,11 +8,11 @@ var vm = require('vm'); // context. Make sure that the new context has a Proxy object of its own. var sandbox = {}; vm.runInNewContext('this.Proxy = Proxy', sandbox); -assert(typeof sandbox.Proxy === 'function'); -assert(sandbox.Proxy !== Proxy); +assert.strictEqual(typeof sandbox.Proxy, 'function'); +assert.notStrictEqual(sandbox.Proxy, Proxy); // Unless we copy the Proxy object explicitly, of course. sandbox = { Proxy: Proxy }; vm.runInNewContext('this.Proxy = Proxy', sandbox); -assert(typeof sandbox.Proxy === 'function'); -assert(sandbox.Proxy === Proxy); +assert.strictEqual(typeof sandbox.Proxy, 'function'); +assert.strictEqual(sandbox.Proxy, Proxy); diff --git a/test/pummel/test-net-connect-memleak.js b/test/pummel/test-net-connect-memleak.js index 2125f6862b10ca..3b91a110eaa585 100644 --- a/test/pummel/test-net-connect-memleak.js +++ b/test/pummel/test-net-connect-memleak.js @@ -5,7 +5,11 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); -assert(typeof global.gc === 'function', 'Run this test with --expose-gc'); +assert.strictEqual( + typeof global.gc, + 'function', + 'Run this test with --expose-gc' +); net.createServer(function() {}).listen(common.PORT); var before = 0; diff --git a/test/pummel/test-tls-connect-memleak.js b/test/pummel/test-tls-connect-memleak.js index 41e16ec76e2eee..b55e33cee0afc4 100644 --- a/test/pummel/test-tls-connect-memleak.js +++ b/test/pummel/test-tls-connect-memleak.js @@ -12,7 +12,11 @@ var tls = require('tls'); var fs = require('fs'); -assert(typeof global.gc === 'function', 'Run this test with --expose-gc'); +assert.strictEqual( + typeof global.gc, + 'function', + 'Run this test with --expose-gc' +); tls.createServer({ cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem'), diff --git a/test/pummel/test-tls-session-timeout.js b/test/pummel/test-tls-session-timeout.js index 225d743eb8ab89..c23a8afcf7fe9a 100644 --- a/test/pummel/test-tls-session-timeout.js +++ b/test/pummel/test-tls-session-timeout.js @@ -99,12 +99,12 @@ function doTest() { server.listen(common.PORT, function() { Client(function(connectionType) { - assert(connectionType === 'New'); + assert.strictEqual(connectionType, 'New'); Client(function(connectionType) { - assert(connectionType === 'Reused'); + assert.strictEqual(connectionType, 'Reused'); setTimeout(function() { Client(function(connectionType) { - assert(connectionType === 'New'); + assert.strictEqual(connectionType, 'New'); server.close(); }); }, (SESSION_TIMEOUT + 1) * 1000); diff --git a/test/sequential/test-child-process-emfile.js b/test/sequential/test-child-process-emfile.js index 8f59842f99563b..55712b405af035 100644 --- a/test/sequential/test-child-process-emfile.js +++ b/test/sequential/test-child-process-emfile.js @@ -31,7 +31,7 @@ for (;;) { try { openFds.push(fs.openSync(__filename, 'r')); } catch (err) { - assert(err.code === 'EMFILE'); + assert.strictEqual(err.code, 'EMFILE'); break; } } diff --git a/test/sequential/test-child-process-fork-getconnections.js b/test/sequential/test-child-process-fork-getconnections.js index 02e60f42e6c2ba..4d6b1a25ef16cc 100644 --- a/test/sequential/test-child-process-fork-getconnections.js +++ b/test/sequential/test-child-process-fork-getconnections.js @@ -75,7 +75,7 @@ if (process.argv[2] === 'child') { } child.once('message', function(m) { - assert(m.status === 'closed'); + assert.strictEqual(m.status, 'closed'); server.getConnections(function(err, num) { closeSockets(i + 1); });