Skip to content

Commit 688e5ed

Browse files
TrottMylesBorins
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 40a61e1 commit 688e5ed

File tree

62 files changed

+153
-159
lines changed

Some content is hidden

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

62 files changed

+153
-159
lines changed

test/common/README.md

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

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

190190
Returns a function that calls `fn`. If the returned function has not been called
191191
exactly `expected` number of times when the test is complete, then the test will
192192
fail.
193193

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

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

201201
Returns a function that calls `fn`. If the returned function has not been called
202202
at least `minimum` number of times when the test is complete, then the test will
203203
fail.
204204

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

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

218218
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.
219219

220-
### noop
221-
222-
A non-op `Function` that can be used for a variety of scenarios.
223-
224-
For instance,
225-
226-
<!-- eslint-disable strict, no-undef -->
227-
```js
228-
const common = require('../common');
229-
230-
someAsyncAPI('foo', common.mustCall(common.noop));
231-
```
232-
233220
### opensslCli
234221
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
235222

test/common/index.js

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

1515
const noop = () => {};
1616

17-
exports.noop = noop;
1817
exports.fixturesDir = path.join(__dirname, '..', 'fixtures');
1918
exports.tmpDirName = 'tmp';
2019
// PORT should match the definition in test/testpy/__init__.py.

test/debugger/test-debugger-client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ addTest(function(client, done) {
129129

130130
let connectCount = 0;
131131
const script = 'setTimeout(function() { console.log("blah"); });' +
132-
'setInterval(common.noop, 1000000);';
132+
'setInterval(() => {}, 1000000);';
133133

134134
let nodeProcess;
135135

@@ -172,7 +172,7 @@ function doTest(cb, done) {
172172
console.error('>>> connecting...');
173173
c.connect(debug.port);
174174
c.on('break', function() {
175-
c.reqContinue(common.noop);
175+
c.reqContinue(() => {});
176176
});
177177
c.on('ready', function() {
178178
connectCount++;

test/parallel/test-assert.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
const a = require('assert');
55

@@ -515,7 +515,7 @@ testAssertionMessage(/a/, '/a/');
515515
testAssertionMessage(/abc/gim, '/abc/gim');
516516
testAssertionMessage(function f() {}, '[Function: f]');
517517
testAssertionMessage(function() {}, '[Function]');
518-
testAssertionMessage(common.noop, '[Function: noop]');
518+
testAssertionMessage(() => {}, '[Function]');
519519
testAssertionMessage({}, '{}');
520520
testAssertionMessage(circular, '{ y: 1, x: [Circular] }');
521521
testAssertionMessage({a: undefined, b: null}, '{ a: undefined, b: null }');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const domain = require('domain');
88

99
if (cluster.isWorker) {
1010
const d = domain.create();
11-
d.run(function() { });
11+
d.run(() => {});
1212

1313
const http = require('http');
14-
http.Server(function() { }).listen(0, '127.0.0.1');
14+
http.Server(() => {}).listen(0, '127.0.0.1');
1515

1616
} else if (cluster.isMaster) {
1717
let worker;

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', function discard() {});
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ global.gc = 42; // Not a valid global unless --expose_gc is set.
1010
assert.deepStrictEqual(common.leakedGlobals(), ['gc']);
1111

1212
assert.throws(function() {
13-
common.mustCall(common.noop, 'foo');
13+
common.mustCall(() => {}, 'foo');
1414
}, /^TypeError: Invalid exact value: foo$/);
1515

1616
assert.throws(function() {
17-
common.mustCall(common.noop, /foo/);
17+
common.mustCall(() => {}, /foo/);
1818
}, /^TypeError: Invalid exact value: \/foo\/$/);
1919

2020
const fnOnce = common.mustCall(() => {});

test/parallel/test-crypto-random.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
1616
[crypto.randomBytes, crypto.pseudoRandomBytes].forEach(function(f) {
1717
[-1, undefined, null, false, true, {}, []].forEach(function(value) {
1818
assert.throws(function() { f(value); }, expectedErrorRegexp);
19-
assert.throws(function() { f(value, common.noop); }, expectedErrorRegexp);
19+
assert.throws(function() { f(value, () => {}); }, expectedErrorRegexp);
2020
});
2121

2222
[0, 1, 2, 4, 16, 256, 1024].forEach(function(len) {

test/parallel/test-env-var-no-warnings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if (process.argv[2] === 'child') {
2929
test({ NODE_NO_WARNINGS: false });
3030
test({ NODE_NO_WARNINGS: {} });
3131
test({ NODE_NO_WARNINGS: [] });
32-
test({ NODE_NO_WARNINGS: common.noop });
32+
test({ NODE_NO_WARNINGS: () => {} });
3333
test({ NODE_NO_WARNINGS: 0 });
3434
test({ NODE_NO_WARNINGS: -1 });
3535
test({ NODE_NO_WARNINGS: '0' });

test/parallel/test-event-emitter-check-listener-leaks.js

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

66
let e = new events.EventEmitter();
77

88
// default
99
for (let i = 0; i < 10; i++) {
10-
e.on('default', common.noop);
10+
e.on('default', () => {});
1111
}
1212
assert.ok(!e._events['default'].hasOwnProperty('warned'));
13-
e.on('default', common.noop);
13+
e.on('default', () => {});
1414
assert.ok(e._events['default'].warned);
1515

1616
// symbol
1717
const symbol = Symbol('symbol');
1818
e.setMaxListeners(1);
19-
e.on(symbol, common.noop);
19+
e.on(symbol, () => {});
2020
assert.ok(!e._events[symbol].hasOwnProperty('warned'));
21-
e.on(symbol, common.noop);
21+
e.on(symbol, () => {});
2222
assert.ok(e._events[symbol].hasOwnProperty('warned'));
2323

2424
// specific
2525
e.setMaxListeners(5);
2626
for (let i = 0; i < 5; i++) {
27-
e.on('specific', common.noop);
27+
e.on('specific', () => {});
2828
}
2929
assert.ok(!e._events['specific'].hasOwnProperty('warned'));
30-
e.on('specific', common.noop);
30+
e.on('specific', () => {});
3131
assert.ok(e._events['specific'].warned);
3232

3333
// only one
3434
e.setMaxListeners(1);
35-
e.on('only one', common.noop);
35+
e.on('only one', () => {});
3636
assert.ok(!e._events['only one'].hasOwnProperty('warned'));
37-
e.on('only one', common.noop);
37+
e.on('only one', () => {});
3838
assert.ok(e._events['only one'].hasOwnProperty('warned'));
3939

4040
// unlimited
4141
e.setMaxListeners(0);
4242
for (let i = 0; i < 1000; i++) {
43-
e.on('unlimited', common.noop);
43+
e.on('unlimited', () => {});
4444
}
4545
assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
4646

@@ -49,26 +49,26 @@ events.EventEmitter.defaultMaxListeners = 42;
4949
e = new events.EventEmitter();
5050

5151
for (let i = 0; i < 42; ++i) {
52-
e.on('fortytwo', common.noop);
52+
e.on('fortytwo', () => {});
5353
}
5454
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
55-
e.on('fortytwo', common.noop);
55+
e.on('fortytwo', () => {});
5656
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
5757
delete e._events['fortytwo'].warned;
5858

5959
events.EventEmitter.defaultMaxListeners = 44;
60-
e.on('fortytwo', common.noop);
60+
e.on('fortytwo', () => {});
6161
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
62-
e.on('fortytwo', common.noop);
62+
e.on('fortytwo', () => {});
6363
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
6464

6565
// but _maxListeners still has precedence over defaultMaxListeners
6666
events.EventEmitter.defaultMaxListeners = 42;
6767
e = new events.EventEmitter();
6868
e.setMaxListeners(1);
69-
e.on('uno', common.noop);
69+
e.on('uno', () => {});
7070
assert.ok(!e._events['uno'].hasOwnProperty('warned'));
71-
e.on('uno', common.noop);
71+
e.on('uno', () => {});
7272
assert.ok(e._events['uno'].hasOwnProperty('warned'));
7373

7474
// chainable

0 commit comments

Comments
 (0)