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‎

Lines changed: 3 additions & 2 deletions
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+
varchild;
910
if(common.isWindows){
10-
varchild=spawn('cmd.exe',['/c','set'],{});
11+
child=spawn('cmd.exe',['/c','set'],{});
1112
}else{
12-
varchild=spawn('/usr/bin/env',[],{});
13+
child=spawn('/usr/bin/env',[],{});
1314
}
1415

1516
varresponse='';

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

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

14+
varchild;
1415
if(common.isWindows){
15-
varchild=spawn('cmd.exe',['/c','set'],{env: env});
16+
child=spawn('cmd.exe',['/c','set'],{env: env});
1617
}else{
17-
varchild=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‎

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

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

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ var assert = require('assert');
44
varchildProcess=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-
}elseif(process.argv[2]==='ipctest'){
11+
}elseif(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
}elseif(process.argv[2]==='parent'){
1919
// Parent | start child pipe test
2020

21-
varchild=childProcess.fork(process.argv[1],['pipetest'],{silent: true});
21+
constchild=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-
varchild=childProcess.fork(process.argv[1],['ipctest'],{silent: true});
49+
constchild=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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function parent(){
3636

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

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Flags: --expose_internals
33

44
require('../common');
5-
varassert=require('assert');
6-
var_validateStdio=require('internal/child_process')._validateStdio;
5+
constassert=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
},/Incorrectvalueofstdiooption/);
1717

1818
// should populate stdio with undefined if len < 3
19-
varstdio1=[];
20-
varresult=_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+
conststdio1=[];
21+
constresult=_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-
varstdio2=['ipc','ipc','ipc'];
29+
conststdio2=['ipc','ipc','ipc'];
2830
assert.throws(function(){
2931
_validateStdio(stdio2,true);
3032
},/YoucannotuseIPCwithsynchronousforks/);
3133

32-
conststdio3=[process.stdin,process.stdout,process.stderr];
33-
varresult=_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+
conststdio3=[process.stdin,process.stdout,process.stderr];
36+
constresult=_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)