@@ -21,11 +21,8 @@ function exec(bin, opts = {}) {
2121 ...opts . env ,
2222 } ;
2323 const args = opts . args || [ ] ;
24- if ( process . platform === 'win32' ) {
25- args . unshift ( bin ) ;
26- [ bin ] = process . argv ;
27- }
28- const c = spawn ( bin , args , {
24+ args . unshift ( ...process . execArgv , bin ) ;
25+ const c = spawn ( process . execPath , args , {
2926 stdio : 'pipe' ,
3027 env,
3128 } ) ;
@@ -45,13 +42,14 @@ function exec(bin, opts = {}) {
4542 reject ( err ) ;
4643 }
4744 } ) ;
48- if ( opts . stdin != null ) {
49- c . stdin . write ( opts . stdin ) ;
50- }
51- c . stdin . end ( ) ;
45+ c . stdin . end ( opts . stdin ) ;
5246 } ) ;
5347}
5448
49+ const env = {
50+ NODE_REPL_HISTORY : '' ,
51+ } ;
52+
5553test ( 'json2cbor' , async t => {
5654 let buf = await exec ( 'json2cbor' , {
5755 stdin : '{"foo": false}' ,
@@ -140,10 +138,9 @@ test('cbor2comment', async t => {
140138test ( 'cbor' , async t => {
141139 let buf = await exec ( t . title , {
142140 stdin : 'true' ,
143- env : {
144- NODE_REPL_HISTORY : '' ,
145- } ,
141+ env,
146142 } ) ;
143+
147144 // I might leave this in for a while to ensure that we're running the cbor
148145 // version I think we should be in CI.
149146 console . log ( 'cli VERSION:' , buf ) ;
@@ -152,77 +149,59 @@ test('cbor', async t => {
152149
153150 await t . throwsAsync ( ( ) => exec ( t . title , {
154151 args : [ '-t' , 'foo' ] ,
155- env : {
156- NODE_REPL_HISTORY : '' ,
157- } ,
152+ env,
158153 } ) ) ;
159154
160155 buf = await exec ( t . title , {
161156 args : [ '-t' , 'diag' , '-c' ] ,
162157 stdin : '0x818100' ,
163- env : {
164- NODE_REPL_HISTORY : '' ,
165- } ,
158+ env,
166159 } ) ;
167160 t . regex ( buf , / \[ \[ 0 \] \] \n / ) ;
168161
169162 buf = await exec ( t . title , {
170163 args : [ '-t' , 'comment' , '-c' ] ,
171164 stdin : '0x818100' ,
172- env : {
173- NODE_REPL_HISTORY : '' ,
174- } ,
165+ env,
175166 } ) ;
176167 t . regex ( buf , / A r r a y , 1 i t e m / ) ;
177168
178169 buf = await exec ( t . title , {
179170 args : [ '-t' , 'js' ] ,
180171 stdin : '0xa1616101' ,
181- env : {
182- NODE_REPL_HISTORY : '' ,
183- } ,
172+ env,
184173 } ) ;
185174 t . regex ( buf , / a : 1 \n / ) ;
186175 buf = await exec ( t . title , {
187176 stdin : 'comment("01")' ,
188- env : {
189- NODE_REPL_HISTORY : '' ,
190- } ,
177+ env,
191178 } ) ;
192179 t . regex ( buf , / P r o m i s e / ) ;
193180 t . regex ( buf , / 0 x 0 1 / ) ;
194181 buf = await exec ( t . title , {
195182 stdin : 'diagnose("01")' ,
196- env : {
197- NODE_REPL_HISTORY : '' ,
198- } ,
183+ env,
199184 } ) ;
200185 t . regex ( buf , / P r o m i s e \n 1 \n / ) ;
201186
202187 buf = await exec ( t . title , {
203188 args : [ '-t' , 'd' ] ,
204189 stdin : '0x81' ,
205- env : {
206- NODE_REPL_HISTORY : '' ,
207- } ,
190+ env,
208191 } ) ;
209192 t . regex ( buf , / E r r o r : u n e x p e c t e d e n d o f i n p u t / ) ;
210193
211194 buf = await exec ( t . title , {
212195 args : [ '-t' , 'c' ] ,
213196 stdin : '0x81' ,
214- env : {
215- NODE_REPL_HISTORY : '' ,
216- } ,
197+ env,
217198 } ) ;
218199 t . regex ( buf , / E r r o r : u n e x p e c t e d e n d o f i n p u t / ) ;
219200
220201 buf = await exec ( t . title , {
221202 args : [ '-t' , 'javascript' ] ,
222203 stdin : '0x81' ,
223- env : {
224- NODE_REPL_HISTORY : '' ,
225- } ,
204+ env,
226205 } ) ;
227206 t . regex ( buf , / E r r o r : u n e x p e c t e d e n d o f i n p u t / ) ;
228207} ) ;
0 commit comments