From ae485a7add138c01d0af3f94a4bb4b21c575f16a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 9 Apr 2017 10:53:30 -0700 Subject: [PATCH] test: remove common.fail() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit common.fail() was added to paste over issues with assert.fail() function signature. assert.fail() has been updated to accept a single argument so common.fail() is no longer necessary. Backport-PR-URL: https://github.com/nodejs/node/pull/15479 PR-URL: https://github.com/nodejs/node/pull/12293 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell --- test/common/index.js | 9 ++---- test/inspector/inspector-helper.js | 2 +- .../test-dgram-send-cb-quelches-error.js | 2 +- test/internet/test-dns.js | 2 +- test/internet/test-tls-add-ca-cert.js | 2 +- test/parallel/test-beforeexit-event-exit.js | 5 ++-- .../test-child-process-fork-and-spawn.js | 2 +- .../test-child-process-stdout-flush-exit.js | 3 +- .../test-cluster-send-handle-twice.js | 2 +- .../test-domain-uncaught-exception.js | 11 +++---- .../test-event-emitter-add-listeners.js | 4 +-- ...st-event-emitter-listeners-side-effects.js | 12 ++++---- test/parallel/test-event-emitter-once.js | 2 +- .../test-event-emitter-remove-listeners.js | 4 +-- test/parallel/test-exception-handler2.js | 3 +- test/parallel/test-fs-stat.js | 2 +- test/parallel/test-fs-write-stream.js | 2 +- test/parallel/test-global-console-exists.js | 4 +-- test/parallel/test-http-createConnection.js | 2 +- test/parallel/test-http-invalid-path-chars.js | 4 +-- .../test-http-localaddress-bind-error.js | 3 +- test/parallel/test-http-mutable-headers.js | 4 ++- ...test-http-response-multi-content-length.js | 4 +-- test/parallel/test-http-response-splitting.js | 4 +-- .../test-http-response-status-message.js | 2 +- ...rver-reject-chunked-with-content-length.js | 2 +- test/parallel/test-http-unix-socket.js | 2 +- .../test-https-localaddress-bind-error.js | 3 +- test/parallel/test-net-error-twice.js | 2 +- test/parallel/test-net-pipe-connect-errors.js | 6 ++-- ...-connections-close-makes-more-available.js | 4 +-- .../test-net-server-pause-on-connect.js | 2 +- test/parallel/test-net-write-slow.js | 2 +- test/parallel/test-next-tick-when-exiting.js | 4 +-- .../test-process-exit-from-before-exit.js | 3 +- test/parallel/test-process-no-deprecation.js | 2 +- .../test-promises-unhandled-rejections.js | 30 +++++++++---------- test/parallel/test-spawn-cmd-named-pipe.js | 2 +- ...est-stream2-base64-single-char-read-end.js | 4 +-- test/parallel/test-tls-empty-sni-context.js | 2 +- test/parallel/test-tls-session-cache.js | 2 +- test/parallel/test-util-inspect.js | 6 ++-- test/parallel/test-vm-debug-context.js | 2 +- test/parallel/test-vm-syntax-error-message.js | 4 ++- test/parallel/test-vm-syntax-error-stderr.js | 4 ++- 45 files changed, 95 insertions(+), 89 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index df223e051935a8..96e2b12c7a8193 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -385,7 +385,7 @@ process.on('exit', function() { if (!exports.globalCheck) return; const leaked = leakedGlobals(); if (leaked.length > 0) { - fail(`Unexpected global(s) found: ${leaked.join(', ')}`); + assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`); } }); @@ -473,14 +473,9 @@ exports.fileExists = function(pathname) { } }; -function fail(msg) { - assert.fail(null, null, msg); -} -exports.fail = fail; - exports.mustNotCall = function(msg) { return function mustNotCall() { - fail(msg || 'function should not have been called'); + assert.fail(msg || 'function should not have been called'); }; }; diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index 17842ffd98961a..7d1f4753b8b331 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -222,7 +222,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) { }; this.sendAll_(commands, () => { timeoutId = setTimeout(() => { - common.fail(`Messages without response: ${ + assert.fail(`Messages without response: ${ Object.keys(this.messages_).join(', ')}`); }, TIMEOUT); }); diff --git a/test/internet/test-dgram-send-cb-quelches-error.js b/test/internet/test-dgram-send-cb-quelches-error.js index abcc36859b96d9..946b6bbb455325 100644 --- a/test/internet/test-dgram-send-cb-quelches-error.js +++ b/test/internet/test-dgram-send-cb-quelches-error.js @@ -28,7 +28,7 @@ function callbackOnly(err) { } function onEvent(err) { - common.fail('Error should not be emitted if there is callback'); + assert.fail('Error should not be emitted if there is callback'); } function onError(err) { diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 68365e59c107c3..f922b35ef91080 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -449,7 +449,7 @@ TEST(function test_lookup_all_mixed(done) { else if (isIPv6(ip.address)) assert.strictEqual(ip.family, 6); else - assert(false); + assert.fail('unexpected IP address'); }); done(); diff --git a/test/internet/test-tls-add-ca-cert.js b/test/internet/test-tls-add-ca-cert.js index a3b6c72d10dd80..299e01405d7dbd 100644 --- a/test/internet/test-tls-add-ca-cert.js +++ b/test/internet/test-tls-add-ca-cert.js @@ -37,7 +37,7 @@ tls.connect(opts, fail).on('error', common.mustCall((err) => { })); function fail() { - assert(false, 'should fail to connect'); + assert.fail('should fail to connect'); } // New secure contexts have the well-known root CAs. diff --git a/test/parallel/test-beforeexit-event-exit.js b/test/parallel/test-beforeexit-event-exit.js index bd6162a46804bf..227e32d645ac3b 100644 --- a/test/parallel/test-beforeexit-event-exit.js +++ b/test/parallel/test-beforeexit-event-exit.js @@ -1,8 +1,9 @@ 'use strict'; -const common = require('../common'); +require('../common'); +const assert = require('assert'); process.on('beforeExit', function() { - common.fail('exit should not allow this to occur'); + assert.fail('exit should not allow this to occur'); }); process.exit(); diff --git a/test/parallel/test-child-process-fork-and-spawn.js b/test/parallel/test-child-process-fork-and-spawn.js index b3e7e29f7d9bd0..cc39f0c52d7ac4 100644 --- a/test/parallel/test-child-process-fork-and-spawn.js +++ b/test/parallel/test-child-process-fork-and-spawn.js @@ -15,7 +15,7 @@ switch (process.argv[2] || '') { case 'spawn': break; default: - common.fail(); + assert.fail(); } function checkExit(statusCode) { diff --git a/test/parallel/test-child-process-stdout-flush-exit.js b/test/parallel/test-child-process-stdout-flush-exit.js index 9db74b51ce5864..b63d9f193a4975 100644 --- a/test/parallel/test-child-process-stdout-flush-exit.js +++ b/test/parallel/test-child-process-stdout-flush-exit.js @@ -21,8 +21,7 @@ if (process.argv[2] === 'child') { child.stderr.setEncoding('utf8'); child.stderr.on('data', function(data) { - console.log('parent stderr: ' + data); - assert.ok(false); + assert.fail(`Unexpected parent stderr: ${data}`); }); // check if we receive both 'hello' at start and 'goodbye' at end diff --git a/test/parallel/test-cluster-send-handle-twice.js b/test/parallel/test-cluster-send-handle-twice.js index d4a6e0be2a200f..e16684fd382c90 100644 --- a/test/parallel/test-cluster-send-handle-twice.js +++ b/test/parallel/test-cluster-send-handle-twice.js @@ -33,7 +33,7 @@ if (cluster.isMaster) { setTimeout(function() { client.end(); }, 50); }).on('error', function(e) { console.error(e); - common.fail('server.listen failed'); + assert.fail('server.listen failed'); cluster.worker.disconnect(); }); } diff --git a/test/parallel/test-domain-uncaught-exception.js b/test/parallel/test-domain-uncaught-exception.js index 0d50e999ec63bf..b4a3d0d1d92b29 100644 --- a/test/parallel/test-domain-uncaught-exception.js +++ b/test/parallel/test-domain-uncaught-exception.js @@ -184,15 +184,16 @@ if (process.argv[2] === 'child') { test.expectedMessages.forEach(function(expectedMessage) { if (test.messagesReceived === undefined || test.messagesReceived.indexOf(expectedMessage) === -1) - assert(false, `test ${test.fn.name} should have sent message: ${ - expectedMessage} but didn't`); + assert.fail('test ' + test.fn.name + ' should have sent message: ' + + expectedMessage + ' but didn\'t'); }); if (test.messagesReceived) { test.messagesReceived.forEach(function(receivedMessage) { - if (!test.expectedMessages.includes(receivedMessage)) { - assert(false, `test ${test.fn.name} should not have sent message: ${ - receivedMessage} but did`); + if (test.expectedMessages.indexOf(receivedMessage) === -1) { + assert.fail('test ' + test.fn.name + + ' should not have sent message: ' + receivedMessage + + ' but did'); } }); } diff --git a/test/parallel/test-event-emitter-add-listeners.js b/test/parallel/test-event-emitter-add-listeners.js index ffeb4b0349637f..a1db5d4ba8ac99 100644 --- a/test/parallel/test-event-emitter-add-listeners.js +++ b/test/parallel/test-event-emitter-add-listeners.js @@ -32,9 +32,9 @@ const EventEmitter = require('events'); }); ee.on('hello', hello); - ee.once('foo', common.fail); + ee.once('foo', assert.fail); assert.deepStrictEqual(['hello', 'foo'], events_new_listener_emited); - assert.deepStrictEqual([hello, common.fail], listeners_new_listener_emited); + assert.deepStrictEqual([hello, assert.fail], listeners_new_listener_emited); ee.emit('hello', 'a', 'b'); } diff --git a/test/parallel/test-event-emitter-listeners-side-effects.js b/test/parallel/test-event-emitter-listeners-side-effects.js index 022750da406500..8d75bfeebb4e1c 100644 --- a/test/parallel/test-event-emitter-listeners-side-effects.js +++ b/test/parallel/test-event-emitter-listeners-side-effects.js @@ -1,6 +1,6 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const EventEmitter = require('events').EventEmitter; @@ -14,12 +14,12 @@ assert.strictEqual(fl.length, 0); assert(!(e._events instanceof Object)); assert.deepStrictEqual(Object.keys(e._events), []); -e.on('foo', common.fail); +e.on('foo', assert.fail); fl = e.listeners('foo'); -assert.strictEqual(e._events.foo, common.fail); +assert.strictEqual(e._events.foo, assert.fail); assert(Array.isArray(fl)); assert.strictEqual(fl.length, 1); -assert.strictEqual(fl[0], common.fail); +assert.strictEqual(fl[0], assert.fail); e.listeners('bar'); @@ -28,12 +28,12 @@ fl = e.listeners('foo'); assert(Array.isArray(e._events.foo)); assert.strictEqual(e._events.foo.length, 2); -assert.strictEqual(e._events.foo[0], common.fail); +assert.strictEqual(e._events.foo[0], assert.fail); assert.strictEqual(e._events.foo[1], assert.ok); assert(Array.isArray(fl)); assert.strictEqual(fl.length, 2); -assert.strictEqual(fl[0], common.fail); +assert.strictEqual(fl[0], assert.fail); assert.strictEqual(fl[1], assert.ok); console.log('ok'); diff --git a/test/parallel/test-event-emitter-once.js b/test/parallel/test-event-emitter-once.js index c23a6c6769c0e6..e0f7851d74c504 100644 --- a/test/parallel/test-event-emitter-once.js +++ b/test/parallel/test-event-emitter-once.js @@ -13,7 +13,7 @@ e.emit('hello', 'a', 'b'); e.emit('hello', 'a', 'b'); function remove() { - common.fail('once->foo should not be emitted'); + assert.fail('once->foo should not be emitted'); } e.once('foo', remove); diff --git a/test/parallel/test-event-emitter-remove-listeners.js b/test/parallel/test-event-emitter-remove-listeners.js index 727523eabdb29a..ed28bc7308ea9c 100644 --- a/test/parallel/test-event-emitter-remove-listeners.js +++ b/test/parallel/test-event-emitter-remove-listeners.js @@ -49,11 +49,11 @@ function listener2() {} const ee = new EventEmitter(); function remove1() { - common.fail('remove1 should not have been called'); + assert.fail('remove1 should not have been called'); } function remove2() { - common.fail('remove2 should not have been called'); + assert.fail('remove2 should not have been called'); } ee.on('removeListener', common.mustCall(function(name, cb) { diff --git a/test/parallel/test-exception-handler2.js b/test/parallel/test-exception-handler2.js index 23d78d838ad76f..a4e140ce7578aa 100644 --- a/test/parallel/test-exception-handler2.js +++ b/test/parallel/test-exception-handler2.js @@ -1,5 +1,6 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); process.on('uncaughtException', function(err) { console.log(`Caught exception: ${err}`); @@ -11,4 +12,4 @@ setTimeout(common.mustCall(function() { // Intentionally cause an exception, but don't catch it. nonexistentFunc(); // eslint-disable-line no-undef -common.fail('This will not run.'); +assert.fail('This will not run.'); diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 083461a4d7bcee..e32734b55c3844 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -41,7 +41,7 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { try { stats = fs.fstatSync(fd); } catch (err) { - common.fail(err); + assert.fail(err); } if (stats) { console.dir(stats); diff --git a/test/parallel/test-fs-write-stream.js b/test/parallel/test-fs-write-stream.js index a3ba0377e2e26e..b4f370ddbe4bb1 100644 --- a/test/parallel/test-fs-write-stream.js +++ b/test/parallel/test-fs-write-stream.js @@ -23,7 +23,7 @@ common.refreshTmpDir(); const stream = fs.createWriteStream(file); stream.on('drain', function() { - common.fail('\'drain\' event must not be emitted before ' + + assert.fail('\'drain\' event must not be emitted before ' + 'stream.write() has been called at least once.'); }); stream.destroy(); diff --git a/test/parallel/test-global-console-exists.js b/test/parallel/test-global-console-exists.js index fe77d42630c2c8..231418d3c15fb6 100644 --- a/test/parallel/test-global-console-exists.js +++ b/test/parallel/test-global-console-exists.js @@ -4,7 +4,7 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const EventEmitter = require('events'); const leak_warning = /EventEmitter memory leak detected\. 2 hello listeners/; @@ -26,7 +26,7 @@ process.stderr.write = (data) => { if (write_calls === 0) assert.ok(leak_warning.test(data)); else - common.fail('stderr.write should be called only once'); + assert.fail('stderr.write should be called only once'); write_calls++; }; diff --git a/test/parallel/test-http-createConnection.js b/test/parallel/test-http-createConnection.js index 279d7022795318..68010f044548fb 100644 --- a/test/parallel/test-http-createConnection.js +++ b/test/parallel/test-http-createConnection.js @@ -21,7 +21,7 @@ const server = http.createServer(common.mustCall(function(req, res) { res.resume(); fn = common.mustCall(createConnectionError); http.get({ createConnection: fn }, function(res) { - common.fail('Unexpected response callback'); + assert.fail('Unexpected response callback'); }).on('error', common.mustCall(function(err) { assert.strictEqual(err.message, 'Could not create socket'); server.close(); diff --git a/test/parallel/test-http-invalid-path-chars.js b/test/parallel/test-http-invalid-path-chars.js index 462e0bc12a0a3f..6aedf430a156cf 100644 --- a/test/parallel/test-http-invalid-path-chars.js +++ b/test/parallel/test-http-invalid-path-chars.js @@ -1,5 +1,5 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const http = require('http'); @@ -8,7 +8,7 @@ const theExperimentallyDeterminedNumber = 39; function fail(path) { assert.throws(() => { - http.request({ path }, common.fail); + http.request({ path }, assert.fail); }, expectedError); } diff --git a/test/parallel/test-http-localaddress-bind-error.js b/test/parallel/test-http-localaddress-bind-error.js index 99c0bac89be2ab..297859e13b24f3 100644 --- a/test/parallel/test-http-localaddress-bind-error.js +++ b/test/parallel/test-http-localaddress-bind-error.js @@ -1,5 +1,6 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); const http = require('http'); const invalidLocalAddress = '1.2.3.4'; @@ -22,7 +23,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() { method: 'GET', localAddress: invalidLocalAddress }, function(res) { - common.fail('unexpectedly got response from server'); + assert.fail('unexpectedly got response from server'); }).on('error', common.mustCall(function(e) { console.log(`client got error: ${e.message}`); server.close(); diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js index 2a4b0dc6c1c99b..7e1583dcbb92f8 100644 --- a/test/parallel/test-http-mutable-headers.js +++ b/test/parallel/test-http-mutable-headers.js @@ -63,6 +63,8 @@ const s = http.createServer(function(req, res) { res.setHeader('x-foo', 'keyboard cat'); res.writeHead(200, { 'x-foo': 'bar', 'x-bar': 'baz' }); break; + default: + assert.fail('Unknown test'); } res.statusCode = 201; @@ -120,7 +122,7 @@ function nextTest() { break; default: - throw new Error('?'); + assert.fail('Unknown test'); } response.setEncoding('utf8'); diff --git a/test/parallel/test-http-response-multi-content-length.js b/test/parallel/test-http-response-multi-content-length.js index f3dce208756f74..c915cb1d531808 100644 --- a/test/parallel/test-http-response-multi-content-length.js +++ b/test/parallel/test-http-response-multi-content-length.js @@ -19,7 +19,7 @@ const server = http.createServer((req, res) => { res.writeHead(200, {'content-length': [1, 2]}); break; default: - common.fail('should never get here'); + assert.fail('should never get here'); } res.end('ok'); }); @@ -35,7 +35,7 @@ server.listen(0, common.mustCall(() => { http.get( {port: server.address().port, headers: {'x-num': n}}, (res) => { - assert(false, 'client allowed multiple content-length headers.'); + assert.fail('client allowed multiple content-length headers.'); } ).on('error', common.mustCall((err) => { assert(/^Parse Error/.test(err.message)); diff --git a/test/parallel/test-http-response-splitting.js b/test/parallel/test-http-response-splitting.js index e6927bc1e63f77..aebb6b813be35e 100644 --- a/test/parallel/test-http-response-splitting.js +++ b/test/parallel/test-http-response-splitting.js @@ -1,6 +1,6 @@ 'use strict'; -const common = require('../common'); +require('../common'); const http = require('http'); const net = require('net'); const url = require('url'); @@ -38,7 +38,7 @@ const server = http.createServer((req, res) => { test(res, 200, {'foo': y}); break; default: - common.fail('should not get to here.'); + assert.fail('should not get to here.'); } if (count === 3) server.close(); diff --git a/test/parallel/test-http-response-status-message.js b/test/parallel/test-http-response-status-message.js index d4dd9a60e73801..0c3d329ff57fdd 100644 --- a/test/parallel/test-http-response-status-message.js +++ b/test/parallel/test-http-response-status-message.js @@ -23,7 +23,7 @@ testCases.findByPath = function(path) { return testCase.path === path; }); if (matching.length === 0) { - throw 'failed to find test case with path ' + path; + assert.fail(`failed to find test case with path ${path}`); } return matching[0]; }; diff --git a/test/parallel/test-http-server-reject-chunked-with-content-length.js b/test/parallel/test-http-server-reject-chunked-with-content-length.js index 7fc76761b318ac..8f77217e2b0a1b 100644 --- a/test/parallel/test-http-server-reject-chunked-with-content-length.js +++ b/test/parallel/test-http-server-reject-chunked-with-content-length.js @@ -23,7 +23,7 @@ server.listen(0, () => { client.on('data', (data) => { // Should not get to this point because the server should simply // close the connection without returning any data. - common.fail('no data should be returned by the server'); + assert.fail('no data should be returned by the server'); }); client.on('end', common.mustCall(() => {})); }); diff --git a/test/parallel/test-http-unix-socket.js b/test/parallel/test-http-unix-socket.js index f9308d86325cd1..346726ee4d06ff 100644 --- a/test/parallel/test-http-unix-socket.js +++ b/test/parallel/test-http-unix-socket.js @@ -45,7 +45,7 @@ server.listen(common.PIPE, common.mustCall(function() { })); req.on('error', function(e) { - common.fail(e.stack); + assert.fail(e.stack); }); req.end(); diff --git a/test/parallel/test-https-localaddress-bind-error.js b/test/parallel/test-https-localaddress-bind-error.js index 30fe4860e4004f..5ce723689f0647 100644 --- a/test/parallel/test-https-localaddress-bind-error.js +++ b/test/parallel/test-https-localaddress-bind-error.js @@ -4,6 +4,7 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +const assert = require('assert'); const fs = require('fs'); const https = require('https'); @@ -32,7 +33,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() { method: 'GET', localAddress: invalidLocalAddress }, function(res) { - common.fail('unexpectedly got response from server'); + assert.fail('unexpectedly got response from server'); }).on('error', common.mustCall(function(e) { console.log(`client got error: ${e.message}`); server.close(); diff --git a/test/parallel/test-net-error-twice.js b/test/parallel/test-net-error-twice.js index 3c25d1c98ed346..e3cba2c362ea1e 100644 --- a/test/parallel/test-net-error-twice.js +++ b/test/parallel/test-net-error-twice.js @@ -20,7 +20,7 @@ const srv = net.createServer(function onConnection(conn) { conn.on('error', function(err) { errs.push(err); if (errs.length > 1 && errs[0] === errs[1]) - assert(false, 'We should not be emitting the same error twice'); + assert.fail('Should not emit the same error twice'); }); conn.on('close', function() { srv.unref(); diff --git a/test/parallel/test-net-pipe-connect-errors.js b/test/parallel/test-net-pipe-connect-errors.js index 16e60a2525bd33..25e9fa3d519fb7 100644 --- a/test/parallel/test-net-pipe-connect-errors.js +++ b/test/parallel/test-net-pipe-connect-errors.js @@ -35,7 +35,7 @@ if (common.isWindows) { } const notSocketClient = net.createConnection(emptyTxt, function() { - common.fail('connection callback should not run'); + assert.fail('connection callback should not run'); }); notSocketClient.on('error', common.mustCall(function(err) { @@ -46,7 +46,7 @@ notSocketClient.on('error', common.mustCall(function(err) { // Trying to connect to not-existing socket should result in ENOENT error const noEntSocketClient = net.createConnection('no-ent-file', function() { - common.fail('connection to non-existent socket, callback should not run'); + assert.fail('connection to non-existent socket, callback should not run'); }); noEntSocketClient.on('error', common.mustCall(function(err) { @@ -63,7 +63,7 @@ if (!common.isWindows && process.getuid() !== 0) { fs.chmodSync(common.PIPE, 0); const accessClient = net.createConnection(common.PIPE, function() { - common.fail('connection should get EACCES, callback should not run'); + assert.fail('connection should get EACCES, callback should not run'); }); accessClient.on('error', common.mustCall(function(err) { diff --git a/test/parallel/test-net-server-max-connections-close-makes-more-available.js b/test/parallel/test-net-server-max-connections-close-makes-more-available.js index f7ab54b7b83b48..db7e1692ab66f7 100644 --- a/test/parallel/test-net-server-max-connections-close-makes-more-available.js +++ b/test/parallel/test-net-server-max-connections-close-makes-more-available.js @@ -1,5 +1,5 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const net = require('net'); @@ -86,5 +86,5 @@ process.on('exit', function() { process.on('unhandledRejection', function() { console.error('promise rejected'); - common.fail('A promise in the chain rejected'); + assert.fail('A promise in the chain rejected'); }); diff --git a/test/parallel/test-net-server-pause-on-connect.js b/test/parallel/test-net-server-pause-on-connect.js index 90206982d5dcca..11bea9e29404bd 100644 --- a/test/parallel/test-net-server-pause-on-connect.js +++ b/test/parallel/test-net-server-pause-on-connect.js @@ -10,7 +10,7 @@ let server1Sock; const server1ConnHandler = (socket) => { socket.on('data', function(data) { if (stopped) { - common.fail('data event should not have happened yet'); + assert.fail('data event should not have happened yet'); } assert.strictEqual(data.toString(), msg, 'invalid data received'); diff --git a/test/parallel/test-net-write-slow.js b/test/parallel/test-net-write-slow.js index c1b2c60e2e202a..b7b0c9b7192a2d 100644 --- a/test/parallel/test-net-write-slow.js +++ b/test/parallel/test-net-write-slow.js @@ -13,7 +13,7 @@ const server = net.createServer(function(socket) { socket.setNoDelay(); socket.setTimeout(9999); socket.on('timeout', function() { - common.fail(`flushed: ${flushed}, received: ${received}/${SIZE * N}`); + assert.fail(`flushed: ${flushed}, received: ${received}/${SIZE * N}`); }); for (let i = 0; i < N; ++i) { diff --git a/test/parallel/test-next-tick-when-exiting.js b/test/parallel/test-next-tick-when-exiting.js index 1bb4c914d01869..b64befa8578579 100644 --- a/test/parallel/test-next-tick-when-exiting.js +++ b/test/parallel/test-next-tick-when-exiting.js @@ -1,13 +1,13 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); process.on('exit', () => { assert.strictEqual(process._exiting, true, 'process._exiting was not set!'); process.nextTick(() => { - common.fail('process is exiting, should not be called.'); + assert.fail('process is exiting, should not be called.'); }); }); diff --git a/test/parallel/test-process-exit-from-before-exit.js b/test/parallel/test-process-exit-from-before-exit.js index e3c3ab208f7814..6e47bd8426dcfa 100644 --- a/test/parallel/test-process-exit-from-before-exit.js +++ b/test/parallel/test-process-exit-from-before-exit.js @@ -1,8 +1,9 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); process.on('beforeExit', common.mustCall(function() { setTimeout(common.mustNotCall(), 5); process.exit(0); // Should execute immediately even if we schedule new work. - common.fail(); + assert.fail(); })); diff --git a/test/parallel/test-process-no-deprecation.js b/test/parallel/test-process-no-deprecation.js index 9185f8beb58bd6..50b62b5f39e918 100644 --- a/test/parallel/test-process-no-deprecation.js +++ b/test/parallel/test-process-no-deprecation.js @@ -10,7 +10,7 @@ process.noDeprecation = true; const assert = require('assert'); function listener() { - common.fail('received unexpected warning'); + assert.fail('received unexpected warning'); } process.addListener('warning', listener); diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index b38d16a40f0f66..03e7f00c1e837b 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -1,5 +1,5 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const domain = require('domain'); @@ -164,7 +164,7 @@ asyncTest('Catching a promise rejection after setImmediate is not' + }); _reject(e); setImmediate(function() { - promise.then(common.fail, () => {}); + promise.then(assert.fail, () => {}); }); }); @@ -176,7 +176,7 @@ asyncTest('When re-throwing new errors in a promise catch, only the' + assert.strictEqual(e2, reason); assert.strictEqual(promise2, promise); }); - let promise2 = Promise.reject(e).then(common.fail, function(reason) { + const promise2 = Promise.reject(e).then(assert.fail, function(reason) { assert.strictEqual(e, reason); throw e2; }); @@ -205,7 +205,7 @@ asyncTest('When re-throwing new errors in a promise catch, only the ' + setTimeout(function() { reject(e); }, 1); - }).then(common.fail, function(reason) { + }).then(assert.fail, function(reason) { assert.strictEqual(e, reason); throw e2; }); @@ -224,7 +224,7 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' + setTimeout(function() { reject(e); process.nextTick(function() { - promise2 = promise.then(common.fail, function(reason) { + promise2 = promise.then(assert.fail, function(reason) { assert.strictEqual(e, reason); throw e2; }); @@ -240,7 +240,7 @@ asyncTest( function(done) { const e = new Error(); onUnhandledFail(done); - Promise.reject(e).then(common.fail, () => {}); + Promise.reject(e).then(assert.fail, () => {}); } ); @@ -252,7 +252,7 @@ asyncTest( onUnhandledFail(done); new Promise(function(_, reject) { reject(e); - }).then(common.fail, () => {}); + }).then(assert.fail, () => {}); } ); @@ -262,7 +262,7 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + onUnhandledFail(done); const promise = Promise.reject(e); process.nextTick(function() { - promise.then(common.fail, () => {}); + promise.then(assert.fail, () => {}); }); }); @@ -274,7 +274,7 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + reject(e); }); process.nextTick(function() { - promise.then(common.fail, () => {}); + promise.then(assert.fail, () => {}); }); }); @@ -305,7 +305,7 @@ asyncTest('catching a promise which is asynchronously rejected (via' + reject(e); }, 1); }); - }).then(common.fail, function(reason) { + }).then(assert.fail, function(reason) { assert.strictEqual(e, reason); }); }); @@ -316,7 +316,7 @@ asyncTest('Catching a rejected promise derived from throwing in a' + onUnhandledFail(done); Promise.resolve().then(function() { throw e; - }).then(common.fail, function(reason) { + }).then(assert.fail, function(reason) { assert.strictEqual(e, reason); }); }); @@ -328,7 +328,7 @@ asyncTest('Catching a rejected promise derived from returning a' + onUnhandledFail(done); Promise.resolve().then(function() { return Promise.reject(e); - }).then(common.fail, function(reason) { + }).then(assert.fail, function(reason) { assert.strictEqual(e, reason); }); }); @@ -385,7 +385,7 @@ asyncTest('Catching the Promise.all() of a collection that includes a' + 'rejected promise prevents unhandledRejection', function(done) { const e = new Error(); onUnhandledFail(done); - Promise.all([Promise.reject(e)]).then(common.fail, () => {}); + Promise.all([Promise.reject(e)]).then(assert.fail, () => {}); }); asyncTest( @@ -401,7 +401,7 @@ asyncTest( }); p = Promise.all([p]); process.nextTick(function() { - p.then(common.fail, () => {}); + p.then(assert.fail, () => {}); }); } ); @@ -437,7 +437,7 @@ asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + throw e; }); setTimeout(function() { - thePromise.then(common.fail, function(reason) { + thePromise.then(assert.fail, function(reason) { assert.strictEqual(e, reason); }); }, 10); diff --git a/test/parallel/test-spawn-cmd-named-pipe.js b/test/parallel/test-spawn-cmd-named-pipe.js index f586d5be0c81fd..4a19e3e1d7f41e 100644 --- a/test/parallel/test-spawn-cmd-named-pipe.js +++ b/test/parallel/test-spawn-cmd-named-pipe.js @@ -37,7 +37,7 @@ if (!process.argv[2]) { const comspec = process.env['comspec']; if (!comspec || comspec.length === 0) { - common.fail('Failed to get COMSPEC'); + assert.fail('Failed to get COMSPEC'); } const args = ['/c', process.execPath, __filename, 'child', diff --git a/test/parallel/test-stream2-base64-single-char-read-end.js b/test/parallel/test-stream2-base64-single-char-read-end.js index 0f5b9c8f892631..7bf09569410fa1 100644 --- a/test/parallel/test-stream2-base64-single-char-read-end.js +++ b/test/parallel/test-stream2-base64-single-char-read-end.js @@ -1,5 +1,5 @@ 'use strict'; -const common = require('../common'); +require('../common'); const R = require('_stream_readable'); const W = require('_stream_writable'); const assert = require('assert'); @@ -33,5 +33,5 @@ src.on('end', function() { src.pipe(dst); timeout = setTimeout(function() { - common.fail('timed out waiting for _write'); + assert.fail('timed out waiting for _write'); }, 100); diff --git a/test/parallel/test-tls-empty-sni-context.js b/test/parallel/test-tls-empty-sni-context.js index 3f39d6e8c1091a..9a8e3449f0cbea 100644 --- a/test/parallel/test-tls-empty-sni-context.js +++ b/test/parallel/test-tls-empty-sni-context.js @@ -17,7 +17,7 @@ const options = { }; const server = tls.createServer(options, (c) => { - common.fail('Should not be called'); + assert.fail('Should not be called'); }).on('tlsClientError', common.mustCall((err, c) => { assert(/SSL_use_certificate:passed a null parameter/i.test(err.message)); server.close(); diff --git a/test/parallel/test-tls-session-cache.js b/test/parallel/test-tls-session-cache.js index a1e6a615ae662f..d4c41518a35b5f 100644 --- a/test/parallel/test-tls-session-cache.js +++ b/test/parallel/test-tls-session-cache.js @@ -102,7 +102,7 @@ function doTest(testOptions, callback) { spawnClient(); return; } - common.fail(`code: ${code}, signal: ${signal}, output: ${err}`); + assert.fail(`code: ${code}, signal: ${signal}, output: ${err}`); } assert.strictEqual(code, 0); server.close(common.mustCall(function() { diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 7ef53e562c42d0..2f3ef367328f9e 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1,5 +1,5 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const util = require('util'); const vm = require('vm'); @@ -208,7 +208,7 @@ for (const showHidden of [true, false]) { ); if (out !== '{ [hidden]: 2, visible: 1 }' && out !== '{ visible: 1, [hidden]: 2 }') { - common.fail(`unexpected value for out ${out}`); + assert.fail(`unexpected value for out ${out}`); } } @@ -220,7 +220,7 @@ for (const showHidden of [true, false]) { hidden: {value: 'secret'}}), true); if (out !== "{ [hidden]: 'secret', name: 'Tim' }" && out !== "{ name: 'Tim', [hidden]: 'secret' }") { - common.fail(`unexpected value for out ${out}`); + assert.fail(`unexpected value for out ${out}`); } } diff --git a/test/parallel/test-vm-debug-context.js b/test/parallel/test-vm-debug-context.js index 313b9f4bcae6ab..032d16142e280e 100644 --- a/test/parallel/test-vm-debug-context.js +++ b/test/parallel/test-vm-debug-context.js @@ -10,7 +10,7 @@ assert.throws(function() { }, /SyntaxError/); assert.throws(function() { - vm.runInDebugContext({ toString: common.fail }); + vm.runInDebugContext({ toString: assert.fail }); }, /AssertionError/); assert.throws(function() { diff --git a/test/parallel/test-vm-syntax-error-message.js b/test/parallel/test-vm-syntax-error-message.js index 5a16239f5653e9..600b1d5097060c 100644 --- a/test/parallel/test-vm-syntax-error-message.js +++ b/test/parallel/test-vm-syntax-error-message.js @@ -11,7 +11,9 @@ const p = child_process.spawn(process.execPath, [ 'catch (e) { console.log(e.message); }' ]); -p.stderr.on('data', common.mustNotCall()); +p.stderr.on('data', function(data) { + assert.fail(`Unexpected stderr data: ${data}`); +}); let output = ''; diff --git a/test/parallel/test-vm-syntax-error-stderr.js b/test/parallel/test-vm-syntax-error-stderr.js index e40edc907c6639..a5b98beebfef08 100644 --- a/test/parallel/test-vm-syntax-error-stderr.js +++ b/test/parallel/test-vm-syntax-error-stderr.js @@ -12,7 +12,9 @@ const p = child_process.spawn(process.execPath, [ wrong_script ]); -p.stdout.on('data', common.mustNotCall()); +p.stdout.on('data', function(data) { + assert.fail(`Unexpected stdout data: ${data}`); +}); let output = '';