Skip to content

Commit e879a56

Browse files
Trottaddaleax
authored andcommitted
test: remove common.noop
This change removes `common.noop` from the Node.js internal testing common module. Over the last few weeks, I've grown to dislike the `common.noop` abstraction. First, new (and experienced) contributors are unaware of it and so it results in a large number of low-value nits on PRs. It also increases the number of things newcomers and infrequent contributors have to be aware of to be effective on the project. Second, it is confusing. Is it a singleton/property or a getter? Which should be expected? This can lead to subtle and hard-to-find bugs. (To my knowledge, none have landed on master. But I also think it's only a matter of time.) Third, the abstraction is low-value in my opinion. What does it really get us? A case could me made that it is without value at all. Lastly, and this is minor, but the abstraction is wordier than not using the abstraction. `common.noop` doesn't save anything over `() => {}`. So, I propose removing it. PR-URL: #12822 Backport-PR-URL: #14174 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 76ba1b5 commit e879a56

File tree

67 files changed

+135
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+135
-149
lines changed

test/common/README.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,26 @@ Gets IP of localhost
209209
Array of IPV6 hosts.
210210

211211
### mustCall([fn][, exact])
212-
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = `common.noop`
212+
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
213213
* `exact` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
214214
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
215215

216216
Returns a function that calls `fn`. If the returned function has not been called
217217
exactly `expected` number of times when the test is complete, then the test will
218218
fail.
219219

220-
If `fn` is not provided, `common.noop` will be used.
220+
If `fn` is not provided, an empty function will be used.
221221

222222
### mustCallAtLeast([fn][, minimum])
223-
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = `common.noop`
223+
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
224224
* `minimum` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
225225
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
226226

227227
Returns a function that calls `fn`. If the returned function has not been called
228228
at least `minimum` number of times when the test is complete, then the test will
229229
fail.
230230

231-
If `fn` is not provided, `common.noop` will be used.
231+
If `fn` is not provided, an empty function will be used.
232232

233233
### mustNotCall([msg])
234234
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) default = 'function should not have been called'
@@ -243,19 +243,6 @@ Returns a function that triggers an `AssertionError` if it is invoked. `msg` is
243243

244244
Returns `true` if the exit code `exitCode` and/or signal name `signal` represent the exit code and/or signal name of a node process that aborted, `false` otherwise.
245245

246-
### noop
247-
248-
A non-op `Function` that can be used for a variety of scenarios.
249-
250-
For instance,
251-
252-
<!-- eslint-disable strict, no-undef -->
253-
```js
254-
const common = require('../common');
255-
256-
someAsyncAPI('foo', common.mustCall(common.noop));
257-
```
258-
259246
### opensslCli
260247
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
261248

test/common/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const testRoot = process.env.NODE_TEST_DIR ?
3737

3838
const noop = () => {};
3939

40-
exports.noop = noop;
4140
exports.fixturesDir = path.join(__dirname, '..', 'fixtures');
4241
exports.tmpDirName = 'tmp';
4342
// PORT should match the definition in test/testpy/__init__.py.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Flags: --trace-warnings
22
'use strict';
3-
const common = require('../common');
3+
require('../common');
44
const p = Promise.reject(new Error('This was rejected'));
5-
setImmediate(() => p.catch(common.noop));
5+
setImmediate(() => p.catch(() => {}));

test/parallel/test-assert.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,29 +571,30 @@ a.throws(makeBlock(a.deepEqual, args, []));
571571

572572
// check messages from assert.throws()
573573
{
574+
const noop = () => {};
574575
assert.throws(
575-
() => { a.throws(common.noop); },
576+
() => { a.throws((noop)); },
576577
common.expectsError({
577578
code: 'ERR_ASSERTION',
578579
message: /^Missing expected exception\.$/
579580
}));
580581

581582
assert.throws(
582-
() => { a.throws(common.noop, TypeError); },
583+
() => { a.throws(noop, TypeError); },
583584
common.expectsError({
584585
code: 'ERR_ASSERTION',
585586
message: /^Missing expected exception \(TypeError\)\.$/
586587
}));
587588

588589
assert.throws(
589-
() => { a.throws(common.noop, 'fhqwhgads'); },
590+
() => { a.throws(noop, 'fhqwhgads'); },
590591
common.expectsError({
591592
code: 'ERR_ASSERTION',
592593
message: /^Missing expected exception: fhqwhgads$/
593594
}));
594595

595596
assert.throws(
596-
() => { a.throws(common.noop, TypeError, 'fhqwhgads'); },
597+
() => { a.throws(noop, TypeError, 'fhqwhgads'); },
597598
common.expectsError({
598599
code: 'ERR_ASSERTION',
599600
message: /^Missing expected exception \(TypeError\): fhqwhgads$/

test/parallel/test-buffer-includes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
33
const assert = require('assert');
44

55
const b = Buffer.from('abcdef');
@@ -274,7 +274,7 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
274274
const expectedError =
275275
/^TypeError: "val" argument must be string, number, Buffer or Uint8Array$/;
276276
assert.throws(() => {
277-
b.includes(common.noop);
277+
b.includes(() => {});
278278
}, expectedError);
279279
assert.throws(() => {
280280
b.includes({});

test/parallel/test-child-process-bad-stdio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('assert');
55
const cp = require('child_process');
66

77
if (process.argv[2] === 'child') {
8-
setTimeout(common.noop, common.platformTimeout(100));
8+
setTimeout(() => {}, common.platformTimeout(100));
99
return;
1010
}
1111

test/parallel/test-child-process-spawnsync-kill-signal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44
const cp = require('child_process');
55

66
if (process.argv[2] === 'child') {
7-
setInterval(common.noop, 1000);
7+
setInterval(() => {}, 1000);
88
} else {
99
const { SIGKILL } = process.binding('constants').os.signals;
1010

test/parallel/test-cluster-rr-domain-listen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
const common = require('../common');
23+
require('../common');
2424
const cluster = require('cluster');
2525
const domain = require('domain');
2626

@@ -29,10 +29,10 @@ const domain = require('domain');
2929

3030
if (cluster.isWorker) {
3131
const d = domain.create();
32-
d.run(common.noop);
32+
d.run(() => {});
3333

3434
const http = require('http');
35-
http.Server(common.noop).listen(0, '127.0.0.1');
35+
http.Server(() => {}).listen(0, '127.0.0.1');
3636

3737
} else if (cluster.isMaster) {
3838

test/parallel/test-cluster-worker-wait-server-close.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (cluster.isWorker) {
1111
const server = net.createServer(function(socket) {
1212
// Wait for any data, then close connection
1313
socket.write('.');
14-
socket.on('data', common.noop);
14+
socket.on('data', () => {});
1515
}).listen(0, common.localhostIPv4);
1616

1717
server.once('close', function() {
@@ -20,7 +20,7 @@ if (cluster.isWorker) {
2020

2121
// Although not typical, the worker process can exit before the disconnect
2222
// event fires. Use this to keep the process open until the event has fired.
23-
const keepOpen = setInterval(common.noop, 9999);
23+
const keepOpen = setInterval(() => {}, 9999);
2424

2525
// Check worker events and properties
2626
process.once('disconnect', function() {

test/parallel/test-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
101101
assert.notStrictEqual(originalWrite, stream.write);
102102

103103
HIJACK_TEST_ARRAY.forEach((val) => {
104-
stream.write(val, common.mustCall(common.noop));
104+
stream.write(val, common.mustCall());
105105
});
106106

107107
assert.strictEqual(HIJACK_TEST_ARRAY.length, stream.writeTimes);

0 commit comments

Comments
 (0)