44 */
55
66import assert from 'assert'
7- import { mergeResolvedShellPath } from '../../../shared/env/resolveEnv'
7+ import * as resolveEnv from '../../../shared/env/resolveEnv'
88import sinon from 'sinon'
9+ import path from 'path'
910
1011describe ( 'resolveEnv' , async function ( ) {
1112 let sandbox : sinon . SinonSandbox
@@ -18,26 +19,51 @@ describe('resolveEnv', async function () {
1819 sandbox . restore ( )
1920 } )
2021
22+ // a copy of resolveEnv.mergeResolvedShellPath for stubbing
23+ const testMergeResolveShellPath = async function mergeResolvedShellPath (
24+ env : resolveEnv . IProcessEnvironment
25+ ) : Promise < typeof process . env > {
26+ const shellEnv = await resolveEnv . getResolvedShellEnv ( env )
27+ // resolve failed or doesn't need to resolve
28+ if ( ! shellEnv || Object . keys ( shellEnv ) . length === 0 ) {
29+ return env
30+ }
31+ try {
32+ const envPaths : string [ ] = env . PATH ? env . PATH . split ( path . delimiter ) : [ ]
33+ const resolvedPaths : string [ ] = shellEnv . PATH ? shellEnv . PATH . split ( path . delimiter ) : [ ]
34+ const envReturn = { ...env }
35+ // merge, dedup, join
36+ envReturn . PATH = [ ...new Set ( envPaths . concat ( resolvedPaths ) ) ] . join ( path . delimiter )
37+
38+ return envReturn
39+ } catch ( err ) {
40+ return env
41+ }
42+ }
43+
2144 describe ( 'resolveWindows' , async function ( ) {
2245 beforeEach ( function ( ) {
2346 sandbox . stub ( process , 'platform' ) . value ( 'win32' )
2447 } )
2548
2649 it ( 'mergeResolvedShellPath should not change path on windows' , async function ( ) {
27- const env = await mergeResolvedShellPath ( process . env )
50+ const env = await resolveEnv . mergeResolvedShellPath ( process . env )
2851 assert ( env . PATH )
2952 assert . strictEqual ( env , process . env )
3053 } )
3154 } )
3255
3356 describe ( 'resolveMac' , async function ( ) {
57+ const originalEnv = { ...process . env }
3458 beforeEach ( function ( ) {
3559 sandbox . stub ( process , 'platform' ) . value ( 'darwin' )
3660 } )
3761
3862 it ( 'mergeResolvedShellPath should get path on mac' , async function ( ) {
3963 sandbox . stub ( process . env , 'PATH' ) . value ( '' )
40- const env = await mergeResolvedShellPath ( process . env )
64+ // stub the resolve Env logic cause this is platform sensitive.
65+ sandbox . stub ( resolveEnv , 'getResolvedShellEnv' ) . resolves ( originalEnv )
66+ const env = await testMergeResolveShellPath ( process . env )
4167 assert ( env . PATH )
4268 assert . notEqual ( env , process . env )
4369 } )
0 commit comments