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: https://github.com/nodejs/node/pull/12822
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Rich Trott 2017-05-03 21:07:54 -07:00
parent 932ee65cd2
commit 380929ec0c
67 changed files with 134 additions and 148 deletions

View File

@ -209,7 +209,7 @@ Gets IP of localhost
Array of IPV6 hosts. Array of IPV6 hosts.
### mustCall([fn][, exact]) ### mustCall([fn][, exact])
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = `common.noop` * `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
* `exact` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1 * `exact` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) * return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
@ -217,10 +217,10 @@ Returns a function that calls `fn`. If the returned function has not been called
exactly `expected` number of times when the test is complete, then the test will exactly `expected` number of times when the test is complete, then the test will
fail. fail.
If `fn` is not provided, `common.noop` will be used. If `fn` is not provided, an empty function will be used.
### mustCallAtLeast([fn][, minimum]) ### mustCallAtLeast([fn][, minimum])
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = `common.noop` * `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
* `minimum` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1 * `minimum` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) * return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
@ -228,7 +228,7 @@ Returns a function that calls `fn`. If the returned function has not been called
at least `minimum` number of times when the test is complete, then the test will at least `minimum` number of times when the test is complete, then the test will
fail. fail.
If `fn` is not provided, `common.noop` will be used. If `fn` is not provided, an empty function will be used.
### mustNotCall([msg]) ### mustNotCall([msg])
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) default = 'function should not have been called' * `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
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. 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.
### noop
A non-op `Function` that can be used for a variety of scenarios.
For instance,
<!-- eslint-disable strict, no-undef -->
```js
const common = require('../common');
someAsyncAPI('foo', common.mustCall(common.noop));
```
### opensslCli ### opensslCli
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) * return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)

View File

@ -37,7 +37,6 @@ const testRoot = process.env.NODE_TEST_DIR ?
const noop = () => {}; const noop = () => {};
exports.noop = noop;
exports.fixturesDir = path.join(__dirname, '..', 'fixtures'); exports.fixturesDir = path.join(__dirname, '..', 'fixtures');
exports.tmpDirName = 'tmp'; exports.tmpDirName = 'tmp';
// PORT should match the definition in test/testpy/__init__.py. // PORT should match the definition in test/testpy/__init__.py.

View File

@ -1,5 +1,5 @@
// Flags: --trace-warnings // Flags: --trace-warnings
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const p = Promise.reject(new Error('This was rejected')); const p = Promise.reject(new Error('This was rejected'));
setImmediate(() => p.catch(common.noop)); setImmediate(() => p.catch(() => {}));

View File

@ -571,29 +571,30 @@ a.throws(makeBlock(a.deepEqual, args, []));
// check messages from assert.throws() // check messages from assert.throws()
{ {
const noop = () => {};
assert.throws( assert.throws(
() => { a.throws(common.noop); }, () => { a.throws((noop)); },
common.expectsError({ common.expectsError({
code: 'ERR_ASSERTION', code: 'ERR_ASSERTION',
message: /^Missing expected exception\.$/ message: /^Missing expected exception\.$/
})); }));
assert.throws( assert.throws(
() => { a.throws(common.noop, TypeError); }, () => { a.throws(noop, TypeError); },
common.expectsError({ common.expectsError({
code: 'ERR_ASSERTION', code: 'ERR_ASSERTION',
message: /^Missing expected exception \(TypeError\)\.$/ message: /^Missing expected exception \(TypeError\)\.$/
})); }));
assert.throws( assert.throws(
() => { a.throws(common.noop, 'fhqwhgads'); }, () => { a.throws(noop, 'fhqwhgads'); },
common.expectsError({ common.expectsError({
code: 'ERR_ASSERTION', code: 'ERR_ASSERTION',
message: /^Missing expected exception: fhqwhgads$/ message: /^Missing expected exception: fhqwhgads$/
})); }));
assert.throws( assert.throws(
() => { a.throws(common.noop, TypeError, 'fhqwhgads'); }, () => { a.throws(noop, TypeError, 'fhqwhgads'); },
common.expectsError({ common.expectsError({
code: 'ERR_ASSERTION', code: 'ERR_ASSERTION',
message: /^Missing expected exception \(TypeError\): fhqwhgads$/ message: /^Missing expected exception \(TypeError\): fhqwhgads$/

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const b = Buffer.from('abcdef'); const b = Buffer.from('abcdef');
@ -274,7 +274,7 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
const expectedError = const expectedError =
/^TypeError: "val" argument must be string, number, Buffer or Uint8Array$/; /^TypeError: "val" argument must be string, number, Buffer or Uint8Array$/;
assert.throws(() => { assert.throws(() => {
b.includes(common.noop); b.includes(() => {});
}, expectedError); }, expectedError);
assert.throws(() => { assert.throws(() => {
b.includes({}); b.includes({});

View File

@ -5,7 +5,7 @@ const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
if (process.argv[2] === 'child') { if (process.argv[2] === 'child') {
setTimeout(common.noop, common.platformTimeout(100)); setTimeout(() => {}, common.platformTimeout(100));
return; return;
} }

View File

@ -5,7 +5,7 @@ const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
if (process.argv[2] === 'child') { if (process.argv[2] === 'child') {
setInterval(common.noop, 1000); setInterval(() => {}, 1000);
} else { } else {
const internalCp = require('internal/child_process'); const internalCp = require('internal/child_process');
const oldSpawnSync = internalCp.spawnSync; const oldSpawnSync = internalCp.spawnSync;

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const cluster = require('cluster'); const cluster = require('cluster');
const domain = require('domain'); const domain = require('domain');
@ -29,10 +29,10 @@ const domain = require('domain');
if (cluster.isWorker) { if (cluster.isWorker) {
const d = domain.create(); const d = domain.create();
d.run(common.noop); d.run(() => {});
const http = require('http'); const http = require('http');
http.Server(common.noop).listen(0, '127.0.0.1'); http.Server(() => {}).listen(0, '127.0.0.1');
} else if (cluster.isMaster) { } else if (cluster.isMaster) {

View File

@ -11,7 +11,7 @@ if (cluster.isWorker) {
const server = net.createServer(function(socket) { const server = net.createServer(function(socket) {
// Wait for any data, then close connection // Wait for any data, then close connection
socket.write('.'); socket.write('.');
socket.on('data', common.noop); socket.on('data', () => {});
}).listen(0, common.localhostIPv4); }).listen(0, common.localhostIPv4);
server.once('close', function() { server.once('close', function() {
@ -20,7 +20,7 @@ if (cluster.isWorker) {
// Although not typical, the worker process can exit before the disconnect // Although not typical, the worker process can exit before the disconnect
// event fires. Use this to keep the process open until the event has fired. // event fires. Use this to keep the process open until the event has fired.
const keepOpen = setInterval(common.noop, 9999); const keepOpen = setInterval(() => {}, 9999);
// Check worker events and properties // Check worker events and properties
process.once('disconnect', function() { process.once('disconnect', function() {

View File

@ -101,7 +101,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
assert.notStrictEqual(originalWrite, stream.write); assert.notStrictEqual(originalWrite, stream.write);
HIJACK_TEST_ARRAY.forEach((val) => { HIJACK_TEST_ARRAY.forEach((val) => {
stream.write(val, common.mustCall(common.noop)); stream.write(val, common.mustCall());
}); });
assert.strictEqual(HIJACK_TEST_ARRAY.length, stream.writeTimes); assert.strictEqual(HIJACK_TEST_ARRAY.length, stream.writeTimes);

View File

@ -49,7 +49,7 @@ assert.throws(
// Console constructor should throw if stderr exists but is not writable // Console constructor should throw if stderr exists but is not writable
assert.throws( assert.throws(
() => { () => {
out.write = common.noop; out.write = () => {};
err.write = undefined; err.write = undefined;
new Console(out, err); new Console(out, err);
}, },

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const EventEmitter = require('events'); const EventEmitter = require('events');
@ -15,5 +15,5 @@ assert.strictEqual(emitter.getMaxListeners(), 3);
// https://github.com/nodejs/node/issues/523 - second call should not throw. // https://github.com/nodejs/node/issues/523 - second call should not throw.
const recv = {}; const recv = {};
EventEmitter.prototype.on.call(recv, 'event', common.noop); EventEmitter.prototype.on.call(recv, 'event', () => {});
EventEmitter.prototype.on.call(recv, 'event', common.noop); EventEmitter.prototype.on.call(recv, 'event', () => {});

View File

@ -1,15 +1,15 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const EventEmitter = require('events'); const EventEmitter = require('events');
const emitter = new EventEmitter(); const emitter = new EventEmitter();
emitter.on('foo', common.noop); emitter.on('foo', () => {});
emitter.on('foo', common.noop); emitter.on('foo', () => {});
emitter.on('baz', common.noop); emitter.on('baz', () => {});
// Allow any type // Allow any type
emitter.on(123, common.noop); emitter.on(123, () => {});
assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2); assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2);
assert.strictEqual(emitter.listenerCount('foo'), 2); assert.strictEqual(emitter.listenerCount('foo'), 2);

View File

@ -18,5 +18,5 @@ process.on('warning', common.mustCall((warning) => {
assert.ok(warning.message.includes('2 null listeners added.')); assert.ok(warning.message.includes('2 null listeners added.'));
})); }));
e.on(null, common.noop); e.on(null, () => {});
e.on(null, common.noop); e.on(null, () => {});

View File

@ -20,5 +20,5 @@ process.on('warning', common.mustCall((warning) => {
assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.')); assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.'));
})); }));
e.on(symbol, common.noop); e.on(symbol, () => {});
e.on(symbol, common.noop); e.on(symbol, () => {});

View File

@ -18,6 +18,6 @@ process.on('warning', common.mustCall((warning) => {
assert.ok(warning.message.includes('2 event-type listeners added.')); assert.ok(warning.message.includes('2 event-type listeners added.'));
})); }));
e.on('event-type', common.noop); e.on('event-type', () => {});
e.on('event-type', common.noop); // Trigger warning. e.on('event-type', () => {}); // Trigger warning.
e.on('event-type', common.noop); // Verify that warning is emitted only once. e.on('event-type', () => {}); // Verify that warning is emitted only once.

View File

@ -140,7 +140,7 @@ function listener2() {}
{ {
const ee = new EventEmitter(); const ee = new EventEmitter();
assert.deepStrictEqual(ee, ee.removeListener('foo', common.noop)); assert.deepStrictEqual(ee, ee.removeListener('foo', () => {}));
} }
// Verify that the removed listener must be a function // Verify that the removed listener must be a function
@ -152,7 +152,7 @@ assert.throws(() => {
{ {
const ee = new EventEmitter(); const ee = new EventEmitter();
const listener = common.noop; const listener = () => {};
ee._events = undefined; ee._events = undefined;
const e = ee.removeListener('foo', listener); const e = ee.removeListener('foo', listener);
assert.strictEqual(e, ee); assert.strictEqual(e, ee);

View File

@ -5,7 +5,7 @@ const EventEmitter = require('events');
const assert = require('assert'); const assert = require('assert');
const ee = new EventEmitter(); const ee = new EventEmitter();
const handler = common.noop; const handler = () => {};
assert.deepStrictEqual(ee.eventNames(), []); assert.deepStrictEqual(ee.eventNames(), []);

View File

@ -62,6 +62,6 @@ MyEE2.prototype = new EventEmitter();
const ee1 = new MyEE2(); const ee1 = new MyEE2();
const ee2 = new MyEE2(); const ee2 = new MyEE2();
ee1.on('x', common.noop); ee1.on('x', () => {});
assert.strictEqual(ee2.listenerCount('x'), 0); assert.strictEqual(ee2.listenerCount('x'), 0);

View File

@ -5,7 +5,6 @@ const EventEmitter = require('events');
const assert = require('assert'); const assert = require('assert');
const EE = new EventEmitter(); const EE = new EventEmitter();
// Do not use common.noop here, these need to be separate listener functions
const m = () => {}; const m = () => {};
EE.on('foo', () => {}); EE.on('foo', () => {});
assert.deepStrictEqual(['foo'], EE.eventNames()); assert.deepStrictEqual(['foo'], EE.eventNames());

View File

@ -9,7 +9,7 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const filePath = path.join(common.tmpDir, 'test_buffer_type'); const filePath = path.join(common.tmpDir, 'test_buffer_type');
const v = [true, false, 0, 1, Infinity, common.noop, {}, [], undefined, null]; const v = [true, false, 0, 1, Infinity, () => {}, {}, [], undefined, null];
common.refreshTmpDir(); common.refreshTmpDir();

View File

@ -77,4 +77,4 @@ common.refreshTmpDir();
// Keep the event loop alive so the async mkdir() requests // Keep the event loop alive so the async mkdir() requests
// have a chance to run (since they don't ref the event loop). // have a chance to run (since they don't ref the event loop).
process.nextTick(common.noop); process.nextTick(() => {});

View File

@ -87,7 +87,7 @@ const strictEqual = require('assert').strictEqual;
// tcp // tcp
{ {
const net = require('net'); const net = require('net');
const server = net.createServer(common.noop).listen(0); const server = net.createServer(() => {}).listen(0);
strictEqual(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'), strictEqual(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'),
true, 'tcp_wrap: hasRef() missing'); true, 'tcp_wrap: hasRef() missing');
strictEqual(server._handle.hasRef(), strictEqual(server._handle.hasRef(),
@ -112,7 +112,7 @@ const strictEqual = require('assert').strictEqual;
// timers // timers
{ {
const timer = setTimeout(common.noop, 500); const timer = setTimeout(() => {}, 500);
timer.unref(); timer.unref();
strictEqual(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'), strictEqual(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'),
true, 'timer_wrap: hasRef() missing'); true, 'timer_wrap: hasRef() missing');

View File

@ -1,23 +1,23 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const ClientRequest = require('http').ClientRequest; const ClientRequest = require('http').ClientRequest;
{ {
const req = new ClientRequest({ createConnection: common.noop }); const req = new ClientRequest({ createConnection: () => {} });
assert.strictEqual(req.path, '/'); assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET'); assert.strictEqual(req.method, 'GET');
} }
{ {
const req = new ClientRequest({ method: '', createConnection: common.noop }); const req = new ClientRequest({ method: '', createConnection: () => {} });
assert.strictEqual(req.path, '/'); assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET'); assert.strictEqual(req.method, 'GET');
} }
{ {
const req = new ClientRequest({ path: '', createConnection: common.noop }); const req = new ClientRequest({ path: '', createConnection: () => {} });
assert.strictEqual(req.path, '/'); assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET'); assert.strictEqual(req.method, 'GET');
} }

View File

@ -4,7 +4,7 @@
// Flags: --expose_gc // Flags: --expose_gc
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const HTTPParser = process.binding('http_parser').HTTPParser; const HTTPParser = process.binding('http_parser').HTTPParser;
@ -39,7 +39,7 @@ function demoBug(part1, part2) {
console.log('url', info.url); console.log('url', info.url);
}; };
parser[kOnBody] = common.noop; parser[kOnBody] = () => {};
parser[kOnMessageComplete] = function() { parser[kOnMessageComplete] = function() {
messagesComplete++; messagesComplete++;

View File

@ -21,7 +21,7 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const util = require('util'); const util = require('util');
@ -38,7 +38,7 @@ function createTestServer() {
} }
function testServer() { function testServer() {
http.Server.call(this, common.noop); http.Server.call(this, () => {});
this.on('connection', function() { this.on('connection', function() {
requests_recv++; requests_recv++;

View File

@ -49,7 +49,7 @@ server.listen(0, function() {
}; };
const req = https.request(requestOptions, function(res) { const req = https.request(requestOptions, function(res) {
res.on('data', common.noop); res.on('data', () => {});
setImmediate(shutdown); setImmediate(shutdown);
}); });
req.end(); req.end();

View File

@ -58,7 +58,7 @@ server_http.listen(0, function() {
}); });
// These methods should exist on the request and get passed down to the socket // These methods should exist on the request and get passed down to the socket
req.setNoDelay(true); req.setNoDelay(true);
req.setTimeout(1000, common.noop); req.setTimeout(1000, () => {});
req.setSocketKeepAlive(true, 1000); req.setSocketKeepAlive(true, 1000);
req.end(); req.end();
}); });
@ -82,7 +82,7 @@ server_https.listen(0, function() {
}); });
// These methods should exist on the request and get passed down to the socket // These methods should exist on the request and get passed down to the socket
req.setNoDelay(true); req.setNoDelay(true);
req.setTimeout(1000, common.noop); req.setTimeout(1000, () => {});
req.setSocketKeepAlive(true, 1000); req.setSocketKeepAlive(true, 1000);
req.end(); req.end();
}); });

View File

@ -1,11 +1,11 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
// Regression test for instanceof, see // Regression test for instanceof, see
// https://github.com/nodejs/node/issues/7592 // https://github.com/nodejs/node/issues/7592
const F = common.noop; const F = () => {};
F.prototype = {}; F.prototype = {};
assert(Object.create(F.prototype) instanceof F); assert(Object.create(F.prototype) instanceof F);

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const cluster = require('cluster'); const cluster = require('cluster');
const net = require('net'); const net = require('net');
@ -20,7 +20,7 @@ if (cluster.isMaster) {
}); });
}); });
} else { } else {
const server = net.createServer(common.noop); const server = net.createServer(() => {});
server.on('error', function(err) { server.on('error', function(err) {
process.send(err.code); process.send(err.code);

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const net = require('net'); const net = require('net');
@ -20,7 +20,7 @@ function connectThrows(input) {
}, expectedError); }, expectedError);
} }
connectDoesNotThrow(common.noop); connectDoesNotThrow(() => {});
function connectDoesNotThrow(input) { function connectDoesNotThrow(input) {
const opts = { const opts = {

View File

@ -27,7 +27,7 @@ const assert = require('assert');
// Verify that invalid delays throw // Verify that invalid delays throw
const s = new net.Socket(); const s = new net.Socket();
const nonNumericDelays = [ const nonNumericDelays = [
'100', true, false, undefined, null, '', {}, common.noop, [] '100', true, false, undefined, null, '', {}, () => {}, []
]; ];
const badRangeDelays = [-0.001, -1, -Infinity, Infinity, NaN]; const badRangeDelays = [-0.001, -1, -Infinity, Infinity, NaN];
const validDelays = [0, 0.001, 1, 1e6]; const validDelays = [0, 0.001, 1, 1e6];
@ -35,19 +35,19 @@ const validDelays = [0, 0.001, 1, 1e6];
for (let i = 0; i < nonNumericDelays.length; i++) { for (let i = 0; i < nonNumericDelays.length; i++) {
assert.throws(function() { assert.throws(function() {
s.setTimeout(nonNumericDelays[i], common.noop); s.setTimeout(nonNumericDelays[i], () => {});
}, TypeError); }, TypeError);
} }
for (let i = 0; i < badRangeDelays.length; i++) { for (let i = 0; i < badRangeDelays.length; i++) {
assert.throws(function() { assert.throws(function() {
s.setTimeout(badRangeDelays[i], common.noop); s.setTimeout(badRangeDelays[i], () => {});
}, RangeError); }, RangeError);
} }
for (let i = 0; i < validDelays.length; i++) { for (let i = 0; i < validDelays.length; i++) {
assert.doesNotThrow(function() { assert.doesNotThrow(function() {
s.setTimeout(validDelays[i], common.noop); s.setTimeout(validDelays[i], () => {});
}); });
} }

View File

@ -21,7 +21,7 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const net = require('net'); const net = require('net');
@ -54,7 +54,7 @@ const server = net.createServer(function(socket) {
}); });
for (let i = 0; i < N; ++i) { for (let i = 0; i < N; ++i) {
socket.write(buf, common.noop); socket.write(buf, () => {});
} }
socket.end(); socket.end();

View File

@ -27,6 +27,6 @@ setImmediate(common.mustCall(() => {
require('domain'); require('domain');
setImmediate(common.mustCall(() => setImmediate(common.mustCall(() => { setImmediate(common.mustCall(() => setImmediate(common.mustCall(() => {
allsGood = true; allsGood = true;
process.nextTick(common.noop); process.nextTick(() => {});
})))); }))));
})); }));

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
for (let i = 0; i < 12; i++) for (let i = 0; i < 12; i++)
fs.open(__filename, 'r', common.noop); fs.open(__filename, 'r', () => {});
assert.strictEqual(12, process._getActiveRequests().length); assert.strictEqual(12, process._getActiveRequests().length);

View File

@ -26,4 +26,4 @@ process.on('warning', common.mustCall((warning) => {
}, 3)); }, 3));
const p = Promise.reject('This was rejected'); const p = Promise.reject('This was rejected');
setImmediate(common.mustCall(() => p.catch(common.noop))); setImmediate(common.mustCall(() => p.catch(() => {})));

View File

@ -34,10 +34,10 @@ function FakeInput() {
EventEmitter.call(this); EventEmitter.call(this);
} }
inherits(FakeInput, EventEmitter); inherits(FakeInput, EventEmitter);
FakeInput.prototype.resume = common.noop; FakeInput.prototype.resume = () => {};
FakeInput.prototype.pause = common.noop; FakeInput.prototype.pause = () => {};
FakeInput.prototype.write = common.noop; FakeInput.prototype.write = () => {};
FakeInput.prototype.end = common.noop; FakeInput.prototype.end = () => {};
function isWarned(emitter) { function isWarned(emitter) {
for (const name in emitter) { for (const name in emitter) {

View File

@ -298,7 +298,7 @@ const runKeyIntervalTests = [
{ name: 'escape', sequence: '\x1b', meta: true }, { name: 'escape', sequence: '\x1b', meta: true },
{ name: 'escape', sequence: '\x1b', meta: true } { name: 'escape', sequence: '\x1b', meta: true }
]) ])
].reverse().reduce((acc, fn) => fn(acc), common.noop); ].reverse().reduce((acc, fn) => fn(acc), () => {});
// run key interval tests one after another // run key interval tests one after another
runKeyIntervalTests(); runKeyIntervalTests();

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
// https://github.com/joyent/node/issues/4948 // https://github.com/joyent/node/issues/4948
const common = require('../common'); require('../common');
const http = require('http'); const http = require('http');
let reqCount = 0; let reqCount = 0;
@ -22,10 +22,10 @@ const server = http.createServer(function(serverReq, serverRes) {
serverRes.end(); serverRes.end();
// required for test to fail // required for test to fail
res.on('data', common.noop); res.on('data', () => {});
}); });
r.on('error', common.noop); r.on('error', () => {});
r.end(); r.end();
serverRes.write('some data'); serverRes.write('some data');

View File

@ -1,11 +1,11 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const agent = require('http').globalAgent; const agent = require('http').globalAgent;
// small stub just so we can call addRequest directly // small stub just so we can call addRequest directly
const req = { const req = {
getHeader: common.noop getHeader: () => {}
}; };
agent.maxSockets = 0; agent.maxSockets = 0;

View File

@ -19,7 +19,7 @@ assert.strictEqual(got, expected);
function initRepl() { function initRepl() {
const input = new stream(); const input = new stream();
input.write = input.pause = input.resume = common.noop; input.write = input.pause = input.resume = () => {};
input.readable = true; input.readable = true;
const output = new stream(); const output = new stream();

View File

@ -19,7 +19,7 @@ const Duplex = require('stream').Duplex;
// and mode 600. // and mode 600.
const stream = new Duplex(); const stream = new Duplex();
stream.pause = stream.resume = common.noop; stream.pause = stream.resume = () => {};
// ends immediately // ends immediately
stream._read = function() { stream._read = function() {
this.push(null); this.push(null);

View File

@ -52,7 +52,7 @@ function testAutoMode() {
function initRepl(mode) { function initRepl(mode) {
const input = new Stream(); const input = new Stream();
input.write = input.pause = input.resume = common.noop; input.write = input.pause = input.resume = () => {};
input.readable = true; input.readable = true;
const output = new Stream(); const output = new Stream();

View File

@ -98,7 +98,7 @@ putIn.write = function(data) {
// make sure I get a failed to load message and not some crazy error // make sure I get a failed to load message and not some crazy error
assert.strictEqual(data, `Failed to load:${loadFile}\n`); assert.strictEqual(data, `Failed to load:${loadFile}\n`);
// eat me to avoid work // eat me to avoid work
putIn.write = common.noop; putIn.write = () => {};
}; };
putIn.run([`.load ${loadFile}`]); putIn.run([`.load ${loadFile}`]);
@ -106,7 +106,7 @@ putIn.run([`.load ${loadFile}`]);
loadFile = common.tmpDir; loadFile = common.tmpDir;
putIn.write = function(data) { putIn.write = function(data) {
assert.strictEqual(data, `Failed to load:${loadFile} is not a valid file\n`); assert.strictEqual(data, `Failed to load:${loadFile} is not a valid file\n`);
putIn.write = common.noop; putIn.write = () => {};
}; };
putIn.run([`.load ${loadFile}`]); putIn.run([`.load ${loadFile}`]);
@ -122,7 +122,7 @@ putIn.write = function(data) {
// make sure I get a failed to save message and not some other error // make sure I get a failed to save message and not some other error
assert.strictEqual(data, `Failed to save:${invalidFileName}\n`); assert.strictEqual(data, `Failed to save:${invalidFileName}\n`);
// reset to no-op // reset to no-op
putIn.write = common.noop; putIn.write = () => {};
}; };
// save it to a file // save it to a file

View File

@ -4,7 +4,7 @@ const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const repl = require('repl'); const repl = require('repl');
common.ArrayStream.prototype.write = common.noop; common.ArrayStream.prototype.write = () => {};
const putIn = new common.ArrayStream(); const putIn = new common.ArrayStream();
const testMe = repl.start('', putIn); const testMe = repl.start('', putIn);

View File

@ -1,11 +1,11 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const stream = require('stream'); const stream = require('stream');
const assert = require('assert'); const assert = require('assert');
const readable = new stream.Readable({ const readable = new stream.Readable({
read: common.noop, read: () => {},
encoding: 'utf16le', encoding: 'utf16le',
objectMode: true objectMode: true
}); });

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const Duplex = require('stream').Duplex; const Duplex = require('stream').Duplex;
@ -38,7 +38,7 @@ stream._write = (obj, _, cb) => {
cb(); cb();
}; };
stream._read = common.noop; stream._read = () => {};
stream.on('data', (obj) => { stream.on('data', (obj) => {
read = obj; read = obj;

View File

@ -15,7 +15,7 @@ const writer3 = new stream.Writable();
// See: https://github.com/nodejs/node/issues/5820 // See: https://github.com/nodejs/node/issues/5820
const buffer = Buffer.allocUnsafe(560000); const buffer = Buffer.allocUnsafe(560000);
reader._read = common.noop; reader._read = () => {};
writer1._write = common.mustCall(function(chunk, encoding, cb) { writer1._write = common.mustCall(function(chunk, encoding, cb) {
this.emit('chunk-received'); this.emit('chunk-received');

View File

@ -11,7 +11,7 @@ const writer2 = new stream.Writable();
// See: https://github.com/nodejs/node/issues/2323 // See: https://github.com/nodejs/node/issues/2323
const buffer = Buffer.allocUnsafe(560000); const buffer = Buffer.allocUnsafe(560000);
reader._read = common.noop; reader._read = () => {};
writer1._write = common.mustCall(function(chunk, encoding, cb) { writer1._write = common.mustCall(function(chunk, encoding, cb) {
this.emit('chunk-received'); this.emit('chunk-received');

View File

@ -101,10 +101,10 @@ const Stream = require('stream').Stream;
}); });
w.on('error', common.mustCall()); w.on('error', common.mustCall());
w._write = common.noop; w._write = () => {};
r.pipe(w); r.pipe(w);
// Removing some OTHER random listener should not do anything // Removing some OTHER random listener should not do anything
w.removeListener('error', common.noop); w.removeListener('error', () => {});
removed = true; removed = true;
} }

View File

@ -4,7 +4,7 @@ const stream = require('stream');
const assert = require('assert'); const assert = require('assert');
const readable = new stream.Readable({ const readable = new stream.Readable({
read: common.noop read: () => {}
}); });
const writables = []; const writables = [];

View File

@ -4,9 +4,9 @@ const assert = require('assert');
const { Readable, Writable } = require('stream'); const { Readable, Writable } = require('stream');
const source = Readable({read: common.noop}); const source = Readable({read: () => {}});
const dest1 = Writable({write: common.noop}); const dest1 = Writable({write: () => {}});
const dest2 = Writable({write: common.noop}); const dest2 = Writable({write: () => {}});
source.pipe(dest1); source.pipe(dest1);
source.pipe(dest2); source.pipe(dest2);

View File

@ -4,7 +4,7 @@ const assert = require('assert');
const Readable = require('stream').Readable; const Readable = require('stream').Readable;
const readable = new Readable({ const readable = new Readable({
read: common.noop read: () => {}
}); });
// Initialized to false. // Initialized to false.
@ -37,7 +37,7 @@ process.nextTick(common.mustCall(() => {
})); }));
const noRead = new Readable({ const noRead = new Readable({
read: common.noop read: () => {}
}); });
noRead.on('readable', common.mustCall(() => { noRead.on('readable', common.mustCall(() => {
@ -52,7 +52,7 @@ noRead.push('foo');
noRead.push(null); noRead.push(null);
const flowing = new Readable({ const flowing = new Readable({
read: common.noop read: () => {}
}); });
flowing.on('data', common.mustCall(() => { flowing.on('data', common.mustCall(() => {

View File

@ -1,11 +1,11 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const stream = require('stream'); const stream = require('stream');
const assert = require('assert'); const assert = require('assert');
const readable = new stream.Readable({ const readable = new stream.Readable({
read: common.noop read: () => {}
}); });
const errMessage = /Invalid non-string\/buffer chunk/; const errMessage = /Invalid non-string\/buffer chunk/;

View File

@ -4,7 +4,7 @@ const assert = require('assert');
const Readable = require('stream').Readable; const Readable = require('stream').Readable;
const readable = new Readable({ const readable = new Readable({
read: common.noop read: () => {}
}); });
// Initialized to false. // Initialized to false.
@ -28,7 +28,7 @@ readable.on('end', common.mustCall(() => {
})); }));
const asyncReadable = new Readable({ const asyncReadable = new Readable({
read: common.noop read: () => {}
}); });
asyncReadable.on('readable', common.mustCall(() => { asyncReadable.on('readable', common.mustCall(() => {
@ -51,7 +51,7 @@ process.nextTick(common.mustCall(() => {
})); }));
const flowing = new Readable({ const flowing = new Readable({
read: common.noop read: () => {}
}); });
// Notice this must be above the on('data') call. // Notice this must be above the on('data') call.
@ -69,7 +69,7 @@ flowing.on('data', common.mustCall(function(data) {
}, 3)); }, 3));
const slowProducer = new Readable({ const slowProducer = new Readable({
read: common.noop read: () => {}
}); });
slowProducer.on('readable', common.mustCall(() => { slowProducer.on('readable', common.mustCall(() => {

View File

@ -5,7 +5,7 @@ const assert = require('assert');
const stream = require('stream'); const stream = require('stream');
const r = new stream.Readable({ const r = new stream.Readable({
read: common.noop read: () => {}
}); });
// readableListening state should start in `false`. // readableListening state should start in `false`.
@ -19,7 +19,7 @@ r.on('readable', common.mustCall(() => {
r.push(Buffer.from('Testing readableListening state')); r.push(Buffer.from('Testing readableListening state'));
const r2 = new stream.Readable({ const r2 = new stream.Readable({
read: common.noop read: () => {}
}); });
// readableListening state should start in `false`. // readableListening state should start in `false`.

View File

@ -21,7 +21,7 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const util = require('util'); const util = require('util');
const stream = require('stream'); const stream = require('stream');
@ -50,7 +50,7 @@ Write.prototype._write = function(buffer, encoding, cb) {
const read = new Read(); const read = new Read();
const write = new Write(); const write = new Write();
write.once('error', common.noop); write.once('error', () => {});
write.once('alldone', function(err) { write.once('alldone', function(err) {
console.log('ok'); console.log('ok');
}); });

View File

@ -26,13 +26,13 @@ const Readable = require('_stream_readable');
const EE = require('events').EventEmitter; const EE = require('events').EventEmitter;
const oldStream = new EE(); const oldStream = new EE();
oldStream.pause = common.noop; oldStream.pause = () => {};
oldStream.resume = common.noop; oldStream.resume = () => {};
const newStream = new Readable().wrap(oldStream); const newStream = new Readable().wrap(oldStream);
newStream newStream
.on('readable', common.noop) .on('readable', () => {})
.on('end', common.mustCall()); .on('end', common.mustCall());
oldStream.emit('end'); oldStream.emit('end');

View File

@ -1,12 +1,12 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const Timer = process.binding('timer_wrap').Timer; const Timer = process.binding('timer_wrap').Timer;
Timer.now = function() { return ++Timer.now.ticks; }; Timer.now = function() { return ++Timer.now.ticks; };
Timer.now.ticks = 0; Timer.now.ticks = 0;
const t = setInterval(common.noop, 1); const t = setInterval(() => {}, 1);
const o = { _idleStart: 0, _idleTimeout: 1 }; const o = { _idleStart: 0, _idleTimeout: 1 };
t.unref.call(o); t.unref.call(o);

View File

@ -29,4 +29,4 @@ timers.enroll(foo, 50);
timers._unrefActive(foo); timers._unrefActive(foo);
// Keep the process open. // Keep the process open.
setTimeout(common.noop, 100); setTimeout(() => {}, 100);

View File

@ -21,7 +21,7 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
let interval_fired = false; let interval_fired = false;
@ -35,11 +35,11 @@ const LONG_TIME = 10 * 1000;
const SHORT_TIME = 100; const SHORT_TIME = 100;
assert.doesNotThrow(function() { assert.doesNotThrow(function() {
setTimeout(common.noop, 10).unref().ref().unref(); setTimeout(() => {}, 10).unref().ref().unref();
}, 'ref and unref are chainable'); }, 'ref and unref are chainable');
assert.doesNotThrow(function() { assert.doesNotThrow(function() {
setInterval(common.noop, 10).unref().ref().unref(); setInterval(() => {}, 10).unref().ref().unref();
}, 'ref and unref are chainable'); }, 'ref and unref are chainable');
setInterval(function() { setInterval(function() {
@ -78,7 +78,7 @@ setInterval(function() {
// Should not assert on args.Holder()->InternalFieldCount() > 0. See #4261. // Should not assert on args.Holder()->InternalFieldCount() > 0. See #4261.
{ {
const t = setInterval(common.noop, 1); const t = setInterval(() => {}, 1);
process.nextTick(t.unref.bind({})); process.nextTick(t.unref.bind({}));
process.nextTick(t.unref.bind(t)); process.nextTick(t.unref.bind(t));
} }

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
let once = 0; let once = 0;
@ -9,7 +9,7 @@ process.on('beforeExit', () => {
if (once > 1) if (once > 1)
throw new RangeError('beforeExit should only have been called once!'); throw new RangeError('beforeExit should only have been called once!');
setTimeout(common.noop, 1).unref(); setTimeout(() => {}, 1).unref();
once++; once++;
}); });

View File

@ -26,7 +26,7 @@ const assert = require('assert');
// https://github.com/joyent/node/issues/2079 - zero timeout drops extra args // https://github.com/joyent/node/issues/2079 - zero timeout drops extra args
{ {
setTimeout(common.mustCall(f), 0, 'foo', 'bar', 'baz'); setTimeout(common.mustCall(f), 0, 'foo', 'bar', 'baz');
setTimeout(common.noop, 0); setTimeout(() => {}, 0);
function f(a, b, c) { function f(a, b, c) {
assert.strictEqual(a, 'foo'); assert.strictEqual(a, 'foo');

View File

@ -785,9 +785,9 @@ if (typeof Symbol !== 'undefined') {
const rejected = Promise.reject(3); const rejected = Promise.reject(3);
assert.strictEqual(util.inspect(rejected), 'Promise { <rejected> 3 }'); assert.strictEqual(util.inspect(rejected), 'Promise { <rejected> 3 }');
// squelch UnhandledPromiseRejection // squelch UnhandledPromiseRejection
rejected.catch(common.noop); rejected.catch(() => {});
const pending = new Promise(common.noop); const pending = new Promise(() => {});
assert.strictEqual(util.inspect(pending), 'Promise { <pending> }'); assert.strictEqual(util.inspect(pending), 'Promise { <pending> }');
const promiseWithProperty = Promise.resolve('foo'); const promiseWithProperty = Promise.resolve('foo');
@ -885,7 +885,7 @@ if (typeof Symbol !== 'undefined') {
'SetSubclass { 1, 2, 3 }'); 'SetSubclass { 1, 2, 3 }');
assert.strictEqual(util.inspect(new MapSubclass([['foo', 42]])), assert.strictEqual(util.inspect(new MapSubclass([['foo', 42]])),
'MapSubclass { \'foo\' => 42 }'); 'MapSubclass { \'foo\' => 42 }');
assert.strictEqual(util.inspect(new PromiseSubclass(common.noop)), assert.strictEqual(util.inspect(new PromiseSubclass(() => {})),
'PromiseSubclass { <pending> }'); 'PromiseSubclass { <pending> }');
} }

View File

@ -44,7 +44,7 @@ if (process.argv[2] === 'child') {
assert.strictEqual(onceHandlerCalled, 0); assert.strictEqual(onceHandlerCalled, 0);
// Keep the process alive for a while so that the second SIGINT can be caught. // Keep the process alive for a while so that the second SIGINT can be caught.
const timeout = setTimeout(common.noop, 1000); const timeout = setTimeout(() => {}, 1000);
let afterHandlerCalled = 0; let afterHandlerCalled = 0;

View File

@ -23,7 +23,7 @@ const failureTests = tests.filter((test) => test.failure).concat([
{ input: null }, { input: null },
{ input: new Date() }, { input: new Date() },
{ input: new RegExp() }, { input: new RegExp() },
{ input: common.noop } { input: () => {} }
]); ]);
const expectedError = common.expectsError( const expectedError = common.expectsError(

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const common = require('../common'); require('../common');
const { TTY, isTTY } = process.binding('tty_wrap'); const { TTY, isTTY } = process.binding('tty_wrap');
const strictEqual = require('assert').strictEqual; const strictEqual = require('assert').strictEqual;
@ -9,7 +9,7 @@ strictEqual(isTTY(0), true, 'fd 0 is not a TTY');
const handle = new TTY(0); const handle = new TTY(0);
handle.readStart(); handle.readStart();
handle.onread = common.noop; handle.onread = () => {};
function isHandleActive(handle) { function isHandleActive(handle) {
return process._getActiveHandles().some((active) => active === handle); return process._getActiveHandles().some((active) => active === handle);