@@ -198,30 +198,69 @@ t.test('npm exec foo, already present locally', async t => {
198
198
} )
199
199
200
200
t . test ( 'npm exec <noargs>, run interactive shell' , async t => {
201
- ARB_CTOR . length = 0
202
- MKDIRPS . length = 0
203
- ARB_REIFY . length = 0
204
- OUTPUT . length = 0
205
- await exec ( [ ] , er => {
206
- if ( er )
207
- throw er
201
+ CI_NAME = null
202
+ const { isTTY } = process . stdin
203
+ process . stdin . isTTY = true
204
+ t . teardown ( ( ) => process . stdin . isTTY = isTTY )
205
+
206
+ const run = async ( t , doRun = true ) => {
207
+ LOG_WARN . length = 0
208
+ ARB_CTOR . length = 0
209
+ MKDIRPS . length = 0
210
+ ARB_REIFY . length = 0
211
+ OUTPUT . length = 0
212
+ await exec ( [ ] , er => {
213
+ if ( er )
214
+ throw er
215
+ } )
216
+ t . strictSame ( MKDIRPS , [ ] , 'no need to make any dirs' )
217
+ t . strictSame ( ARB_CTOR , [ ] , 'no need to instantiate arborist' )
218
+ t . strictSame ( ARB_REIFY , [ ] , 'no need to reify anything' )
219
+ t . equal ( PROGRESS_ENABLED , true , 'progress re-enabled' )
220
+ if ( doRun ) {
221
+ t . match ( RUN_SCRIPTS , [ {
222
+ pkg : { scripts : { npx : 'shell-cmd' } } ,
223
+ banner : false ,
224
+ path : process . cwd ( ) ,
225
+ stdioString : true ,
226
+ event : 'npx' ,
227
+ env : { PATH : process . env . PATH } ,
228
+ stdio : 'inherit' ,
229
+ } ] )
230
+ } else
231
+ t . strictSame ( RUN_SCRIPTS , [ ] )
232
+ RUN_SCRIPTS . length = 0
233
+ }
234
+
235
+ t . test ( 'print message when tty and not in CI' , async t => {
236
+ CI_NAME = null
237
+ process . stdin . isTTY = true
238
+ await run ( t )
239
+ t . strictSame ( LOG_WARN , [ ] )
240
+ t . strictSame ( OUTPUT , [
241
+ [ '\nEntering npm script environment\nType \'exit\' or ^D when finished\n' ] ,
242
+ ] , 'printed message about interactive shell' )
208
243
} )
209
- t . strictSame ( OUTPUT , [
210
- [ '\nEntering npm script environment\nType \'exit\' or ^D when finished\n' ] ,
211
- ] , 'printed message about interactive shell' )
212
- t . strictSame ( MKDIRPS , [ ] , 'no need to make any dirs' )
213
- t . strictSame ( ARB_CTOR , [ ] , 'no need to instantiate arborist' )
214
- t . strictSame ( ARB_REIFY , [ ] , 'no need to reify anything' )
215
- t . equal ( PROGRESS_ENABLED , true , 'progress re-enabled' )
216
- t . match ( RUN_SCRIPTS , [ {
217
- pkg : { scripts : { npx : 'shell-cmd' } } ,
218
- banner : false ,
219
- path : process . cwd ( ) ,
220
- stdioString : true ,
221
- event : 'npx' ,
222
- env : { PATH : process . env . PATH } ,
223
- stdio : 'inherit' ,
224
- } ] )
244
+
245
+ t . test ( 'no message when not TTY' , async t => {
246
+ CI_NAME = null
247
+ process . stdin . isTTY = false
248
+ await run ( t )
249
+ t . strictSame ( LOG_WARN , [ ] )
250
+ t . strictSame ( OUTPUT , [ ] , 'no message about interactive shell' )
251
+ } )
252
+
253
+ t . test ( 'print warning when in CI and interactive' , async t => {
254
+ CI_NAME = 'travis-ci'
255
+ process . stdin . isTTY = true
256
+ await run ( t , false )
257
+ t . strictSame ( LOG_WARN , [
258
+ [ 'exec' , 'Interactive mode disabled in CI environment' ] ,
259
+ ] )
260
+ t . strictSame ( OUTPUT , [ ] , 'no message about interactive shell' )
261
+ } )
262
+
263
+ t . end ( )
225
264
} )
226
265
227
266
t . test ( 'npm exec foo, not present locally or in central loc' , async t => {
0 commit comments