@@ -9,16 +9,16 @@ jest.mock('mkdirp');
9
9
10
10
describe ( 'common' , ( ) => {
11
11
describe ( 'getInstallationPath()' , ( ) => {
12
- let callback , env ;
12
+ let callback , _process ;
13
13
14
14
beforeEach ( ( ) => {
15
15
callback = jest . fn ( ) ;
16
16
17
- env = { ...process . env } ;
17
+ _process = { ...global . process , env : { ... process . env } } ;
18
18
} ) ;
19
19
20
20
afterEach ( ( ) => {
21
- process . env = env ;
21
+ global . process = _process ;
22
22
} ) ;
23
23
24
24
it ( 'should get binaries path from `npm bin`' , ( ) => {
@@ -29,9 +29,21 @@ describe('common', () => {
29
29
expect ( callback ) . toHaveBeenCalledWith ( null , path . sep + path . join ( 'usr' , 'local' , 'bin' ) ) ;
30
30
} ) ;
31
31
32
- it ( 'should get binaries path from env' , ( ) => {
32
+ it ( 'should get binaries path from env on windows platform' , ( ) => {
33
+ childProcess . exec . mockImplementationOnce ( ( _cmd , cb ) => cb ( new Error ( ) ) ) ;
34
+
35
+ process . platform = 'win32' ;
36
+ process . env . npm_config_prefix = String . raw `C:\Users\John Smith\AppData\npm` ;
37
+
38
+ common . getInstallationPath ( callback ) ;
39
+
40
+ expect ( callback ) . toHaveBeenCalledWith ( null , path . win32 . join ( 'C:' , 'Users' , 'John Smith' , 'AppData' , 'npm' ) ) ;
41
+ } ) ;
42
+
43
+ it ( 'should get binaries path from env on platform different than windows' , ( ) => {
33
44
childProcess . exec . mockImplementationOnce ( ( _cmd , cb ) => cb ( new Error ( ) ) ) ;
34
45
46
+ process . platform = 'linux' ;
35
47
process . env . npm_config_prefix = '/usr/local' ;
36
48
37
49
common . getInstallationPath ( callback ) ;
0 commit comments