Skip to content

Commit f0eba78

Browse files
cjihrigitaloacasas
authored andcommitted
test: add common.mustNotCall()
This commit adds a mustNotCall() helper for testing. This provides an alternative to using common.fail() as a callback, or creating a callback function for the sole purpose of calling common.fail(). PR-URL: #11152 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent 44b17a2 commit f0eba78

File tree

124 files changed

+243
-234
lines changed

Some content is hidden

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

124 files changed

+243
-234
lines changed

test/common.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ function fail(msg) {
494494
}
495495
exports.fail = fail;
496496

497+
exports.mustNotCall = function(msg) {
498+
return function mustNotCall() {
499+
fail(msg || 'function should not have been called');
500+
};
501+
};
502+
497503
exports.skip = function(msg) {
498504
console.log(`1..0 # Skipped: ${msg}`);
499505
};

test/debugger/test-debugger-remote.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const interfacer = spawn(process.execPath, ['debug', `localhost:${PORT}`]);
1515
interfacer.stdout.setEncoding('utf-8');
1616

1717
// fail the test if either of the processes exit normally
18-
const debugBreakExit = common.fail.bind(null, 'child should not exit normally');
19-
const debugExit = common.fail.bind(null, 'interfacer should not exit normally');
18+
const debugBreakExit = common.mustNotCall('child should not exit normally');
19+
const debugExit = common.mustNotCall('interfacer should not exit normally');
2020
child.on('exit', debugBreakExit);
2121
interfacer.on('exit', debugExit);
2222

test/inspector/inspector-helper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ function makeBufferingDataCallback(dataCallback) {
116116
}
117117

118118
function timeout(message, multiplicator) {
119-
return setTimeout(() => common.fail(message), TIMEOUT * (multiplicator || 1));
119+
return setTimeout(common.mustNotCall(message),
120+
TIMEOUT * (multiplicator || 1));
120121
}
121122

122123
const TestSession = function(socket, harness) {
@@ -398,7 +399,7 @@ Harness.prototype.wsHandshake = function(devtoolsUrl, tests, readyCallback) {
398399
});
399400
}
400401
enqueue(tests);
401-
}).on('response', () => common.fail('Upgrade was not received'));
402+
}).on('response', common.mustNotCall('Upgrade was not received'));
402403
};
403404

404405
Harness.prototype.runFrontendSession = function(tests) {

test/internet/test-dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function checkWrap(req) {
4545

4646
TEST(function test_reverse_bogus(done) {
4747
assert.throws(() => {
48-
dns.reverse('bogus ip', common.fail);
48+
dns.reverse('bogus ip', common.mustNotCall());
4949
}, /^Error: getHostByAddr EINVAL$/);
5050
done();
5151
});

test/internet/test-http-dns-fail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function httpreq(count) {
1616
port: 80,
1717
path: '/',
1818
method: 'GET'
19-
}, common.fail);
19+
}, common.mustNotCall());
2020

2121
req.on('error', common.mustCall((e) => {
2222
assert.strictEqual(e.code, 'ENOTFOUND');

test/internet/test-net-connect-timeout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ socket.on('timeout', common.mustCall(function() {
2626
socket.destroy();
2727
}));
2828

29-
socket.on('connect', common.fail);
29+
socket.on('connect', common.mustNotCall());

test/internet/test-net-connect-unref.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ const client = net.createConnection(53, '8.8.8.8', function() {
88
client.unref();
99
});
1010

11-
client.on('close', common.fail);
11+
client.on('close', common.mustNotCall());
1212

13-
setTimeout(common.fail, TIMEOUT).unref();
13+
setTimeout(common.mustNotCall(), TIMEOUT).unref();

test/parallel/test-async-wrap-throw-from-callback.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ if (typeof process.argv[2] === 'string') {
3737
async_wrap.setupHooks({ init, pre, post, destroy });
3838
async_wrap.enable();
3939

40-
process.on('uncaughtException', common.fail);
40+
process.on('uncaughtException', common.mustNotCall());
4141

4242
const d = domain.create();
43-
d.on('error', common.fail);
43+
d.on('error', common.mustNotCall());
4444
d.run(() => {
4545
// Using randomBytes because timers are not yet supported.
4646
crypto.randomBytes(0, () => { });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const spawn = require('child_process').spawn;
55
const cat = spawn(common.isWindows ? 'cmd' : 'cat');
66

77
cat.stdout.on('end', common.mustCall(function() {}));
8-
cat.stderr.on('data', common.fail);
8+
cat.stderr.on('data', common.mustNotCall());
99
cat.stderr.on('end', common.mustCall(function() {}));
1010

1111
cat.on('exit', common.mustCall(function(code, signal) {

test/parallel/test-child-process-recv-handle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function master() {
2424
});
2525
proc.stdout.on('data', common.mustCall((data) => {
2626
assert.strictEqual(data.toString(), 'ok\r\n');
27-
net.createServer(common.fail).listen(0, function() {
27+
net.createServer(common.mustNotCall()).listen(0, function() {
2828
handle = this._handle;
2929
proc.send('one');
3030
proc.send('two', handle);

0 commit comments

Comments
 (0)