From d9f394e60720f373465cb8b3958b6e189f9d85a6 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 24 Jun 2023 16:16:07 +0200 Subject: [PATCH] test: remove unnecessary noop function args to `mustNotCall()` PR-URL: https://github.com/nodejs/node/pull/48513 Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Harshitha K P Reviewed-By: Rich Trott --- test/.eslintrc.yaml | 2 +- test/parallel/test-child-process-execfile.js | 2 +- test/parallel/test-fs-promises-readfile.js | 2 +- test/parallel/test-fs-readfile.js | 2 +- test/parallel/test-http2-client-http1-server.js | 2 +- test/parallel/test-https-agent-session-injection.js | 4 ++-- test/parallel/test-readline-interface.js | 3 +-- test/parallel/test-stream-filter.js | 2 +- test/parallel/test-stream-flatMap.js | 2 +- test/parallel/test-stream-forEach.js | 2 +- test/parallel/test-stream-readable-destroy.js | 2 +- test/parallel/test-stream-readable-next-no-null.js | 2 +- test/parallel/test-stream-some-find-every.mjs | 2 +- test/parallel/test-worker-data-url.js | 6 +++--- 14 files changed, 17 insertions(+), 18 deletions(-) diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index d110489abc1..ef1336e34c7 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -47,7 +47,7 @@ rules: message: Use Number.isNaN() instead of the global isNaN() function. - selector: VariableDeclarator > CallExpression:matches([callee.name='debuglog'], [callee.property.name='debuglog']):not([arguments.0.value='test']) message: Use 'test' as debuglog value in tests. - - selector: CallExpression:matches([callee.object.name="common"][callee.property.name=/^mustCall/],[callee.name="mustCall"],[callee.name="mustCallAtLeast"])>:first-child[type=/FunctionExpression$/][body.body.length=0] + - selector: CallExpression:matches([callee.object.name="common"][callee.property.name=/^must(Not)?Call/],[callee.name="mustCall"],[callee.name="mustCallAtLeast"],[callee.name="mustNotCall"])>:first-child[type=/FunctionExpression$/][body.body.length=0] message: Do not use an empty function, omit the parameter altogether. - selector: Identifier[name='webcrypto'] message: Use `globalThis.crypto`. diff --git a/test/parallel/test-child-process-execfile.js b/test/parallel/test-child-process-execfile.js index f51c1729c9a..e6e04ff61f9 100644 --- a/test/parallel/test-child-process-execfile.js +++ b/test/parallel/test-child-process-execfile.js @@ -84,7 +84,7 @@ const execOpts = { encoding: 'utf8', shell: true }; // Verify that if something different than Abortcontroller.signal // is passed, ERR_INVALID_ARG_TYPE is thrown assert.throws(() => { - const callback = common.mustNotCall(() => {}); + const callback = common.mustNotCall(); execFile(process.execPath, [echoFixture, 0], { signal: 'hello' }, callback); }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' }); diff --git a/test/parallel/test-fs-promises-readfile.js b/test/parallel/test-fs-promises-readfile.js index fd1bfabf88d..8043223e591 100644 --- a/test/parallel/test-fs-promises-readfile.js +++ b/test/parallel/test-fs-promises-readfile.js @@ -64,7 +64,7 @@ async function validateWrongSignalParam() { // is passed, ERR_INVALID_ARG_TYPE is thrown await assert.rejects(async () => { - const callback = common.mustNotCall(() => {}); + const callback = common.mustNotCall(); await readFile(fn, { signal: 'hello' }, callback); }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' }); diff --git a/test/parallel/test-fs-readfile.js b/test/parallel/test-fs-readfile.js index 1a7ddf45beb..999c2216527 100644 --- a/test/parallel/test-fs-readfile.js +++ b/test/parallel/test-fs-readfile.js @@ -95,7 +95,7 @@ for (const e of fileInfo) { // Verify that if something different than Abortcontroller.signal // is passed, ERR_INVALID_ARG_TYPE is thrown assert.throws(() => { - const callback = common.mustNotCall(() => {}); + const callback = common.mustNotCall(); fs.readFile(fileInfo[0].name, { signal: 'hello' }, callback); }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' }); } diff --git a/test/parallel/test-http2-client-http1-server.js b/test/parallel/test-http2-client-http1-server.js index e6680ee14bd..4a7c7c0a7d5 100644 --- a/test/parallel/test-http2-client-http1-server.js +++ b/test/parallel/test-http2-client-http1-server.js @@ -11,7 +11,7 @@ const http2 = require('http2'); const { NghttpError } = require('internal/http2/util'); // Creating an http1 server here... -const server = http.createServer(common.mustNotCall(() => {})) +const server = http.createServer(common.mustNotCall()) .on('clientError', common.mustCall((error, socket) => { assert.strictEqual(error.code, 'HPE_PAUSED_H2_UPGRADE'); assert.strictEqual(error.bytesParsed, 24); diff --git a/test/parallel/test-https-agent-session-injection.js b/test/parallel/test-https-agent-session-injection.js index cb9358b1b17..986953a59fe 100644 --- a/test/parallel/test-https-agent-session-injection.js +++ b/test/parallel/test-https-agent-session-injection.js @@ -32,7 +32,7 @@ const server = https.createServer(options, function(req, res) { path: '/', ca, servername: 'nodejs.org', - }, common.mustNotCall(() => {})); + }, common.mustNotCall()); req.on('error', common.mustCall((err) => { assert.strictEqual( @@ -45,7 +45,7 @@ const server = https.createServer(options, function(req, res) { path: '/', ca, servername: 'nodejs.org', - }, common.mustNotCall(() => {})); + }, common.mustNotCall()); second.on('error', common.mustCall((err) => { server.close(); diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 1e02c34b225..b5ffb490fba 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -1067,8 +1067,7 @@ for (let i = 0; i < 12; i++) { rli.question('foo?', common.mustCall((answer) => { assert.strictEqual(answer, 'baz'); })); - rli.question('bar?', common.mustNotCall(() => { - })); + rli.question('bar?', common.mustNotCall()); rli.write('baz\n'); rli.close(); } diff --git a/test/parallel/test-stream-filter.js b/test/parallel/test-stream-filter.js index e434eb8c84e..173e4f47e24 100644 --- a/test/parallel/test-stream-filter.js +++ b/test/parallel/test-stream-filter.js @@ -169,7 +169,7 @@ const { setTimeout } = require('timers/promises'); { const stream = Readable.from([1, 2, 3, 4, 5]); Object.defineProperty(stream, 'map', { - value: common.mustNotCall(() => {}), + value: common.mustNotCall(), }); // Check that map isn't getting called. stream.filter(() => true); diff --git a/test/parallel/test-stream-flatMap.js b/test/parallel/test-stream-flatMap.js index 07c534a9c1f..0e55119f7a7 100644 --- a/test/parallel/test-stream-flatMap.js +++ b/test/parallel/test-stream-flatMap.js @@ -124,7 +124,7 @@ function oneTo5() { { const stream = oneTo5(); Object.defineProperty(stream, 'map', { - value: common.mustNotCall(() => {}), + value: common.mustNotCall(), }); // Check that map isn't getting called. stream.flatMap(() => true); diff --git a/test/parallel/test-stream-forEach.js b/test/parallel/test-stream-forEach.js index e3678352c41..7a21e299534 100644 --- a/test/parallel/test-stream-forEach.js +++ b/test/parallel/test-stream-forEach.js @@ -132,7 +132,7 @@ const { once } = require('events'); { const stream = Readable.from([1, 2, 3, 4, 5]); Object.defineProperty(stream, 'map', { - value: common.mustNotCall(() => {}), + value: common.mustNotCall(), }); // Check that map isn't getting called. stream.forEach(() => true); diff --git a/test/parallel/test-stream-readable-destroy.js b/test/parallel/test-stream-readable-destroy.js index fc82f44bc9d..a62beb27961 100644 --- a/test/parallel/test-stream-readable-destroy.js +++ b/test/parallel/test-stream-readable-destroy.js @@ -249,7 +249,7 @@ const assert = require('assert'); { const read = new Readable({ - read: common.mustNotCall(function() {}) + read: common.mustNotCall() }); read.destroy(); assert.strictEqual(read.destroyed, true); diff --git a/test/parallel/test-stream-readable-next-no-null.js b/test/parallel/test-stream-readable-next-no-null.js index 64ca40be11e..7599e386ca7 100644 --- a/test/parallel/test-stream-readable-next-no-null.js +++ b/test/parallel/test-stream-readable-next-no-null.js @@ -14,6 +14,6 @@ stream.on('error', expectsError({ message: 'May not write null values to stream' })); -stream.on('data', mustNotCall((chunk) => {})); +stream.on('data', mustNotCall()); stream.on('end', mustNotCall()); diff --git a/test/parallel/test-stream-some-find-every.mjs b/test/parallel/test-stream-some-find-every.mjs index c4637d41deb..0617102bc47 100644 --- a/test/parallel/test-stream-some-find-every.mjs +++ b/test/parallel/test-stream-some-find-every.mjs @@ -164,7 +164,7 @@ function oneTo5Async() { for (const op of ['some', 'every', 'find']) { const stream = oneTo5(); Object.defineProperty(stream, 'map', { - value: common.mustNotCall(() => {}), + value: common.mustNotCall(), }); // Check that map isn't getting called. stream[op](() => {}); diff --git a/test/parallel/test-worker-data-url.js b/test/parallel/test-worker-data-url.js index f224ebcf447..6649565a0c1 100644 --- a/test/parallel/test-worker-data-url.js +++ b/test/parallel/test-worker-data-url.js @@ -5,9 +5,9 @@ const { Worker } = require('worker_threads'); const assert = require('assert'); new Worker(new URL('data:text/javascript,')) - .on('error', common.mustNotCall(() => {})); + .on('error', common.mustNotCall()); new Worker(new URL('data:text/javascript,export{}')) - .on('error', common.mustNotCall(() => {})); + .on('error', common.mustNotCall()); new Worker(new URL('data:text/plain,')) .on('error', common.mustCall()); @@ -15,7 +15,7 @@ new Worker(new URL('data:text/javascript,module.exports={}')) .on('error', common.mustCall()); new Worker(new URL('data:text/javascript,await Promise.resolve()')) - .on('error', common.mustNotCall(() => {})); + .on('error', common.mustNotCall()); new Worker(new URL('data:text/javascript,await Promise.reject()')) .on('error', common.mustCall()); new Worker(new URL('data:text/javascript,await new Promise(()=>{})'))