Skip to content

Commit 714cbfd

Browse files
JonathanPrinceFishrock123
authored andcommitted
test: update test-child-process-recv-handle
change var to const/let where appropriate use strictEqual instead of equal call toString on buffers in strictEqual asserts use common.mustCall on callbacks containing asserts PR-URL: #8648 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent c664109 commit 714cbfd

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Test that a Linux specific quirk in the handle passing protocol is handled
33
// correctly. See https://github.com/joyent/node/issues/5330 for details.
44

5-
var common = require('../common');
6-
var assert = require('assert');
7-
var net = require('net');
8-
var spawn = require('child_process').spawn;
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const net = require('net');
8+
const spawn = require('child_process').spawn;
99

1010
if (process.argv[2] === 'worker')
1111
worker();
@@ -15,49 +15,48 @@ else
1515
function master() {
1616
// spawn() can only create one IPC channel so we use stdin/stdout as an
1717
// ad-hoc command channel.
18-
var proc = spawn(process.execPath, [__filename, 'worker'], {
18+
const proc = spawn(process.execPath, [__filename, 'worker'], {
1919
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
2020
});
21-
var handle = null;
22-
proc.on('exit', function() {
21+
let handle = null;
22+
proc.on('exit', () => {
2323
handle.close();
2424
});
25-
proc.stdout.on('data', function(data) {
26-
assert.equal(data, 'ok\r\n');
25+
proc.stdout.on('data', common.mustCall((data) => {
26+
assert.strictEqual(data.toString(), 'ok\r\n');
2727
net.createServer(common.fail).listen(0, function() {
2828
handle = this._handle;
2929
proc.send('one');
3030
proc.send('two', handle);
3131
proc.send('three');
3232
proc.stdin.write('ok\r\n');
3333
});
34-
});
34+
}));
3535
proc.stderr.pipe(process.stderr);
3636
}
3737

3838
function worker() {
3939
process._channel.readStop(); // Make messages batch up.
4040
process.stdout.ref();
4141
process.stdout.write('ok\r\n');
42-
process.stdin.once('data', function(data) {
43-
assert.equal(data, 'ok\r\n');
42+
process.stdin.once('data', common.mustCall((data) => {
43+
assert.strictEqual(data.toString(), 'ok\r\n');
4444
process._channel.readStart();
45-
});
46-
var n = 0;
47-
process.on('message', function(msg, handle) {
45+
}));
46+
let n = 0;
47+
process.on('message', common.mustCall((msg, handle) => {
4848
n += 1;
4949
if (n === 1) {
50-
assert.equal(msg, 'one');
51-
assert.equal(handle, undefined);
50+
assert.strictEqual(msg, 'one');
51+
assert.strictEqual(handle, undefined);
5252
} else if (n === 2) {
53-
assert.equal(msg, 'two');
54-
assert.equal(typeof handle, 'object'); // Also matches null, therefore...
55-
assert.ok(handle); // also check that it's truthy.
53+
assert.strictEqual(msg, 'two');
54+
assert.ok(handle !== null && typeof handle === 'object');
5655
handle.close();
5756
} else if (n === 3) {
58-
assert.equal(msg, 'three');
59-
assert.equal(handle, undefined);
57+
assert.strictEqual(msg, 'three');
58+
assert.strictEqual(handle, undefined);
6059
process.exit();
6160
}
62-
});
61+
}, 3));
6362
}

0 commit comments

Comments
 (0)