@@ -130,6 +130,7 @@ t.test('exec commands', async t => {
130
130
)
131
131
t . equal ( REIFY_CALLED , true , 'called reify' )
132
132
t . strictSame ( SCRIPTS , [ ] , 'no scripts when installing globally' )
133
+ t . equal ( npm . config . get ( 'audit' , 'cli' ) , false )
133
134
} )
134
135
135
136
await t . test ( 'should not install invalid global package name' , async t => {
@@ -327,3 +328,77 @@ t.test('completion', async t => {
327
328
t . strictSame ( res , [ ] )
328
329
} )
329
330
} )
331
+
332
+ t . test ( 'location detection and audit' , async ( ) => {
333
+ t . test ( 'audit false without package.json' , async t => {
334
+ const { npm } = await _loadMockNpm ( t , {
335
+ prefixDir : {
336
+ // no package.json
337
+ 'readme.txt' : 'just a file' ,
338
+ other : { } ,
339
+ } ,
340
+ } )
341
+ const install = await npm . cmd ( 'install' )
342
+ t . equal ( install . npm . config . get ( 'location' ) , 'user' )
343
+ t . equal ( install . npm . config . get ( 'audit' ) , false )
344
+ } )
345
+ t . test ( 'audit true with package.json' , async t => {
346
+ const { npm } = await _loadMockNpm ( t , {
347
+ prefixDir : {
348
+ 'package.json' : '{ "name": "testpkg", "version": "1.0.0" }' ,
349
+ 'readme.txt' : 'just a file' ,
350
+ } ,
351
+ } )
352
+ const install = await npm . cmd ( 'install' )
353
+ t . equal ( install . npm . config . get ( 'location' ) , 'project' )
354
+ t . equal ( install . npm . config . get ( 'audit' ) , true )
355
+ } )
356
+ t . test ( 'audit true without package.json when set' , async t => {
357
+ const { npm } = await _loadMockNpm ( t , {
358
+ prefixDir : {
359
+ // no package.json
360
+ 'readme.txt' : 'just a file' ,
361
+ other : { } ,
362
+ } ,
363
+ config : {
364
+ audit : { value : true , where : 'cli' } ,
365
+ } ,
366
+ } )
367
+ const install = await npm . cmd ( 'install' )
368
+ t . equal ( install . npm . config . get ( 'location' ) , 'user' )
369
+ t . equal ( install . npm . config . get ( 'audit' ) , true )
370
+ } )
371
+ t . test ( 'audit true in root config without package.json' , async t => {
372
+ const { npm } = await _loadMockNpm ( t , {
373
+ prefixDir : {
374
+ // no package.json
375
+ 'readme.txt' : 'just a file' ,
376
+ other : { } ,
377
+ } ,
378
+ config : {
379
+ audit : { value : true , where : 'builtin' } ,
380
+ } ,
381
+ } )
382
+ const install = await npm . cmd ( 'install' )
383
+ t . equal ( install . npm . config . get ( 'location' ) , 'user' )
384
+ t . equal ( install . npm . config . get ( 'audit' ) , true )
385
+ } )
386
+ t . test ( 'test for warning when --global & --audit' , async t => {
387
+ const { npm, logs } = await _loadMockNpm ( t , {
388
+ prefixDir : {
389
+ // no package.json
390
+ 'readme.txt' : 'just a file' ,
391
+ other : { } ,
392
+ } ,
393
+ config : {
394
+ audit : { value : true , where : 'cli' } ,
395
+ global : { value : true , where : 'cli' } ,
396
+ } ,
397
+ } )
398
+ const install = await npm . cmd ( 'install' )
399
+ t . equal ( install . npm . config . get ( 'location' ) , 'user' )
400
+ t . equal ( install . npm . config . get ( 'audit' ) , true )
401
+ t . equal ( logs . warn [ 0 ] [ 0 ] , 'config' )
402
+ t . equal ( logs . warn [ 0 ] [ 1 ] , 'includes both --global and --audit, which is currently unsupported.' )
403
+ } )
404
+ } )
0 commit comments