@@ -130,6 +130,7 @@ t.test('exec commands', async t => {
130130 )
131131 t . equal ( REIFY_CALLED , true , 'called reify' )
132132 t . strictSame ( SCRIPTS , [ ] , 'no scripts when installing globally' )
133+ t . equal ( npm . config . get ( 'audit' , 'cli' ) , false )
133134 } )
134135
135136 await t . test ( 'should not install invalid global package name' , async t => {
@@ -327,3 +328,44 @@ t.test('completion', async t => {
327328 t . strictSame ( res , [ ] )
328329 } )
329330} )
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+ } )
0 commit comments