Skip to content

Commit a7b9450

Browse files
jasnellMylesBorins
authored andcommitted
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: #12027 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent e79c054 commit a7b9450

File tree

98 files changed

+236
-225
lines changed

Some content is hidden

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

98 files changed

+236
-225
lines changed

test/addons/async-hello-world/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ const binding = require(`./build/${common.buildType}/binding`);
66
binding(5, common.mustCall(function(err, val) {
77
assert.strictEqual(err, null);
88
assert.strictEqual(val, 10);
9-
process.nextTick(common.mustCall(function() {}));
9+
process.nextTick(common.mustCall());
1010
}));

test/common/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const Timer = process.binding('timer_wrap').Timer;
1212
const testRoot = process.env.NODE_TEST_DIR ?
1313
fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..');
1414

15+
const noop = () => {};
16+
17+
exports.noop = noop;
1518
exports.fixturesDir = path.join(__dirname, '..', 'fixtures');
1619
exports.tmpDirName = 'tmp';
1720
// PORT should match the definition in test/testpy/__init__.py.
@@ -419,6 +422,13 @@ function runCallChecks(exitCode) {
419422

420423

421424
exports.mustCall = function(fn, expected) {
425+
if (typeof fn === 'number') {
426+
expected = fn;
427+
fn = noop;
428+
} else if (fn === undefined) {
429+
fn = noop;
430+
}
431+
422432
if (expected === undefined)
423433
expected = 1;
424434
else if (typeof expected !== 'number')
@@ -487,9 +497,9 @@ util.inherits(ArrayStream, stream.Stream);
487497
exports.ArrayStream = ArrayStream;
488498
ArrayStream.prototype.readable = true;
489499
ArrayStream.prototype.writable = true;
490-
ArrayStream.prototype.pause = function() {};
491-
ArrayStream.prototype.resume = function() {};
492-
ArrayStream.prototype.write = function() {};
500+
ArrayStream.prototype.pause = noop;
501+
ArrayStream.prototype.resume = noop;
502+
ArrayStream.prototype.write = noop;
493503

494504
// Returns true if the exit code "exitCode" and/or signal name "signal"
495505
// represent the exit code and/or signal name of a node process that aborted,

test/debugger/test-debugger-client.js

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

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

134134
let nodeProcess;
135135

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

test/parallel/test-assert.js

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

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

test/parallel/test-child-process-disconnect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if (process.argv[2] === 'child') {
5757
}));
5858

5959
// the process should also self terminate without using signals
60-
child.on('exit', common.mustCall(function() {}));
60+
child.on('exit', common.mustCall());
6161

6262
// when child is listening
6363
child.on('message', function(obj) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const assert = require('assert');
44
const spawn = require('child_process').spawn;
55
const cat = spawn(common.isWindows ? 'cmd' : 'cat');
66

7-
cat.stdout.on('end', common.mustCall(function() {}));
7+
cat.stdout.on('end', common.mustCall());
88
cat.stderr.on('data', common.mustNotCall());
9-
cat.stderr.on('end', common.mustCall(function() {}));
9+
cat.stderr.on('end', common.mustCall());
1010

1111
cat.on('exit', common.mustCall(function(code, signal) {
1212
assert.strictEqual(code, null);

test/parallel/test-child-process-stdin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ cat.stdout.on('data', function(chunk) {
2222
response += chunk;
2323
});
2424

25-
cat.stdout.on('end', common.mustCall(function() {}));
25+
cat.stdout.on('end', common.mustCall());
2626

2727
cat.stderr.on('data', common.mustNotCall());
2828

29-
cat.stderr.on('end', common.mustCall(function() {}));
29+
cat.stderr.on('end', common.mustCall());
3030

3131
cat.on('exit', common.mustCall(function(status) {
3232
assert.strictEqual(0, status);

test/parallel/test-cluster-eaccess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ if (cluster.isMaster) {
1414
const worker = cluster.fork();
1515

1616
// makes sure master is able to fork the worker
17-
cluster.on('fork', common.mustCall(function() {}));
17+
cluster.on('fork', common.mustCall());
1818

1919
// makes sure the worker is ready
20-
worker.on('online', common.mustCall(function() {}));
20+
worker.on('online', common.mustCall());
2121

2222
worker.on('message', common.mustCall(function(err) {
2323
// disconnect first, so that we will not leave zombies

test/parallel/test-cluster-setup-master-emit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ function emitAndCatch2(next) {
2222
}
2323

2424
emitAndCatch(common.mustCall(function() {
25-
emitAndCatch2(common.mustCall(function() {}));
25+
emitAndCatch2(common.mustCall());
2626
}));

test/parallel/test-cluster-worker-destroy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ if (cluster.isMaster) {
1717
worker2 = cluster.fork();
1818

1919
[worker1, worker2].forEach(function(worker) {
20-
worker.on('disconnect', common.mustCall(function() {}));
21-
worker.on('exit', common.mustCall(function() {}));
20+
worker.on('disconnect', common.mustCall());
21+
worker.on('exit', common.mustCall());
2222
});
2323
} else {
2424
if (cluster.worker.id === 1) {

0 commit comments

Comments
 (0)