@@ -11,27 +11,32 @@ const patchPackage = require('../lib/package.js')
1111
1212spawk . preventUnmatched ( )
1313
14- t . test ( 'when npm_package_json is unset logs stack and sets exitCode ' , async ( t ) => {
14+ t . test ( 'when npm_config_global is true, does nothing ' , async ( t ) => {
1515 // this is set by virtue of running tests with npm, save it and remove it
16- const _env = process . env . npm_package_json
17- delete process . env . npm_package_json
16+ const _env = process . env . npm_config_global
17+ delete process . env . npm_config_global
1818
19- const _error = console . error
20- const logs = [ ]
21- console . error = ( ...args ) => {
22- logs . push ( ...args )
23- }
19+ t . teardown ( ( ) => {
20+ process . env . npm_config_global = _env
21+ } )
22+
23+ // t.mock instead of require so the cache doesn't interfere
24+ await t . mock ( '../bin/postinstall.js' )
25+ t . equal ( process . exitCode , undefined , 'exitCode is unset' )
26+ } )
27+
28+ t . test ( 'when npm_config_local_prefix is unset, does nothing' , async ( t ) => {
29+ // this is set by virtue of running tests with npm, save it and remove it
30+ const _env = process . env . npm_config_local_prefix
31+ delete process . env . npm_config_local_prefix
2432
2533 t . teardown ( ( ) => {
26- process . env . npm_package_json = _env
27- console . error = _error
28- process . exitCode = undefined // yes, really
34+ process . env . npm_config_local_prefix = _env
2935 } )
3036
3137 // t.mock instead of require so the cache doesn't interfere
3238 await t . mock ( '../bin/postinstall.js' )
33- t . match ( logs [ 0 ] , / m u s t b e r u n / , 'logged the error' )
34- t . equal ( process . exitCode , 1 , 'set process.exitCode' )
39+ t . equal ( process . exitCode , undefined , 'exitCode is unset' )
3540} )
3641
3742t . test ( 'when patchPackage returns false no further action is taken' , async ( t ) => {
@@ -47,11 +52,14 @@ t.test('when patchPackage returns false no further action is taken', async (t) =
4752 'package.json' : JSON . stringify ( pkg , null , 2 ) ,
4853 } ) )
4954
50- const _env = process . env . npm_package_json
51- process . env . npm_package_json = join ( root , 'package.json' )
55+ const _global = process . env . npm_config_global
56+ const _prefix = process . env . npm_config_local_prefix
57+ delete process . env . npm_config_global
58+ process . env . npm_config_local_prefix = root
5259
5360 t . teardown ( ( ) => {
54- process . env . npm_package_json = _env
61+ process . env . npm_config_global = _global
62+ process . env . npm_config_local_prefix = _prefix
5563 } )
5664
5765 // t.mock instead of require so the cache doesn't interfere
@@ -76,11 +84,14 @@ t.test('sets up a new project', async (t) => {
7684 'package.json' : JSON . stringify ( pkg , null , 2 ) ,
7785 } ) )
7886
79- const _env = process . env . npm_package_json
80- process . env . npm_package_json = join ( root , 'package.json' )
87+ const _global = process . env . npm_config_global
88+ const _prefix = process . env . npm_config_local_prefix
89+ delete process . env . npm_config_global
90+ process . env . npm_config_local_prefix = root
8191
8292 t . teardown ( ( ) => {
83- process . env . npm_package_json = _env
93+ process . env . npm_config_global = _global
94+ process . env . npm_config_local_prefix = _prefix
8495 } )
8596
8697 const uninstall = spawk . spawn ( 'npm' , ( args ) => {
0 commit comments