@@ -28,10 +28,7 @@ const { execFileSync, execSync, spawnSync } = require('child_process');
2828const TIMER = 200 ;
2929const SLEEP = 2000 ;
3030
31- const start = Date . now ( ) ;
3231const execOpts = { encoding : 'utf8' , shell : true } ;
33- let err ;
34- let caught = false ;
3532
3633// Verify that stderr is not accessed when a bad shell is used
3734assert . throws (
@@ -43,9 +40,11 @@ assert.throws(
4340 / s p a w n S y n c b a d _ s h e l l E N O E N T /
4441) ;
4542
46- let cmd , ret ;
43+ let caught = false ;
44+ let ret , err ;
45+ const start = Date . now ( ) ;
4746try {
48- cmd = `"${ process . execPath } " -e "setTimeout(function(){}, ${ SLEEP } );"` ;
47+ const cmd = `"${ process . execPath } " -e "setTimeout(function(){}, ${ SLEEP } );"` ;
4948 ret = execSync ( cmd , { timeout : TIMER } ) ;
5049} catch ( e ) {
5150 caught = true ;
@@ -69,28 +68,32 @@ const msgBuf = Buffer.from(`${msg}\n`);
6968
7069// console.log ends every line with just '\n', even on Windows.
7170
72- cmd = `"${ process . execPath } " -e "console.log('${ msg } ');"` ;
71+ const cmd = `"${ process . execPath } " -e "console.log('${ msg } ');"` ;
7372
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+ }
8078
81- assert . strictEqual ( ret , `${ msg } \n` ) ;
79+ {
80+ const ret = execSync ( cmd , { encoding : 'utf8' } ) ;
81+ assert . strictEqual ( ret , `${ msg } \n` ) ;
82+ }
8283
8384const args = [
8485 '-e' ,
8586 `console.log("${ msg } ");`
8687] ;
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+ }
9292
93- assert . strictEqual ( ret , `${ msg } \n` ) ;
93+ {
94+ const ret = execFileSync ( process . execPath , args , { encoding : 'utf8' } ) ;
95+ assert . strictEqual ( ret , `${ msg } \n` ) ;
96+ }
9497
9598// Verify that the cwd option works.
9699// See https://github.com/nodejs/node-v0.x-archive/issues/7824.
@@ -133,10 +136,11 @@ assert.strictEqual(ret, `${msg}\n`);
133136 assert . strictEqual ( err . message , msg ) ;
134137 assert . strictEqual ( err . status , 1 ) ;
135138 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+ } ) ;
140144 return true ;
141145 } ) ;
142146}
0 commit comments