@@ -28,10 +28,7 @@ const { execFileSync, execSync, spawnSync } = require('child_process');
28
28
const TIMER = 200 ;
29
29
const SLEEP = 2000 ;
30
30
31
- const start = Date . now ( ) ;
32
31
const execOpts = { encoding : 'utf8' , shell : true } ;
33
- let err ;
34
- let caught = false ;
35
32
36
33
// Verify that stderr is not accessed when a bad shell is used
37
34
assert . throws (
@@ -43,9 +40,11 @@ assert.throws(
43
40
/ s p a w n S y n c b a d _ s h e l l E N O E N T /
44
41
) ;
45
42
46
- let cmd , ret ;
43
+ let caught = false ;
44
+ let ret , err ;
45
+ const start = Date . now ( ) ;
47
46
try {
48
- cmd = `"${ process . execPath } " -e "setTimeout(function(){}, ${ SLEEP } );"` ;
47
+ const cmd = `"${ process . execPath } " -e "setTimeout(function(){}, ${ SLEEP } );"` ;
49
48
ret = execSync ( cmd , { timeout : TIMER } ) ;
50
49
} catch ( e ) {
51
50
caught = true ;
@@ -69,28 +68,32 @@ const msgBuf = Buffer.from(`${msg}\n`);
69
68
70
69
// console.log ends every line with just '\n', even on Windows.
71
70
72
- cmd = `"${ process . execPath } " -e "console.log('${ msg } ');"` ;
71
+ const cmd = `"${ process . execPath } " -e "console.log('${ msg } ');"` ;
73
72
74
- ret = execSync ( cmd ) ;
75
-
76
- assert . strictEqual ( ret . length , msgBuf . length ) ;
77
- assert . deepStrictEqual ( ret , msgBuf ) ;
78
-
79
- ret = execSync ( cmd , { encoding : 'utf8' } ) ;
73
+ {
74
+ const ret = execSync ( cmd ) ;
75
+ assert . strictEqual ( ret . length , msgBuf . length ) ;
76
+ assert . deepStrictEqual ( ret , msgBuf ) ;
77
+ }
80
78
81
- assert . strictEqual ( ret , `${ msg } \n` ) ;
79
+ {
80
+ const ret = execSync ( cmd , { encoding : 'utf8' } ) ;
81
+ assert . strictEqual ( ret , `${ msg } \n` ) ;
82
+ }
82
83
83
84
const args = [
84
85
'-e' ,
85
86
`console.log("${ msg } ");`
86
87
] ;
87
- ret = execFileSync ( process . execPath , args ) ;
88
-
89
- assert . deepStrictEqual ( ret , msgBuf ) ;
90
-
91
- ret = execFileSync ( process . execPath , args , { encoding : 'utf8' } ) ;
88
+ {
89
+ const ret = execFileSync ( process . execPath , args ) ;
90
+ assert . deepStrictEqual ( ret , msgBuf ) ;
91
+ }
92
92
93
- assert . strictEqual ( ret , `${ msg } \n` ) ;
93
+ {
94
+ const ret = execFileSync ( process . execPath , args , { encoding : 'utf8' } ) ;
95
+ assert . strictEqual ( ret , `${ msg } \n` ) ;
96
+ }
94
97
95
98
// Verify that the cwd option works.
96
99
// See https://github.com/nodejs/node-v0.x-archive/issues/7824.
@@ -133,10 +136,11 @@ assert.strictEqual(ret, `${msg}\n`);
133
136
assert . strictEqual ( err . message , msg ) ;
134
137
assert . strictEqual ( err . status , 1 ) ;
135
138
assert . strictEqual ( typeof err . pid , 'number' ) ;
136
- spawnSyncKeys . forEach ( ( key ) => {
137
- if ( key === 'pid' ) return ;
138
- assert . deepStrictEqual ( err [ key ] , spawnSyncResult [ key ] ) ;
139
- } ) ;
139
+ spawnSyncKeys
140
+ . filter ( ( key ) => key !== 'pid' )
141
+ . forEach ( ( key ) => {
142
+ assert . deepStrictEqual ( err [ key ] , spawnSyncResult [ key ] ) ;
143
+ } ) ;
140
144
return true ;
141
145
} ) ;
142
146
}
0 commit comments