Skip to content

Commit bea0a6e

Browse files
cjihrigMylesBorins
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 <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
1 parent f2230cc commit bea0a6e

File tree

106 files changed

+178
-200
lines changed

Some content is hidden

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

106 files changed

+178
-200
lines changed

test/common.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ function fail(msg) {
464464
}
465465
exports.fail = fail;
466466

467+
exports.mustNotCall = function(msg) {
468+
return function mustNotCall() {
469+
fail(msg || 'function should not have been called');
470+
};
471+
};
472+
467473
exports.skip = function(msg) {
468474
console.log(`1..0 # Skipped: ${msg}`);
469475
};

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-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-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);

test/parallel/test-child-process-send-returns-boolean.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ s.on('exit', function() {
2020
handle.close();
2121
});
2222

23-
net.createServer(common.fail).listen(0, function() {
23+
net.createServer(common.mustNotCall()).listen(0, function() {
2424
handle = this._handle;
2525
assert.strictEqual(s.send('one', handle), true);
2626
assert.strictEqual(s.send('two', handle), true);

test/parallel/test-child-process-spawn-shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const cp = require('child_process');
77
const doesNotExist = cp.spawn('does-not-exist', {shell: true});
88

99
assert.notStrictEqual(doesNotExist.spawnfile, 'does-not-exist');
10-
doesNotExist.on('error', common.fail);
10+
doesNotExist.on('error', common.mustNotCall());
1111
doesNotExist.on('exit', common.mustCall((code, signal) => {
1212
assert.strictEqual(signal, null);
1313

0 commit comments

Comments
 (0)