test: add common.noop, default for common.mustCall()

Export a new common.noop no-operation function for general use.
Allow using common.mustCall() without a fn argument to simplify
test cases.

Replace various non-op functions throughout tests with common.noop

PR-URL: https://github.com/nodejs/node/pull/12027
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
James M Snell 2017-03-24 09:46:44 -07:00
parent d13bd4acc0
commit 4f2e372716
184 changed files with 492 additions and 490 deletions

View File

@ -324,7 +324,7 @@ Gets IP of localhost
Array of IPV6 hosts. Array of IPV6 hosts.
### mustCall(fn[, expected]) ### mustCall([fn][, expected])
* fn [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) * fn [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
* expected [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1 * expected [&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)
@ -333,6 +333,8 @@ 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.
### nodeProcessAborted(exitCode, signal) ### nodeProcessAborted(exitCode, signal)
* `exitCode` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) * `exitCode` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
* `signal` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) * `signal` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
@ -340,6 +342,18 @@ fail.
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,
```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

@ -6,5 +6,5 @@ const binding = require(`./build/${common.buildType}/binding`);
binding(5, common.mustCall(function(err, val) { binding(5, common.mustCall(function(err, val) {
assert.strictEqual(err, null); assert.strictEqual(err, null);
assert.strictEqual(val, 10); assert.strictEqual(val, 10);
process.nextTick(common.mustCall(function() {})); process.nextTick(common.mustCall());
})); }));

View File

@ -5,7 +5,7 @@ const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`); const binding = require(`./build/${common.buildType}/binding`);
// Create an AsyncWrap object. // Create an AsyncWrap object.
const timer = setTimeout(function() {}, 1); const timer = setTimeout(common.noop, 1);
timer.unref(); timer.unref();
// Stress-test the heap profiler. // Stress-test the heap profiler.

View File

@ -35,6 +35,9 @@ const execSync = require('child_process').execSync;
const testRoot = process.env.NODE_TEST_DIR ? const testRoot = process.env.NODE_TEST_DIR ?
fs.realpathSync(process.env.NODE_TEST_DIR) : __dirname; fs.realpathSync(process.env.NODE_TEST_DIR) : __dirname;
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.
@ -429,6 +432,13 @@ function runCallChecks(exitCode) {
exports.mustCall = function(fn, expected) { exports.mustCall = function(fn, expected) {
if (typeof fn === 'number') {
expected = fn;
fn = noop;
} else if (fn === undefined) {
fn = noop;
}
if (expected === undefined) if (expected === undefined)
expected = 1; expected = 1;
else if (typeof expected !== 'number') else if (typeof expected !== 'number')
@ -525,9 +535,9 @@ util.inherits(ArrayStream, stream.Stream);
exports.ArrayStream = ArrayStream; exports.ArrayStream = ArrayStream;
ArrayStream.prototype.readable = true; ArrayStream.prototype.readable = true;
ArrayStream.prototype.writable = true; ArrayStream.prototype.writable = true;
ArrayStream.prototype.pause = function() {}; ArrayStream.prototype.pause = noop;
ArrayStream.prototype.resume = function() {}; ArrayStream.prototype.resume = noop;
ArrayStream.prototype.write = function() {}; ArrayStream.prototype.write = noop;
// Returns true if the exit code "exitCode" and/or signal name "signal" // 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, // represent the exit code and/or signal name of a node process that aborted,

View File

@ -150,7 +150,7 @@ addTest(function(client, done) {
let connectCount = 0; let connectCount = 0;
const script = 'setTimeout(function() { console.log("blah"); });' + const script = 'setTimeout(function() { console.log("blah"); });' +
'setInterval(function() {}, 1000000);'; 'setInterval(common.noop, 1000000);';
let nodeProcess; let nodeProcess;
@ -193,7 +193,7 @@ function doTest(cb, done) {
console.error('>>> connecting...'); console.error('>>> connecting...');
c.connect(debug.port); c.connect(debug.port);
c.on('break', function() { c.on('break', function() {
c.reqContinue(function() {}); c.reqContinue(common.noop);
}); });
c.on('ready', function() { c.on('ready', function() {
connectCount++; connectCount++;

View File

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

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const a = require('assert'); const a = require('assert');
@ -505,22 +505,22 @@ a.throws(makeBlock(a.deepEqual, args, []));
// check messages from assert.throws() // check messages from assert.throws()
{ {
assert.throws( assert.throws(
() => { a.throws(() => {}); }, () => { a.throws(common.noop); },
/^AssertionError: Missing expected exception\.$/ /^AssertionError: Missing expected exception\.$/
); );
assert.throws( assert.throws(
() => { a.throws(() => {}, TypeError); }, () => { a.throws(common.noop, TypeError); },
/^AssertionError: Missing expected exception \(TypeError\)\.$/ /^AssertionError: Missing expected exception \(TypeError\)\.$/
); );
assert.throws( assert.throws(
() => { a.throws(() => {}, 'fhqwhgads'); }, () => { a.throws(common.noop, 'fhqwhgads'); },
/^AssertionError: Missing expected exception: fhqwhgads$/ /^AssertionError: Missing expected exception: fhqwhgads$/
); );
assert.throws( assert.throws(
() => { a.throws(() => {}, TypeError, 'fhqwhgads'); }, () => { a.throws(common.noop, TypeError, 'fhqwhgads'); },
/^AssertionError: Missing expected exception \(TypeError\): fhqwhgads$/ /^AssertionError: Missing expected exception \(TypeError\): fhqwhgads$/
); );
} }

View File

@ -39,35 +39,33 @@ function init(id, provider) {
keyList = keyList.filter((e) => e !== pkeys[provider]); keyList = keyList.filter((e) => e !== pkeys[provider]);
} }
function noop() { }
async_wrap.setupHooks({ init }); async_wrap.setupHooks({ init });
async_wrap.enable(); async_wrap.enable();
setTimeout(function() { }, 1); setTimeout(common.noop, 1);
fs.stat(__filename, noop); fs.stat(__filename, common.noop);
if (!common.isAix) { if (!common.isAix) {
// fs-watch currently needs special configuration on AIX and we // fs-watch currently needs special configuration on AIX and we
// want to improve under https://github.com/nodejs/node/issues/5085. // want to improve under https://github.com/nodejs/node/issues/5085.
// strip out fs watch related parts for now // strip out fs watch related parts for now
fs.watchFile(__filename, noop); fs.watchFile(__filename, common.noop);
fs.unwatchFile(__filename); fs.unwatchFile(__filename);
fs.watch(__filename).close(); fs.watch(__filename).close();
} }
dns.lookup('localhost', noop); dns.lookup('localhost', common.noop);
dns.lookupService('::', 0, noop); dns.lookupService('::', 0, common.noop);
dns.resolve('localhost', noop); dns.resolve('localhost', common.noop);
new StreamWrap(new net.Socket()); new StreamWrap(new net.Socket());
new (process.binding('tty_wrap').TTY)(); new (process.binding('tty_wrap').TTY)();
crypto.randomBytes(1, noop); crypto.randomBytes(1, common.noop);
common.refreshTmpDir(); common.refreshTmpDir();
@ -75,14 +73,14 @@ net.createServer(function(c) {
c.end(); c.end();
this.close(); this.close();
}).listen(common.PIPE, function() { }).listen(common.PIPE, function() {
net.connect(common.PIPE, noop); net.connect(common.PIPE, common.noop);
}); });
net.createServer(function(c) { net.createServer(function(c) {
c.end(); c.end();
this.close(checkTLS); this.close(checkTLS);
}).listen(0, function() { }).listen(0, function() {
net.connect(this.address().port, noop); net.connect(this.address().port, common.noop);
}); });
dgram.createSocket('udp4').bind(0, function() { dgram.createSocket('udp4').bind(0, function() {
@ -99,7 +97,7 @@ function checkTLS() {
key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'), key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem') cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem')
}; };
const server = tls.createServer(options, noop) const server = tls.createServer(options, common.noop)
.listen(0, function() { .listen(0, function() {
const connectOpts = { rejectUnauthorized: false }; const connectOpts = { rejectUnauthorized: false };
tls.connect(this.address().port, connectOpts, function() { tls.connect(this.address().port, connectOpts, function() {

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const net = require('net'); const net = require('net');
const async_wrap = process.binding('async_wrap'); const async_wrap = process.binding('async_wrap');
@ -28,8 +28,6 @@ function init(uid, type, parentUid, parentHandle) {
} }
} }
function noop() { }
async_wrap.setupHooks({ init }); async_wrap.setupHooks({ init });
async_wrap.enable(); async_wrap.enable();
@ -41,7 +39,7 @@ const server = net.createServer(function(c) {
this.close(); this.close();
}); });
}).listen(0, function() { }).listen(0, function() {
net.connect(this.address().port, noop); net.connect(this.address().port, common.noop);
}); });
async_wrap.disable(); async_wrap.disable();

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const net = require('net'); const net = require('net');
const async_wrap = process.binding('async_wrap'); const async_wrap = process.binding('async_wrap');
@ -28,8 +28,6 @@ function init(uid, type, parentUid, parentHandle) {
} }
} }
function noop() { }
async_wrap.setupHooks({ init }); async_wrap.setupHooks({ init });
async_wrap.enable(); async_wrap.enable();
@ -41,7 +39,7 @@ const server = net.createServer(function(c) {
this.close(); this.close();
}); });
}).listen(0, function() { }).listen(0, function() {
net.connect(this.address().port, noop); net.connect(this.address().port, common.noop);
}); });

View File

@ -43,7 +43,7 @@ if (typeof process.argv[2] === 'string') {
d.on('error', common.mustNotCall()); d.on('error', common.mustNotCall());
d.run(() => { d.run(() => {
// Using randomBytes because timers are not yet supported. // Using randomBytes because timers are not yet supported.
crypto.randomBytes(0, () => { }); crypto.randomBytes(0, common.noop);
}); });
} else { } else {

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const async_wrap = process.binding('async_wrap'); const async_wrap = process.binding('async_wrap');
@ -17,9 +17,9 @@ assert.throws(function() {
}, /init callback is not assigned to a function/); }, /init callback is not assigned to a function/);
// Should not throw // Should not throw
async_wrap.setupHooks({ init: () => {} }); async_wrap.setupHooks({ init: common.noop });
async_wrap.enable(); async_wrap.enable();
assert.throws(function() { assert.throws(function() {
async_wrap.setupHooks(() => {}); async_wrap.setupHooks(common.noop);
}, /hooks should not be set while also enabled/); }, /hooks should not be set while also enabled/);

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const fs = require('fs'); const fs = require('fs');
const assert = require('assert'); const assert = require('assert');
const async_wrap = process.binding('async_wrap'); const async_wrap = process.binding('async_wrap');
@ -8,7 +8,7 @@ const async_wrap = process.binding('async_wrap');
// Give the event loop time to clear out the final uv_close(). // Give the event loop time to clear out the final uv_close().
let si_cntr = 3; let si_cntr = 3;
process.on('beforeExit', () => { process.on('beforeExit', () => {
if (--si_cntr > 0) setImmediate(() => {}); if (--si_cntr > 0) setImmediate(common.noop);
}); });
const storage = new Map(); const storage = new Map();

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const Buffer = require('buffer').Buffer; const Buffer = require('buffer').Buffer;
@ -278,7 +278,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(() => {}); b.includes(common.noop);
}, 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.platformTimeout(100)); setTimeout(common.noop, common.platformTimeout(100));
return; return;
} }

View File

@ -78,7 +78,7 @@ if (process.argv[2] === 'child') {
})); }));
// the process should also self terminate without using signals // the process should also self terminate without using signals
child.on('exit', common.mustCall(function() {})); child.on('exit', common.mustCall());
// when child is listening // when child is listening
child.on('message', function(obj) { child.on('message', function(obj) {

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const fork = require('child_process').fork; const fork = require('child_process').fork;
if (process.argv[2] === 'child') { if (process.argv[2] === 'child') {
@ -29,7 +29,7 @@ if (process.argv[2] === 'child') {
setTimeout(function() { setTimeout(function() {
console.log('child -> will this keep it alive?'); console.log('child -> will this keep it alive?');
process.on('message', function() { }); process.on('message', common.noop);
}, 400); }, 400);
} else { } else {

View File

@ -25,9 +25,9 @@ const assert = require('assert');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
const cat = spawn(common.isWindows ? 'cmd' : 'cat'); const cat = spawn(common.isWindows ? 'cmd' : 'cat');
cat.stdout.on('end', common.mustCall(function() {})); cat.stdout.on('end', common.mustCall());
cat.stderr.on('data', common.mustNotCall()); cat.stderr.on('data', common.mustNotCall());
cat.stderr.on('end', common.mustCall(function() {})); cat.stderr.on('end', common.mustCall());
cat.on('exit', common.mustCall(function(code, signal) { cat.on('exit', common.mustCall(function(code, signal) {
assert.strictEqual(code, null); assert.strictEqual(code, null);

View File

@ -1,10 +1,8 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
function noop() {}
function fail(proc, args) { function fail(proc, args) {
assert.throws(() => { assert.throws(() => {
proc.send.apply(proc, args); proc.send.apply(proc, args);
@ -22,4 +20,4 @@ fail(target, ['msg', null, 'foo']);
fail(target, ['msg', null, 0]); fail(target, ['msg', null, 0]);
fail(target, ['msg', null, NaN]); fail(target, ['msg', null, NaN]);
fail(target, ['msg', null, 1]); fail(target, ['msg', null, 1]);
fail(target, ['msg', null, null, noop]); fail(target, ['msg', null, null, common.noop]);

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); 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(() => {}, 1000); setInterval(common.noop, 1000);
} else { } else {
const { SIGKILL } = process.binding('constants').os.signals; const { SIGKILL } = process.binding('constants').os.signals;

View File

@ -2,7 +2,6 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const spawnSync = require('child_process').spawnSync; const spawnSync = require('child_process').spawnSync;
const noop = function() {};
function pass(option, value) { function pass(option, value) {
// Run the command with the specified option. Since it's not a real command, // Run the command with the specified option. Since it's not a real command,
@ -31,7 +30,7 @@ function fail(option, value, message) {
fail('cwd', false, err); fail('cwd', false, err);
fail('cwd', [], err); fail('cwd', [], err);
fail('cwd', {}, err); fail('cwd', {}, err);
fail('cwd', noop, err); fail('cwd', common.noop, err);
} }
{ {
@ -47,7 +46,7 @@ function fail(option, value, message) {
fail('detached', __dirname, err); fail('detached', __dirname, err);
fail('detached', [], err); fail('detached', [], err);
fail('detached', {}, err); fail('detached', {}, err);
fail('detached', noop, err); fail('detached', common.noop, err);
} }
if (!common.isWindows) { if (!common.isWindows) {
@ -64,7 +63,7 @@ if (!common.isWindows) {
fail('uid', false, err); fail('uid', false, err);
fail('uid', [], err); fail('uid', [], err);
fail('uid', {}, err); fail('uid', {}, err);
fail('uid', noop, err); fail('uid', common.noop, err);
fail('uid', NaN, err); fail('uid', NaN, err);
fail('uid', Infinity, err); fail('uid', Infinity, err);
fail('uid', 3.1, err); fail('uid', 3.1, err);
@ -85,7 +84,7 @@ if (!common.isWindows) {
fail('gid', false, err); fail('gid', false, err);
fail('gid', [], err); fail('gid', [], err);
fail('gid', {}, err); fail('gid', {}, err);
fail('gid', noop, err); fail('gid', common.noop, err);
fail('gid', NaN, err); fail('gid', NaN, err);
fail('gid', Infinity, err); fail('gid', Infinity, err);
fail('gid', 3.1, err); fail('gid', 3.1, err);
@ -105,7 +104,7 @@ if (!common.isWindows) {
fail('shell', 1, err); fail('shell', 1, err);
fail('shell', [], err); fail('shell', [], err);
fail('shell', {}, err); fail('shell', {}, err);
fail('shell', noop, err); fail('shell', common.noop, err);
} }
{ {
@ -121,7 +120,7 @@ if (!common.isWindows) {
fail('argv0', false, err); fail('argv0', false, err);
fail('argv0', [], err); fail('argv0', [], err);
fail('argv0', {}, err); fail('argv0', {}, err);
fail('argv0', noop, err); fail('argv0', common.noop, err);
} }
{ {
@ -137,7 +136,7 @@ if (!common.isWindows) {
fail('windowsVerbatimArguments', __dirname, err); fail('windowsVerbatimArguments', __dirname, err);
fail('windowsVerbatimArguments', [], err); fail('windowsVerbatimArguments', [], err);
fail('windowsVerbatimArguments', {}, err); fail('windowsVerbatimArguments', {}, err);
fail('windowsVerbatimArguments', noop, err); fail('windowsVerbatimArguments', common.noop, err);
} }
{ {
@ -154,7 +153,7 @@ if (!common.isWindows) {
fail('timeout', __dirname, err); fail('timeout', __dirname, err);
fail('timeout', [], err); fail('timeout', [], err);
fail('timeout', {}, err); fail('timeout', {}, err);
fail('timeout', noop, err); fail('timeout', common.noop, err);
fail('timeout', NaN, err); fail('timeout', NaN, err);
fail('timeout', Infinity, err); fail('timeout', Infinity, err);
fail('timeout', 3.1, err); fail('timeout', 3.1, err);
@ -179,7 +178,7 @@ if (!common.isWindows) {
fail('maxBuffer', __dirname, err); fail('maxBuffer', __dirname, err);
fail('maxBuffer', [], err); fail('maxBuffer', [], err);
fail('maxBuffer', {}, err); fail('maxBuffer', {}, err);
fail('maxBuffer', noop, err); fail('maxBuffer', common.noop, err);
} }
{ {
@ -198,5 +197,5 @@ if (!common.isWindows) {
fail('killSignal', false, typeErr); fail('killSignal', false, typeErr);
fail('killSignal', [], typeErr); fail('killSignal', [], typeErr);
fail('killSignal', {}, typeErr); fail('killSignal', {}, typeErr);
fail('killSignal', noop, typeErr); fail('killSignal', common.noop, typeErr);
} }

View File

@ -43,11 +43,11 @@ cat.stdout.on('data', function(chunk) {
response += chunk; response += chunk;
}); });
cat.stdout.on('end', common.mustCall(function() {})); cat.stdout.on('end', common.mustCall());
cat.stderr.on('data', common.mustNotCall()); cat.stderr.on('data', common.mustNotCall());
cat.stderr.on('end', common.mustCall(function() {})); cat.stderr.on('end', common.mustCall());
cat.on('exit', common.mustCall(function(status) { cat.on('exit', common.mustCall(function(status) {
assert.strictEqual(0, status); assert.strictEqual(0, status);

View File

@ -103,7 +103,7 @@ if (cluster.isWorker) {
})); }));
//Kill process when worker is killed //Kill process when worker is killed
cluster.on('exit', common.mustCall(() => {})); cluster.on('exit', common.mustCall());
//Create worker //Create worker
const worker = cluster.fork(); const worker = cluster.fork();

View File

@ -6,19 +6,17 @@ const common = require('../common');
const net = require('net'); const net = require('net');
const cluster = require('cluster'); const cluster = require('cluster');
const noop = () => {};
cluster.schedulingPolicy = cluster.SCHED_NONE; cluster.schedulingPolicy = cluster.SCHED_NONE;
if (cluster.isMaster) { if (cluster.isMaster) {
const worker = cluster.fork(); const worker = cluster.fork();
// This is the important part of the test: Confirm that `disconnect` fires. // This is the important part of the test: Confirm that `disconnect` fires.
worker.on('disconnect', common.mustCall(noop)); worker.on('disconnect', common.mustCall());
// These are just some extra stuff we're checking for good measure... // These are just some extra stuff we're checking for good measure...
worker.on('exit', common.mustCall(noop)); worker.on('exit', common.mustCall());
cluster.on('exit', common.mustCall(noop)); cluster.on('exit', common.mustCall());
cluster.disconnect(); cluster.disconnect();
return; return;

View File

@ -35,10 +35,10 @@ if (cluster.isMaster) {
const worker = cluster.fork(); const worker = cluster.fork();
// makes sure master is able to fork the worker // makes sure master is able to fork the worker
cluster.on('fork', common.mustCall(function() {})); cluster.on('fork', common.mustCall());
// makes sure the worker is ready // makes sure the worker is ready
worker.on('online', common.mustCall(function() {})); worker.on('online', common.mustCall());
worker.on('message', common.mustCall(function(err) { worker.on('message', common.mustCall(function(err) {
// disconnect first, so that we will not leave zombies // disconnect first, so that we will not leave zombies

View File

@ -38,7 +38,7 @@ if (cluster.isMaster) {
worker.on('message', common.mustCall((msg) => { worker.on('message', common.mustCall((msg) => {
assert.strictEqual(msg, 'DONE'); assert.strictEqual(msg, 'DONE');
})); }));
worker.on('exit', common.mustCall(() => {})); worker.on('exit', common.mustCall());
return; return;
} }

View File

@ -29,10 +29,10 @@ const domain = require('domain');
if (cluster.isWorker) { if (cluster.isWorker) {
const d = domain.create(); const d = domain.create();
d.run(function() { }); d.run(common.noop);
const http = require('http'); const http = require('http');
http.Server(function() { }).listen(common.PORT, '127.0.0.1'); http.Server(common.noop).listen(common.PORT, '127.0.0.1');
} else if (cluster.isMaster) { } else if (cluster.isMaster) {

View File

@ -43,5 +43,5 @@ function emitAndCatch2(next) {
} }
emitAndCatch(common.mustCall(function() { emitAndCatch(common.mustCall(function() {
emitAndCatch2(common.mustCall(function() {})); emitAndCatch2(common.mustCall());
})); }));

View File

@ -38,8 +38,8 @@ if (cluster.isMaster) {
worker2 = cluster.fork(); worker2 = cluster.fork();
[worker1, worker2].forEach(function(worker) { [worker1, worker2].forEach(function(worker) {
worker.on('disconnect', common.mustCall(function() {})); worker.on('disconnect', common.mustCall());
worker.on('exit', common.mustCall(function() {})); worker.on('exit', common.mustCall());
}); });
} else { } else {
if (cluster.worker.id === 1) { if (cluster.worker.id === 1) {

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', function discard() {}); socket.on('data', common.noop);
}).listen(common.PORT, common.localhostIPv4); }).listen(common.PORT, 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(function() {}, 9999); const keepOpen = setInterval(common.noop, 9999);
// Check worker events and properties // Check worker events and properties
process.once('disconnect', function() { process.once('disconnect', function() {

View File

@ -43,7 +43,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 = () => {}; out.write = common.noop;
err.write = undefined; err.write = undefined;
new Console(out, err); new Console(out, err);
}, /^TypeError: Console expects writable stream instances$/); }, /^TypeError: Console expects writable stream instances$/);

View File

@ -98,7 +98,7 @@ assert.doesNotThrow(() => {
}); });
assert.throws(() => { assert.throws(() => {
crypto.pbkdf2('password', 'salt', 8, 8, function() {}); crypto.pbkdf2('password', 'salt', 8, 8, common.noop);
}, /^TypeError: The "digest" argument is required and must not be undefined$/); }, /^TypeError: The "digest" argument is required and must not be undefined$/);
assert.throws(() => { assert.throws(() => {

View File

@ -38,7 +38,7 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
[crypto.randomBytes, crypto.pseudoRandomBytes].forEach(function(f) { [crypto.randomBytes, crypto.pseudoRandomBytes].forEach(function(f) {
[-1, undefined, null, false, true, {}, []].forEach(function(value) { [-1, undefined, null, false, true, {}, []].forEach(function(value) {
assert.throws(function() { f(value); }, expectedErrorRegexp); assert.throws(function() { f(value); }, expectedErrorRegexp);
assert.throws(function() { f(value, function() {}); }, expectedErrorRegexp); assert.throws(function() { f(value, common.noop); }, expectedErrorRegexp);
}); });
[0, 1, 2, 4, 16, 256, 1024].forEach(function(len) { [0, 1, 2, 4, 16, 256, 1024].forEach(function(len) {

View File

@ -3,7 +3,7 @@
const common = require('../common'); const common = require('../common');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
let run = () => {}; let run = common.noop;
function test(extraArgs, stdoutPattern) { function test(extraArgs, stdoutPattern) {
const next = run; const next = run;
run = () => { run = () => {

View File

@ -25,8 +25,6 @@ const assert = require('assert');
const cluster = require('cluster'); const cluster = require('cluster');
const dgram = require('dgram'); const dgram = require('dgram');
function noop() { }
if (cluster.isMaster) { if (cluster.isMaster) {
const worker1 = cluster.fork(); const worker1 = cluster.fork();
@ -51,8 +49,8 @@ if (cluster.isMaster) {
}); });
}); });
} else { } else {
const socket1 = dgram.createSocket('udp4', noop); const socket1 = dgram.createSocket('udp4', common.noop);
const socket2 = dgram.createSocket('udp4', noop); const socket2 = dgram.createSocket('udp4', common.noop);
socket1.on('error', (err) => { socket1.on('error', (err) => {
// no errors expected // no errors expected

View File

@ -11,4 +11,4 @@ socket.send(buf, 0, buf.length, common.PORT, 'localhost');
// if close callback is not function, ignore the argument. // if close callback is not function, ignore the argument.
socket.close('bad argument'); socket.close('bad argument');
socket.on('close', common.mustCall(function() {})); socket.on('close', common.mustCall());

View File

@ -33,8 +33,8 @@ let socket = dgram.createSocket('udp4');
const handle = socket._handle; const handle = socket._handle;
socket.send(buf, 0, buf.length, common.PORT, 'localhost'); socket.send(buf, 0, buf.length, common.PORT, 'localhost');
assert.strictEqual(socket.close(common.mustCall(function() {})), socket); assert.strictEqual(socket.close(common.mustCall()), socket);
socket.on('close', common.mustCall(function() {})); socket.on('close', common.mustCall());
socket = null; socket = null;
// Verify that accessing handle after closure doesn't throw // Verify that accessing handle after closure doesn't throw

View File

@ -30,12 +30,11 @@ const dgram = require('dgram');
const socket = dgram.createSocket('udp4'); const socket = dgram.createSocket('udp4');
const buf = Buffer.from([1, 2, 3, 4]); const buf = Buffer.from([1, 2, 3, 4]);
function ok() {} socket.send(buf, 0, 0, common.PORT, '127.0.0.1', common.noop); // useful? no
socket.send(buf, 0, 0, common.PORT, '127.0.0.1', ok); // useful? no socket.send(buf, 0, 4, common.PORT, '127.0.0.1', common.noop);
socket.send(buf, 0, 4, common.PORT, '127.0.0.1', ok); socket.send(buf, 1, 3, common.PORT, '127.0.0.1', common.noop);
socket.send(buf, 1, 3, common.PORT, '127.0.0.1', ok); socket.send(buf, 3, 1, common.PORT, '127.0.0.1', common.noop);
socket.send(buf, 3, 1, common.PORT, '127.0.0.1', ok);
// Since length of zero means nothing, don't error despite OOB. // Since length of zero means nothing, don't error despite OOB.
socket.send(buf, 4, 0, common.PORT, '127.0.0.1', ok); socket.send(buf, 4, 0, common.PORT, '127.0.0.1', common.noop);
socket.close(); socket.close();

View File

@ -43,6 +43,6 @@ client.bind(0, common.mustCall(function() {
const buf = Buffer.alloc(0); const buf = Buffer.alloc(0);
const interval = setInterval(function() { const interval = setInterval(function() {
client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(function() {})); client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall());
}, 10); }, 10);
})); }));

View File

@ -46,7 +46,7 @@ server.on('listening', common.mustCall(() => {
message_to_send.length, message_to_send.length,
port, port,
'localhost'); 'localhost');
client.on('close', common.mustCall(() => {})); client.on('close', common.mustCall());
})); }));
server.on('close', common.mustCall(() => {})); server.on('close', common.mustCall());
server.bind(0); server.bind(0);

View File

@ -24,7 +24,7 @@ assert.throws(() => {
hints: 100, hints: 100,
family: 0, family: 0,
all: false all: false
}, () => {}); }, common.noop);
}, /^TypeError: Invalid argument: hints must use valid flags$/); }, /^TypeError: Invalid argument: hints must use valid flags$/);
assert.throws(() => { assert.throws(() => {
@ -32,7 +32,7 @@ assert.throws(() => {
hints: 0, hints: 0,
family: 20, family: 20,
all: false all: false
}, () => {}); }, common.noop);
}, /^TypeError: Invalid argument: family must be 4 or 6$/); }, /^TypeError: Invalid argument: family must be 4 or 6$/);
assert.doesNotThrow(() => { assert.doesNotThrow(() => {

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const dns = require('dns'); const dns = require('dns');
@ -55,8 +55,6 @@ assert.doesNotThrow(() => {
dns.setServers(servers); dns.setServers(servers);
}); });
function noop() {}
const goog = [ const goog = [
'8.8.8.8', '8.8.8.8',
'8.8.4.4', '8.8.4.4',
@ -93,7 +91,7 @@ assert.doesNotThrow(() => dns.setServers([]));
assert.deepStrictEqual(dns.getServers(), []); assert.deepStrictEqual(dns.getServers(), []);
assert.throws(() => { assert.throws(() => {
dns.resolve('test.com', [], noop); dns.resolve('test.com', [], common.noop);
}, function(err) { }, function(err) {
return !(err instanceof TypeError); return !(err instanceof TypeError);
}, 'Unexpected error'); }, 'Unexpected error');
@ -102,25 +100,25 @@ assert.throws(() => {
const errorReg = const errorReg =
/^TypeError: Invalid arguments: hostname must be a string or falsey$/; /^TypeError: Invalid arguments: hostname must be a string or falsey$/;
assert.throws(() => dns.lookup({}, noop), errorReg); assert.throws(() => dns.lookup({}, common.noop), errorReg);
assert.throws(() => dns.lookup([], noop), errorReg); assert.throws(() => dns.lookup([], common.noop), errorReg);
assert.throws(() => dns.lookup(true, noop), errorReg); assert.throws(() => dns.lookup(true, common.noop), errorReg);
assert.throws(() => dns.lookup(1, noop), errorReg); assert.throws(() => dns.lookup(1, common.noop), errorReg);
assert.throws(() => dns.lookup(noop, noop), errorReg); assert.throws(() => dns.lookup(common.noop, common.noop), errorReg);
assert.doesNotThrow(() => dns.lookup('', noop)); assert.doesNotThrow(() => dns.lookup('', common.noop));
assert.doesNotThrow(() => dns.lookup(null, noop)); assert.doesNotThrow(() => dns.lookup(null, common.noop));
assert.doesNotThrow(() => dns.lookup(undefined, noop)); assert.doesNotThrow(() => dns.lookup(undefined, common.noop));
assert.doesNotThrow(() => dns.lookup(0, noop)); assert.doesNotThrow(() => dns.lookup(0, common.noop));
assert.doesNotThrow(() => dns.lookup(NaN, noop)); assert.doesNotThrow(() => dns.lookup(NaN, common.noop));
/* /*
* Make sure that dns.lookup throws if hints does not represent a valid flag. * Make sure that dns.lookup throws if hints does not represent a valid flag.
@ -133,7 +131,7 @@ assert.doesNotThrow(() => dns.lookup(NaN, noop));
*/ */
assert.throws(() => { assert.throws(() => {
dns.lookup('www.google.com', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 }, dns.lookup('www.google.com', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 },
noop); common.noop);
}, /^TypeError: Invalid argument: hints must use valid flags$/); }, /^TypeError: Invalid argument: hints must use valid flags$/);
assert.throws(() => dns.lookup('www.google.com'), assert.throws(() => dns.lookup('www.google.com'),
@ -142,49 +140,49 @@ assert.throws(() => dns.lookup('www.google.com'),
assert.throws(() => dns.lookup('www.google.com', 4), assert.throws(() => dns.lookup('www.google.com', 4),
/^TypeError: Invalid arguments: callback must be passed$/); /^TypeError: Invalid arguments: callback must be passed$/);
assert.doesNotThrow(() => dns.lookup('www.google.com', 6, noop)); assert.doesNotThrow(() => dns.lookup('www.google.com', 6, common.noop));
assert.doesNotThrow(() => dns.lookup('www.google.com', {}, noop)); assert.doesNotThrow(() => dns.lookup('www.google.com', {}, common.noop));
assert.doesNotThrow(() => dns.lookup('', {family: 4, hints: 0}, noop)); assert.doesNotThrow(() => dns.lookup('', {family: 4, hints: 0}, common.noop));
assert.doesNotThrow(() => { assert.doesNotThrow(() => {
dns.lookup('', { dns.lookup('', {
family: 6, family: 6,
hints: dns.ADDRCONFIG hints: dns.ADDRCONFIG
}, noop); }, common.noop);
}); });
assert.doesNotThrow(() => dns.lookup('', {hints: dns.V4MAPPED}, noop)); assert.doesNotThrow(() => dns.lookup('', {hints: dns.V4MAPPED}, common.noop));
assert.doesNotThrow(() => { assert.doesNotThrow(() => {
dns.lookup('', { dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED hints: dns.ADDRCONFIG | dns.V4MAPPED
}, noop); }, common.noop);
}); });
assert.throws(() => dns.lookupService('0.0.0.0'), assert.throws(() => dns.lookupService('0.0.0.0'),
/^Error: Invalid arguments$/); /^Error: Invalid arguments$/);
assert.throws(() => dns.lookupService('fasdfdsaf', 0, noop), assert.throws(() => dns.lookupService('fasdfdsaf', 0, common.noop),
/^TypeError: "host" argument needs to be a valid IP address$/); /^TypeError: "host" argument needs to be a valid IP address$/);
assert.doesNotThrow(() => dns.lookupService('0.0.0.0', '0', noop)); assert.doesNotThrow(() => dns.lookupService('0.0.0.0', '0', common.noop));
assert.doesNotThrow(() => dns.lookupService('0.0.0.0', 0, noop)); assert.doesNotThrow(() => dns.lookupService('0.0.0.0', 0, common.noop));
assert.throws(() => dns.lookupService('0.0.0.0', null, noop), assert.throws(() => dns.lookupService('0.0.0.0', null, common.noop),
/^TypeError: "port" should be >= 0 and < 65536, got "null"$/); /^TypeError: "port" should be >= 0 and < 65536, got "null"$/);
assert.throws( assert.throws(
() => dns.lookupService('0.0.0.0', undefined, noop), () => dns.lookupService('0.0.0.0', undefined, common.noop),
/^TypeError: "port" should be >= 0 and < 65536, got "undefined"$/ /^TypeError: "port" should be >= 0 and < 65536, got "undefined"$/
); );
assert.throws(() => dns.lookupService('0.0.0.0', 65538, noop), assert.throws(() => dns.lookupService('0.0.0.0', 65538, common.noop),
/^TypeError: "port" should be >= 0 and < 65536, got "65538"$/); /^TypeError: "port" should be >= 0 and < 65536, got "65538"$/);
assert.throws(() => dns.lookupService('0.0.0.0', 'test', noop), assert.throws(() => dns.lookupService('0.0.0.0', 'test', common.noop),
/^TypeError: "port" should be >= 0 and < 65536, got "test"$/); /^TypeError: "port" should be >= 0 and < 65536, got "test"$/);
assert.throws(() => dns.lookupService('0.0.0.0', 80, null), assert.throws(() => dns.lookupService('0.0.0.0', 80, null),

View File

@ -37,7 +37,7 @@ global.domain = require('domain');
// should not throw a 'TypeError: undefined is not a function' exception // should not throw a 'TypeError: undefined is not a function' exception
crypto.randomBytes(8); crypto.randomBytes(8);
crypto.randomBytes(8, function() {}); crypto.randomBytes(8, common.noop);
crypto.pseudoRandomBytes(8); crypto.pseudoRandomBytes(8);
crypto.pseudoRandomBytes(8, function() {}); crypto.pseudoRandomBytes(8, common.noop);
crypto.pbkdf2('password', 'salt', 8, 8, 'sha1', function() {}); crypto.pbkdf2('password', 'salt', 8, 8, 'sha1', common.noop);

View File

@ -43,7 +43,7 @@ function err() {
function err2() { function err2() {
// this timeout should never be called, since the domain gets // this timeout should never be called, since the domain gets
// disposed when the error happens. // disposed when the error happens.
setTimeout(common.mustCall(() => {}, 0), 1); setTimeout(common.mustNotCall(), 1);
// this function doesn't exist, and throws an error as a result. // this function doesn't exist, and throws an error as a result.
err3(); // eslint-disable-line no-undef err3(); // eslint-disable-line no-undef

View File

@ -51,4 +51,4 @@ immediated.run(function() {
}); });
}); });
const timeout = setTimeout(function() {}, 10 * 1000); const timeout = setTimeout(common.noop, 10 * 1000);

View File

@ -22,7 +22,7 @@
'use strict'; 'use strict';
// Simple tests of most basic domain functionality. // Simple tests of most basic domain functionality.
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const domain = require('domain'); const domain = require('domain');
const events = require('events'); const events = require('events');
@ -261,7 +261,7 @@ const fst = fs.createReadStream('stream for nonexistent file');
d.add(fst); d.add(fst);
expectCaught++; expectCaught++;
[42, null, , false, function() {}, 'string'].forEach(function(something) { [42, null, , false, common.noop, 'string'].forEach(function(something) {
const d = new domain.Domain(); const d = new domain.Domain();
d.run(function() { d.run(function() {
process.nextTick(function() { process.nextTick(function() {

View File

@ -20,7 +20,8 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common');
const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const events = require('events'); const events = require('events');
@ -28,40 +29,40 @@ let e = new events.EventEmitter();
// default // default
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
e.on('default', function() {}); e.on('default', common.noop);
} }
assert.ok(!e._events['default'].hasOwnProperty('warned')); assert.ok(!e._events['default'].hasOwnProperty('warned'));
e.on('default', function() {}); e.on('default', common.noop);
assert.ok(e._events['default'].warned); assert.ok(e._events['default'].warned);
// symbol // symbol
const symbol = Symbol('symbol'); const symbol = Symbol('symbol');
e.setMaxListeners(1); e.setMaxListeners(1);
e.on(symbol, function() {}); e.on(symbol, common.noop);
assert.ok(!e._events[symbol].hasOwnProperty('warned')); assert.ok(!e._events[symbol].hasOwnProperty('warned'));
e.on(symbol, function() {}); e.on(symbol, common.noop);
assert.ok(e._events[symbol].hasOwnProperty('warned')); assert.ok(e._events[symbol].hasOwnProperty('warned'));
// specific // specific
e.setMaxListeners(5); e.setMaxListeners(5);
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
e.on('specific', function() {}); e.on('specific', common.noop);
} }
assert.ok(!e._events['specific'].hasOwnProperty('warned')); assert.ok(!e._events['specific'].hasOwnProperty('warned'));
e.on('specific', function() {}); e.on('specific', common.noop);
assert.ok(e._events['specific'].warned); assert.ok(e._events['specific'].warned);
// only one // only one
e.setMaxListeners(1); e.setMaxListeners(1);
e.on('only one', function() {}); e.on('only one', common.noop);
assert.ok(!e._events['only one'].hasOwnProperty('warned')); assert.ok(!e._events['only one'].hasOwnProperty('warned'));
e.on('only one', function() {}); e.on('only one', common.noop);
assert.ok(e._events['only one'].hasOwnProperty('warned')); assert.ok(e._events['only one'].hasOwnProperty('warned'));
// unlimited // unlimited
e.setMaxListeners(0); e.setMaxListeners(0);
for (let i = 0; i < 1000; i++) { for (let i = 0; i < 1000; i++) {
e.on('unlimited', function() {}); e.on('unlimited', common.noop);
} }
assert.ok(!e._events['unlimited'].hasOwnProperty('warned')); assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
@ -70,26 +71,26 @@ events.EventEmitter.defaultMaxListeners = 42;
e = new events.EventEmitter(); e = new events.EventEmitter();
for (let i = 0; i < 42; ++i) { for (let i = 0; i < 42; ++i) {
e.on('fortytwo', function() {}); e.on('fortytwo', common.noop);
} }
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned')); assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
e.on('fortytwo', function() {}); e.on('fortytwo', common.noop);
assert.ok(e._events['fortytwo'].hasOwnProperty('warned')); assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
delete e._events['fortytwo'].warned; delete e._events['fortytwo'].warned;
events.EventEmitter.defaultMaxListeners = 44; events.EventEmitter.defaultMaxListeners = 44;
e.on('fortytwo', function() {}); e.on('fortytwo', common.noop);
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned')); assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
e.on('fortytwo', function() {}); e.on('fortytwo', common.noop);
assert.ok(e._events['fortytwo'].hasOwnProperty('warned')); assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
// but _maxListeners still has precedence over defaultMaxListeners // but _maxListeners still has precedence over defaultMaxListeners
events.EventEmitter.defaultMaxListeners = 42; events.EventEmitter.defaultMaxListeners = 42;
e = new events.EventEmitter(); e = new events.EventEmitter();
e.setMaxListeners(1); e.setMaxListeners(1);
e.on('uno', function() {}); e.on('uno', common.noop);
assert.ok(!e._events['uno'].hasOwnProperty('warned')); assert.ok(!e._events['uno'].hasOwnProperty('warned'));
e.on('uno', function() {}); e.on('uno', common.noop);
assert.ok(e._events['uno'].hasOwnProperty('warned')); assert.ok(e._events['uno'].hasOwnProperty('warned'));
// chainable // chainable

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
require('../common'); const 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', function() {}); EventEmitter.prototype.on.call(recv, 'event', common.noop);
EventEmitter.prototype.on.call(recv, 'event', function() {}); EventEmitter.prototype.on.call(recv, 'event', common.noop);

View File

@ -1,15 +1,15 @@
'use strict'; 'use strict';
require('../common'); const 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', function() {}); emitter.on('foo', common.noop);
emitter.on('foo', function() {}); emitter.on('foo', common.noop);
emitter.on('baz', function() {}); emitter.on('baz', common.noop);
// Allow any type // Allow any type
emitter.on(123, function() {}); emitter.on(123, common.noop);
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, function() {}); e.on(null, common.noop);
e.on(null, function() {}); e.on(null, common.noop);

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, function() {}); e.on(symbol, common.noop);
e.on(symbol, function() {}); e.on(symbol, common.noop);

View File

@ -18,5 +18,5 @@ 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', function() {}); e.on('event-type', common.noop);
e.on('event-type', function() {}); e.on('event-type', common.noop);

View File

@ -25,7 +25,7 @@ const assert = require('assert');
const events = require('events'); const events = require('events');
const e = new events.EventEmitter(); const e = new events.EventEmitter();
e.on('maxListeners', common.mustCall(function() {})); e.on('maxListeners', common.mustCall());
// Should not corrupt the 'maxListeners' queue. // Should not corrupt the 'maxListeners' queue.
e.setMaxListeners(42); e.setMaxListeners(42);

View File

@ -26,7 +26,7 @@ const EventEmitter = require('events');
const e = new EventEmitter(); const e = new EventEmitter();
e.once('hello', common.mustCall(function(a, b) {})); e.once('hello', common.mustCall());
e.emit('hello', 'a', 'b'); e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b'); e.emit('hello', 'a', 'b');
@ -45,7 +45,7 @@ e.once('e', common.mustCall(function() {
e.emit('e'); e.emit('e');
})); }));
e.once('e', common.mustCall(function() {})); e.once('e', common.mustCall());
e.emit('e'); e.emit('e');

View File

@ -36,28 +36,26 @@ function expect(expected) {
return common.mustCall(listener, expected.length); return common.mustCall(listener, expected.length);
} }
function listener() {}
{ {
const ee = new events.EventEmitter(); const ee = new events.EventEmitter();
ee.on('foo', listener); ee.on('foo', common.noop);
ee.on('bar', listener); ee.on('bar', common.noop);
ee.on('baz', listener); ee.on('baz', common.noop);
ee.on('baz', listener); ee.on('baz', common.noop);
const fooListeners = ee.listeners('foo'); const fooListeners = ee.listeners('foo');
const barListeners = ee.listeners('bar'); const barListeners = ee.listeners('bar');
const bazListeners = ee.listeners('baz'); const bazListeners = ee.listeners('baz');
ee.on('removeListener', expect(['bar', 'baz', 'baz'])); ee.on('removeListener', expect(['bar', 'baz', 'baz']));
ee.removeAllListeners('bar'); ee.removeAllListeners('bar');
ee.removeAllListeners('baz'); ee.removeAllListeners('baz');
assert.deepStrictEqual(ee.listeners('foo'), [listener]); assert.deepStrictEqual(ee.listeners('foo'), [common.noop]);
assert.deepStrictEqual(ee.listeners('bar'), []); assert.deepStrictEqual(ee.listeners('bar'), []);
assert.deepStrictEqual(ee.listeners('baz'), []); assert.deepStrictEqual(ee.listeners('baz'), []);
// After calling removeAllListeners(), // After calling removeAllListeners(),
// the old listeners array should stay unchanged. // the old listeners array should stay unchanged.
assert.deepStrictEqual(fooListeners, [listener]); assert.deepStrictEqual(fooListeners, [common.noop]);
assert.deepStrictEqual(barListeners, [listener]); assert.deepStrictEqual(barListeners, [common.noop]);
assert.deepStrictEqual(bazListeners, [listener, listener]); assert.deepStrictEqual(bazListeners, [common.noop, common.noop]);
// After calling removeAllListeners(), // After calling removeAllListeners(),
// new listeners arrays is different from the old. // new listeners arrays is different from the old.
assert.notStrictEqual(ee.listeners('bar'), barListeners); assert.notStrictEqual(ee.listeners('bar'), barListeners);
@ -66,8 +64,8 @@ function listener() {}
{ {
const ee = new events.EventEmitter(); const ee = new events.EventEmitter();
ee.on('foo', listener); ee.on('foo', common.noop);
ee.on('bar', listener); ee.on('bar', common.noop);
// Expect LIFO order // Expect LIFO order
ee.on('removeListener', expect(['foo', 'bar', 'removeListener'])); ee.on('removeListener', expect(['foo', 'bar', 'removeListener']));
ee.on('removeListener', expect(['foo', 'bar'])); ee.on('removeListener', expect(['foo', 'bar']));
@ -78,7 +76,7 @@ function listener() {}
{ {
const ee = new events.EventEmitter(); const ee = new events.EventEmitter();
ee.on('removeListener', listener); ee.on('removeListener', common.noop);
// Check for regression where removeAllListeners() throws when // Check for regression where removeAllListeners() throws when
// there exists a 'removeListener' listener, but there exists // there exists a 'removeListener' listener, but there exists
// no listeners for the provided event type. // no listeners for the provided event type.
@ -88,12 +86,12 @@ function listener() {}
{ {
const ee = new events.EventEmitter(); const ee = new events.EventEmitter();
let expectLength = 2; let expectLength = 2;
ee.on('removeListener', function(name, listener) { ee.on('removeListener', function(name, noop) {
assert.strictEqual(expectLength--, this.listeners('baz').length); assert.strictEqual(expectLength--, this.listeners('baz').length);
}); });
ee.on('baz', function() {}); ee.on('baz', common.noop);
ee.on('baz', function() {}); ee.on('baz', common.noop);
ee.on('baz', function() {}); ee.on('baz', common.noop);
assert.strictEqual(ee.listeners('baz').length, expectLength + 1); assert.strictEqual(ee.listeners('baz').length, expectLength + 1);
ee.removeAllListeners('baz'); ee.removeAllListeners('baz');
assert.strictEqual(ee.listeners('baz').length, 0); assert.strictEqual(ee.listeners('baz').length, 0);

View File

@ -112,7 +112,7 @@ function listener2() {}
const listener3 = common.mustCall(() => { const listener3 = common.mustCall(() => {
ee.removeListener('hello', listener4); ee.removeListener('hello', listener4);
}, 2); }, 2);
const listener4 = common.mustCall(() => {}); const listener4 = common.mustCall();
ee.on('hello', listener3); ee.on('hello', listener3);
ee.on('hello', listener4); ee.on('hello', listener4);
@ -140,7 +140,7 @@ function listener2() {}
{ {
const ee = new EventEmitter(); const ee = new EventEmitter();
assert.deepStrictEqual(ee, ee.removeListener('foo', () => {})); assert.deepStrictEqual(ee, ee.removeListener('foo', common.noop));
} }
// 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 = () => {}; const listener = common.noop;
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 = () => {}; const handler = common.noop;
assert.deepStrictEqual(ee.eventNames(), []); assert.deepStrictEqual(ee.eventNames(), []);

View File

@ -34,7 +34,7 @@ function MyEE(cb) {
EventEmitter.call(this); EventEmitter.call(this);
} }
const myee = new MyEE(common.mustCall(function() {})); const myee = new MyEE(common.mustCall());
util.inherits(ErrorEE, EventEmitter); util.inherits(ErrorEE, EventEmitter);
@ -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', function() {}); ee1.on('x', common.noop);
assert.strictEqual(ee2.listenerCount('x'), 0); assert.strictEqual(ee2.listenerCount('x'), 0);

View File

@ -6,7 +6,7 @@ const assert = require('assert');
const ee = new EventEmitter(); const ee = new EventEmitter();
const foo = Symbol('foo'); const foo = Symbol('foo');
const listener = common.mustCall(function() {}); const listener = common.mustCall();
ee.on(foo, listener); ee.on(foo, listener);
assert.deepStrictEqual(ee.listeners(foo), [listener]); assert.deepStrictEqual(ee.listeners(foo), [listener]);

View File

@ -5,6 +5,7 @@ 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

@ -1,14 +1,13 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const options = 'test'; const options = 'test';
const noop = () => {};
const unknownEncodingMessage = /^Error: Unknown encoding: test$/; const unknownEncodingMessage = /^Error: Unknown encoding: test$/;
assert.throws(() => { assert.throws(() => {
fs.readFile('path', options, noop); fs.readFile('path', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
@ -16,7 +15,7 @@ assert.throws(() => {
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
fs.readdir('path', options, noop); fs.readdir('path', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
@ -24,7 +23,7 @@ assert.throws(() => {
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
fs.readlink('path', options, noop); fs.readlink('path', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
@ -32,7 +31,7 @@ assert.throws(() => {
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
fs.writeFile('path', 'data', options, noop); fs.writeFile('path', 'data', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
@ -40,7 +39,7 @@ assert.throws(() => {
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
fs.appendFile('path', 'data', options, noop); fs.appendFile('path', 'data', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
@ -48,11 +47,11 @@ assert.throws(() => {
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
fs.watch('path', options, noop); fs.watch('path', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
fs.realpath('path', options, noop); fs.realpath('path', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
@ -60,7 +59,7 @@ assert.throws(() => {
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {
fs.mkdtemp('path', options, noop); fs.mkdtemp('path', options, common.noop);
}, unknownEncodingMessage); }, unknownEncodingMessage);
assert.throws(() => { assert.throws(() => {

View File

@ -33,11 +33,9 @@ fs.open(emptyFile, 'r', common.mustCall((error, fd) => {
const read = fs.createReadStream(emptyFile, { fd }); const read = fs.createReadStream(emptyFile, { fd });
read.once('data', () => { read.once('data', common.mustNotCall('data event should not emit'));
common.fail('data event should not emit');
});
read.once('end', common.mustCall(function endEvent1() {})); read.once('end', common.mustCall());
})); }));
fs.open(emptyFile, 'r', common.mustCall((error, fd) => { fs.open(emptyFile, 'r', common.mustCall((error, fd) => {
@ -48,13 +46,9 @@ fs.open(emptyFile, 'r', common.mustCall((error, fd) => {
read.pause(); read.pause();
read.once('data', () => { read.once('data', common.mustNotCall('data event should not emit'));
common.fail('data event should not emit');
});
read.once('end', function endEvent2() { read.once('end', common.mustNotCall('end event should not emit'));
common.fail('end event should not emit');
});
setTimeout(common.mustCall(() => { setTimeout(common.mustCall(() => {
assert.strictEqual(read.isPaused(), true); assert.strictEqual(read.isPaused(), true);

View File

@ -12,7 +12,7 @@ function test(cb) {
} }
// Verify the case where a callback function is provided // Verify the case where a callback function is provided
assert.doesNotThrow(test(function() {})); assert.doesNotThrow(test(common.noop));
process.once('warning', common.mustCall((warning) => { process.once('warning', common.mustCall((warning) => {
assert.strictEqual( assert.strictEqual(

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(function() {}); process.nextTick(common.noop);

View File

@ -63,12 +63,14 @@ if (!common.isAix) {
// https://github.com/nodejs/node/issues/5085 is fixed // https://github.com/nodejs/node/issues/5085 is fixed
{ {
let watch; let watch;
assert.doesNotThrow(() => watch = fs.watch(__filename, options, () => {})); assert.doesNotThrow(() => {
watch = fs.watch(__filename, options, common.noop);
});
watch.close(); watch.close();
} }
{ {
assert.doesNotThrow(() => fs.watchFile(__filename, options, () => {})); assert.doesNotThrow(() => fs.watchFile(__filename, options, common.noop));
fs.unwatchFile(__filename); fs.unwatchFile(__filename);
} }
} }

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
require('../common');
const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
@ -8,6 +8,6 @@ const encoding = 'foo-8';
const filename = 'bar.txt'; const filename = 'bar.txt';
assert.throws( assert.throws(
fs.readFile.bind(fs, filename, { encoding }, () => {}), fs.readFile.bind(fs, filename, { encoding }, common.noop),
new RegExp(`Error: Unknown encoding: ${encoding}$`) new RegExp(`Error: Unknown encoding: ${encoding}$`)
); );

View File

@ -5,7 +5,5 @@ const fs = require('fs');
const s = fs.createReadStream(__filename); const s = fs.createReadStream(__filename);
s.close(common.mustCall(noop)); s.close(common.mustCall());
s.close(common.mustCall(noop)); s.close(common.mustCall());
function noop() {}

View File

@ -39,7 +39,7 @@ let paused = false;
}); });
file.on('end', common.mustCall(function() {})); file.on('end', common.mustCall());
file.on('close', common.mustCall(function() { file.on('close', common.mustCall(function() {
@ -139,7 +139,7 @@ let paused = false;
let file7 = let file7 =
fs.createReadStream(rangeFile, Object.create({autoClose: false })); fs.createReadStream(rangeFile, Object.create({autoClose: false }));
assert.strictEqual(file7.autoClose, false); assert.strictEqual(file7.autoClose, false);
file7.on('data', function() {}); file7.on('data', common.noop);
file7.on('end', common.mustCall(function() { file7.on('end', common.mustCall(function() {
process.nextTick(common.mustCall(function() { process.nextTick(common.mustCall(function() {
assert(!file7.closed); assert(!file7.closed);
@ -169,8 +169,8 @@ let paused = false;
{ {
const options = Object.create({fd: 13337, autoClose: false}); const options = Object.create({fd: 13337, autoClose: false});
const file8 = fs.createReadStream(null, options); const file8 = fs.createReadStream(null, options);
file8.on('data', function() {}); file8.on('data', common.noop);
file8.on('error', common.mustCall(function() {})); file8.on('error', common.mustCall());
process.on('exit', function() { process.on('exit', function() {
assert(!file8.closed); assert(!file8.closed);
assert(!file8.destroyed); assert(!file8.destroyed);
@ -181,8 +181,8 @@ let paused = false;
// Make sure stream is destroyed when file does not exist. // Make sure stream is destroyed when file does not exist.
{ {
const file9 = fs.createReadStream('/path/to/file/that/does/not/exist'); const file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
file9.on('data', function() {}); file9.on('data', common.noop);
file9.on('error', common.mustCall(function() {})); file9.on('error', common.mustCall());
process.on('exit', function() { process.on('exit', function() {
assert(!file9.closed); assert(!file9.closed);

View File

@ -159,7 +159,7 @@ pauseRes.pause();
pauseRes.resume(); pauseRes.resume();
let file7 = fs.createReadStream(rangeFile, {autoClose: false }); let file7 = fs.createReadStream(rangeFile, {autoClose: false });
file7.on('data', function() {}); file7.on('data', common.noop);
file7.on('end', function() { file7.on('end', function() {
process.nextTick(function() { process.nextTick(function() {
assert(!file7.closed); assert(!file7.closed);
@ -182,13 +182,13 @@ function file7Next() {
// Just to make sure autoClose won't close the stream because of error. // Just to make sure autoClose won't close the stream because of error.
const file8 = fs.createReadStream(null, {fd: 13337, autoClose: false }); const file8 = fs.createReadStream(null, {fd: 13337, autoClose: false });
file8.on('data', function() {}); file8.on('data', common.noop);
file8.on('error', common.mustCall(function() {})); file8.on('error', common.mustCall());
// Make sure stream is destroyed when file does not exist. // Make sure stream is destroyed when file does not exist.
const file9 = fs.createReadStream('/path/to/file/that/does/not/exist'); const file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
file9.on('data', function() {}); file9.on('data', common.noop);
file9.on('error', common.mustCall(function() {})); file9.on('error', common.mustCall());
process.on('exit', function() { process.on('exit', function() {
assert(file7.closed); assert(file7.closed);

View File

@ -13,7 +13,7 @@ assert.throws(() => {
expected.length, expected.length,
0, 0,
'utf-8', 'utf-8',
() => {}); common.noop);
}, /Second argument needs to be a buffer/); }, /Second argument needs to be a buffer/);
assert.throws(() => { assert.throws(() => {

View File

@ -3,7 +3,7 @@ const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const watch = fs.watchFile(__filename, () => {}); const watch = fs.watchFile(__filename, common.noop);
let triggered; let triggered;
const listener = common.mustCall(() => { const listener = common.mustCall(() => {
triggered = true; triggered = true;

View File

@ -1,9 +1,10 @@
'use strict'; 'use strict';
require('../common');
const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const watch = fs.watchFile(__filename, () => {}); const watch = fs.watchFile(__filename, common.noop);
watch.once('stop', assert.fail); // Should not trigger. watch.once('stop', assert.fail); // Should not trigger.
watch.stop(); watch.stop();
watch.removeListener('stop', assert.fail); watch.removeListener('stop', assert.fail);

View File

@ -15,7 +15,7 @@ assert.throws(function() {
}, /"watchFile\(\)" requires a listener function/); }, /"watchFile\(\)" requires a listener function/);
assert.throws(function() { assert.throws(function() {
fs.watchFile(new Object(), function() {}); fs.watchFile(new Object(), common.noop);
}, /Path must be a string/); }, /Path must be a string/);
const enoentFile = path.join(common.tmpDir, 'non-existent-file'); const enoentFile = path.join(common.tmpDir, 'non-existent-file');

View File

@ -8,7 +8,5 @@ common.refreshTmpDir();
const s = fs.createWriteStream(path.join(common.tmpDir, 'rw')); const s = fs.createWriteStream(path.join(common.tmpDir, 'rw'));
s.close(common.mustCall(noop)); s.close(common.mustCall());
s.close(common.mustCall(noop)); s.close(common.mustCall());
function noop() {}

View File

@ -31,7 +31,7 @@ common.refreshTmpDir();
const file = path.join(common.tmpDir, 'write-end-test0.txt'); const file = path.join(common.tmpDir, 'write-end-test0.txt');
const stream = fs.createWriteStream(file); const stream = fs.createWriteStream(file);
stream.end(); stream.end();
stream.on('close', common.mustCall(function() { })); stream.on('close', common.mustCall());
} }
{ {

View File

@ -35,8 +35,8 @@ const old_default = EventEmitter.defaultMaxListeners;
EventEmitter.defaultMaxListeners = 1; EventEmitter.defaultMaxListeners = 1;
const e = new EventEmitter(); const e = new EventEmitter();
e.on('hello', () => {}); e.on('hello', common.noop);
e.on('hello', () => {}); e.on('hello', common.noop);
// TODO: Figure out how to validate console. Currently, // TODO: Figure out how to validate console. Currently,
// there is no obvious way of validating that console // there is no obvious way of validating that console

View File

@ -22,7 +22,7 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
process.on('uncaughtException', common.mustCall(function() {}, 2)); process.on('uncaughtException', common.mustCall(2));
setTimeout(function() { setTimeout(function() {
process.nextTick(function() { process.nextTick(function() {

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(() => {}).listen(0); const server = net.createServer(common.noop).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(() => {}, 500); const timer = setTimeout(common.noop, 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

@ -59,6 +59,6 @@ server.listen(0, common.mustCall(function() {
}); });
// it would be nice if this worked: // it would be nice if this worked:
res.on('close', common.mustCall(function() {})); res.on('close', common.mustCall());
})); }));
})); }));

View File

@ -13,6 +13,6 @@ server.listen(0, common.mustCall(function() {
headers: { connection: 'keep-alive' } headers: { connection: 'keep-alive' }
}, common.mustCall(function(res) { }, common.mustCall(function(res) {
server.close(); server.close();
res.on('aborted', common.mustCall(function() {})); res.on('aborted', common.mustCall());
})); }));
})); }));

View File

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

View File

@ -33,7 +33,7 @@ server.listen(0, common.mustCall(function() {
path: 'example.com:443' path: 'example.com:443'
}, common.mustNotCall()); }, common.mustNotCall());
req.on('close', common.mustCall(function() { })); req.on('close', common.mustCall());
req.on('connect', common.mustCall(function(res, socket, firstBodyChunk) { req.on('connect', common.mustCall(function(res, socket, firstBodyChunk) {
console.error('Client got CONNECT request'); console.error('Client got CONNECT request');

View File

@ -49,7 +49,7 @@ server.listen(0, common.mustCall(function() {
path: 'google.com:443' path: 'google.com:443'
}, common.mustNotCall()); }, common.mustNotCall());
req.on('close', common.mustCall(() => {})); req.on('close', common.mustCall());
req.on('connect', common.mustCall((res, socket, firstBodyChunk) => { req.on('connect', common.mustCall((res, socket, firstBodyChunk) => {
// Make sure this request got removed from the pool. // Make sure this request got removed from the pool.

View File

@ -49,4 +49,4 @@ server.listen(0, common.mustCall(() => {
} }
})); }));
process.on('uncaughtException', common.mustCall(() => {}, 10)); process.on('uncaughtException', common.mustCall(10));

View File

@ -20,7 +20,8 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common');
const common = require('../common');
const net = require('net'); const net = require('net');
const http = require('http'); const http = require('http');
@ -28,7 +29,7 @@ const http = require('http');
// It is separate from test-http-malformed-request.js because it is only // It is separate from test-http-malformed-request.js because it is only
// reproduceable on the first packet on the first connection to a server. // reproduceable on the first packet on the first connection to a server.
const server = http.createServer(function(req, res) {}); const server = http.createServer(common.noop);
server.listen(0); server.listen(0);
server.on('listening', function() { server.on('listening', function() {

View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
require('../common');
const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const EventEmitter = require('events'); const EventEmitter = require('events');
const http = require('http'); const http = require('http');
@ -28,7 +29,7 @@ server.listen(0, function() {
port: server.address().port, port: server.address().port,
headers: {'testing 123': 123} headers: {'testing 123': 123}
}; };
http.get(options, function() {}); http.get(options, common.noop);
}, },
function(err) { function(err) {
ee.emit('done'); ee.emit('done');

View File

@ -4,7 +4,7 @@
// Flags: --expose_gc // Flags: --expose_gc
require('../common'); const 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] = function(b, start, len) { }; parser[kOnBody] = common.noop;
parser[kOnMessageComplete] = function() { parser[kOnMessageComplete] = function() {
messagesComplete++; messagesComplete++;

View File

@ -43,6 +43,6 @@ server.listen(0, common.mustCall(function() {
}); });
})); }));
res.on('end', common.mustCall(function() {})); res.on('end', common.mustCall());
})); }));
})); }));

View File

@ -46,7 +46,7 @@ function parent() {
res.end(); res.end();
}); });
server.on('connection', common.mustCall(function(conn) {})); server.on('connection', common.mustCall());
server.listen(0, function() { server.listen(0, function() {
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;

View File

@ -25,5 +25,5 @@ server.listen(0, () => {
// close the connection without returning any data. // close the connection without returning any data.
common.fail('no data should be returned by the server'); common.fail('no data should be returned by the server');
}); });
client.on('end', common.mustCall(() => {})); client.on('end', common.mustCall());
}); });

View File

@ -52,7 +52,7 @@ test(function serverTimeout(cb) {
// just do nothing, we should get a timeout event. // just do nothing, we should get a timeout event.
}); });
server.listen(common.mustCall(function() { server.listen(common.mustCall(function() {
http.get({ port: server.address().port }).on('error', function() {}); http.get({ port: server.address().port }).on('error', common.noop);
})); }));
const s = server.setTimeout(50, function(socket) { const s = server.setTimeout(50, function(socket) {
caughtTimeout = true; caughtTimeout = true;
@ -81,7 +81,7 @@ test(function serverRequestTimeout(cb) {
server.listen(common.mustCall(function() { server.listen(common.mustCall(function() {
const port = server.address().port; const port = server.address().port;
const req = http.request({ port: port, method: 'POST' }); const req = http.request({ port: port, method: 'POST' });
req.on('error', function() {}); req.on('error', common.noop);
req.write('Hello'); req.write('Hello');
// req is in progress // req is in progress
})); }));
@ -104,7 +104,7 @@ test(function serverResponseTimeout(cb) {
}); });
server.listen(common.mustCall(function() { server.listen(common.mustCall(function() {
const port = server.address().port; const port = server.address().port;
http.get({ port: port }).on('error', function() {}); http.get({ port: port }).on('error', common.noop);
})); }));
}); });
@ -132,7 +132,7 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
}); });
server.listen(common.mustCall(function() { server.listen(common.mustCall(function() {
const port = server.address().port; const port = server.address().port;
http.get({ port: port }).on('error', function() {}); http.get({ port: port }).on('error', common.noop);
})); }));
}); });

View File

@ -20,7 +20,8 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common');
const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const util = require('util'); const util = require('util');
@ -37,7 +38,7 @@ function createTestServer() {
} }
function testServer() { function testServer() {
http.Server.call(this, function() {}); http.Server.call(this, common.noop);
this.on('connection', function() { this.on('connection', function() {
requests_recv++; requests_recv++;

View File

@ -31,7 +31,7 @@ server.on('connection', function(connection) {
}); });
function shutdown() { function shutdown() {
server.close(common.mustCall(function() {})); server.close(common.mustCall());
for (const key in connections) { for (const key in connections) {
connections[key].destroy(); connections[key].destroy();
@ -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', function(d) {}); res.on('data', common.noop);
setImmediate(shutdown); setImmediate(shutdown);
}); });
req.end(); req.end();

View File

@ -69,7 +69,7 @@ test(function serverTimeout(cb) {
https.get({ https.get({
port: this.address().port, port: this.address().port,
rejectUnauthorized: false rejectUnauthorized: false
}).on('error', function() {}); }).on('error', common.noop);
})); }));
}); });
@ -90,7 +90,7 @@ test(function serverRequestTimeout(cb) {
method: 'POST', method: 'POST',
rejectUnauthorized: false rejectUnauthorized: false
}); });
req.on('error', function() {}); req.on('error', common.noop);
req.write('Hello'); req.write('Hello');
// req is in progress // req is in progress
}); });
@ -111,7 +111,7 @@ test(function serverResponseTimeout(cb) {
https.get({ https.get({
port: this.address().port, port: this.address().port,
rejectUnauthorized: false rejectUnauthorized: false
}).on('error', function() {}); }).on('error', common.noop);
}); });
}); });
@ -119,7 +119,7 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
function handler(req, res) { function handler(req, res) {
// just do nothing, we should get a timeout event. // just do nothing, we should get a timeout event.
req.setTimeout(50, common.mustNotCall()); req.setTimeout(50, common.mustNotCall());
res.on('timeout', common.mustCall(function(socket) {})); res.on('timeout', common.mustCall());
} }
const server = https.createServer(serverOptions, common.mustCall(handler)); const server = https.createServer(serverOptions, common.mustCall(handler));
server.on('timeout', function(socket) { server.on('timeout', function(socket) {
@ -131,7 +131,7 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
https.get({ https.get({
port: this.address().port, port: this.address().port,
rejectUnauthorized: false rejectUnauthorized: false
}).on('error', function() {}); }).on('error', common.noop);
}); });
}); });

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, function() { }); req.setTimeout(1000, common.noop);
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, function() { }); req.setTimeout(1000, common.noop);
req.setSocketKeepAlive(true, 1000); req.setSocketKeepAlive(true, 1000);
req.end(); req.end();
}); });

View File

@ -1,10 +1,11 @@
'use strict'; 'use strict';
require('../common');
const 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 = () => {}; const F = common.noop;
F.prototype = {}; F.prototype = {};
assert(Object.create(F.prototype) instanceof F); assert(Object.create(F.prototype) instanceof F);

View File

@ -36,7 +36,7 @@ let localhostTries = 10;
const server = net.createServer({allowHalfOpen: true}, function(socket) { const server = net.createServer({allowHalfOpen: true}, function(socket) {
socket.resume(); socket.resume();
socket.on('end', common.mustCall(function() {})); socket.on('end', common.mustCall());
socket.end(); socket.end();
}); });

View File

@ -159,7 +159,8 @@ function syncFailToConnect(port, regexp, optOnly) {
} }
function canConnect(port) { function canConnect(port) {
const noop = () => common.mustCall(function() {}); const noop = () => common.mustCall();
// connect(port, cb) and connect(port) // connect(port, cb) and connect(port)
const portArgBlocks = doConnect([port], noop); const portArgBlocks = doConnect([port], noop);
for (const block of portArgBlocks) { for (const block of portArgBlocks) {

View File

@ -4,7 +4,7 @@ const net = require('net');
const server = net.createServer(common.mustNotCall()); const server = net.createServer(common.mustNotCall());
server.on('close', common.mustCall(function() {})); server.on('close', common.mustCall());
server.listen(0, common.mustNotCall()); server.listen(0, common.mustNotCall());

View File

@ -26,4 +26,4 @@ const net = require('net');
const server = net.createServer(function(socket) { const server = net.createServer(function(socket) {
}); });
server.listen(1, '1.1.1.1', common.mustNotCall()); // EACCESS or EADDRNOTAVAIL server.listen(1, '1.1.1.1', common.mustNotCall()); // EACCESS or EADDRNOTAVAIL
server.on('error', common.mustCall(function(error) {})); server.on('error', common.mustCall());

Some files were not shown because too many files have changed in this diff Show More