Skip to content

Commit 48a353f

Browse files
Trottrvagg
authored andcommitted
test: scope redeclared vars in test-child-process*
A handful of child process tests had variables declared multiple times in the same scope using `var`. This change scopes those declarations. PR-URL: #4944 Reviewed-By: Michaël Zasso <[email protected]>
1 parent c09eb44 commit 48a353f

6 files changed

+37
-32
lines changed

test/parallel/test-child-process-default-options.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ var spawn = require('child_process').spawn;
66

77
process.env.HELLO = 'WORLD';
88

9+
var child;
910
if (common.isWindows) {
10-
var child = spawn('cmd.exe', ['/c', 'set'], {});
11+
child = spawn('cmd.exe', ['/c', 'set'], {});
1112
} else {
12-
var child = spawn('/usr/bin/env', [], {});
13+
child = spawn('/usr/bin/env', [], {});
1314
}
1415

1516
var response = '';

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ env.__proto__ = {
1111
'FOO': 'BAR'
1212
};
1313

14+
var child;
1415
if (common.isWindows) {
15-
var child = spawn('cmd.exe', ['/c', 'set'], {env: env});
16+
child = spawn('cmd.exe', ['/c', 'set'], {env: env});
1617
} else {
17-
var child = spawn('/usr/bin/env', [], {env: env});
18+
child = spawn('/usr/bin/env', [], {env: env});
1819
}
1920

2021

test/parallel/test-child-process-fork-dgram.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ if (common.isWindows) {
2424
return;
2525
}
2626

27+
var server;
2728
if (process.argv[2] === 'child') {
28-
var server;
29-
3029
process.on('message', function removeMe(msg, clusterServer) {
3130
if (msg === 'server') {
3231
server = clusterServer;
@@ -42,7 +41,7 @@ if (process.argv[2] === 'child') {
4241
});
4342

4443
} else {
45-
var server = dgram.createSocket('udp4');
44+
server = dgram.createSocket('udp4');
4645
var client = dgram.createSocket('udp4');
4746
var child = fork(__filename, ['child']);
4847

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ var assert = require('assert');
44
var childProcess = require('child_process');
55

66
// Child pipe test
7-
if (process.argv[2] === 'pipetest') {
7+
if (process.argv[2] === 'pipe') {
88
process.stdout.write('stdout message');
99
process.stderr.write('stderr message');
1010

11-
} else if (process.argv[2] === 'ipctest') {
11+
} else if (process.argv[2] === 'ipc') {
1212
// Child IPC test
1313
process.send('message from child');
1414
process.on('message', function() {
@@ -18,7 +18,7 @@ if (process.argv[2] === 'pipetest') {
1818
} else if (process.argv[2] === 'parent') {
1919
// Parent | start child pipe test
2020

21-
var child = childProcess.fork(process.argv[1], ['pipetest'], {silent: true});
21+
const child = childProcess.fork(process.argv[1], ['pipe'], {silent: true});
2222

2323
// Allow child process to self terminate
2424
child._channel.close();
@@ -46,7 +46,7 @@ if (process.argv[2] === 'pipetest') {
4646
});
4747

4848
// testing: do message system work when using silent
49-
var child = childProcess.fork(process.argv[1], ['ipctest'], {silent: true});
49+
const child = childProcess.fork(process.argv[1], ['ipc'], {silent: true});
5050

5151
// Manual pipe so we will get errors
5252
child.stderr.pipe(process.stderr, {end: false});

test/parallel/test-child-process-stdio-big-write-end.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function parent() {
3636

3737
// then write a bunch more times.
3838
for (var i = 0; i < 100; i++) {
39-
var buf = new Buffer(BUFSIZE);
39+
const buf = new Buffer(BUFSIZE);
4040
buf.fill('.');
4141
sent += BUFSIZE;
4242
child.stdin.write(buf);

test/parallel/test-child-process-validate-stdio.js

+24-20
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Flags: --expose_internals
33

44
require('../common');
5-
var assert = require('assert');
6-
var _validateStdio = require('internal/child_process')._validateStdio;
5+
const assert = require('assert');
6+
const _validateStdio = require('internal/child_process')._validateStdio;
77

88
// should throw if string and not ignore, pipe, or inherit
99
assert.throws(function() {
@@ -16,27 +16,31 @@ assert.throws(function() {
1616
}, /Incorrect value of stdio option/);
1717

1818
// should populate stdio with undefined if len < 3
19-
var stdio1 = [];
20-
var result = _validateStdio(stdio1, false);
21-
assert.equal(stdio1.length, 3);
22-
assert.equal(result.hasOwnProperty('stdio'), true);
23-
assert.equal(result.hasOwnProperty('ipc'), true);
24-
assert.equal(result.hasOwnProperty('ipcFd'), true);
19+
{
20+
const stdio1 = [];
21+
const result = _validateStdio(stdio1, false);
22+
assert.equal(stdio1.length, 3);
23+
assert.equal(result.hasOwnProperty('stdio'), true);
24+
assert.equal(result.hasOwnProperty('ipc'), true);
25+
assert.equal(result.hasOwnProperty('ipcFd'), true);
26+
}
2527

2628
// should throw if stdio has ipc and sync is true
27-
var stdio2 = ['ipc', 'ipc', 'ipc'];
29+
const stdio2 = ['ipc', 'ipc', 'ipc'];
2830
assert.throws(function() {
2931
_validateStdio(stdio2, true);
3032
}, /You cannot use IPC with synchronous forks/);
3133

32-
const stdio3 = [process.stdin, process.stdout, process.stderr];
33-
var result = _validateStdio(stdio3, false);
34-
assert.deepStrictEqual(result, {
35-
stdio: [
36-
{ type: 'fd', fd: 0 },
37-
{ type: 'fd', fd: 1 },
38-
{ type: 'fd', fd: 2 }
39-
],
40-
ipc: undefined,
41-
ipcFd: undefined
42-
});
34+
{
35+
const stdio3 = [process.stdin, process.stdout, process.stderr];
36+
const result = _validateStdio(stdio3, false);
37+
assert.deepStrictEqual(result, {
38+
stdio: [
39+
{ type: 'fd', fd: 0 },
40+
{ type: 'fd', fd: 1 },
41+
{ type: 'fd', fd: 2 }
42+
],
43+
ipc: undefined,
44+
ipcFd: undefined
45+
});
46+
}

0 commit comments

Comments
 (0)