@@ -7,7 +7,13 @@ import * as sinon from 'sinon';
77import { assert , expect } from 'chai' ;
88import { cloneDeep } from 'lodash' ;
99import { mock , instance , when , anything , verify , reset } from 'ts-mockito' ;
10- import { EnvironmentVariableCollection , ProgressLocation , Uri , WorkspaceFolder } from 'vscode' ;
10+ import {
11+ EnvironmentVariableCollection ,
12+ EnvironmentVariableScope ,
13+ ProgressLocation ,
14+ Uri ,
15+ WorkspaceFolder ,
16+ } from 'vscode' ;
1117import {
1218 IApplicationShell ,
1319 IApplicationEnvironment ,
@@ -39,7 +45,10 @@ suite('Terminal Environment Variable Collection Service', () => {
3945 let context : IExtensionContext ;
4046 let shell : IApplicationShell ;
4147 let experimentService : IExperimentService ;
42- let collection : EnvironmentVariableCollection ;
48+ let collection : EnvironmentVariableCollection & {
49+ getScopedEnvironmentVariableCollection ( scope : EnvironmentVariableScope ) : EnvironmentVariableCollection ;
50+ } ;
51+ let scopedCollection : EnvironmentVariableCollection ;
4352 let applicationEnvironment : IApplicationEnvironment ;
4453 let environmentActivationService : IEnvironmentActivationService ;
4554 let workspaceService : IWorkspaceService ;
@@ -62,7 +71,13 @@ suite('Terminal Environment Variable Collection Service', () => {
6271 interpreterService = mock < IInterpreterService > ( ) ;
6372 context = mock < IExtensionContext > ( ) ;
6473 shell = mock < IApplicationShell > ( ) ;
65- collection = mock < EnvironmentVariableCollection > ( ) ;
74+ collection = mock <
75+ EnvironmentVariableCollection & {
76+ getScopedEnvironmentVariableCollection ( scope : EnvironmentVariableScope ) : EnvironmentVariableCollection ;
77+ }
78+ > ( ) ;
79+ scopedCollection = mock < EnvironmentVariableCollection > ( ) ;
80+ when ( collection . getScopedEnvironmentVariableCollection ( anything ( ) ) ) . thenReturn ( instance ( scopedCollection ) ) ;
6681 when ( context . environmentVariableCollection ) . thenReturn ( instance ( collection ) ) ;
6782 experimentService = mock < IExperimentService > ( ) ;
6883 when ( experimentService . inExperimentSync ( TerminalEnvVarActivation . experiment ) ) . thenReturn ( true ) ;
@@ -166,12 +181,12 @@ suite('Terminal Environment Variable Collection Service', () => {
166181 ) . thenResolve ( envVars ) ;
167182
168183 when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
169- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
184+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
170185
171186 await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
172187
173188 verify ( collection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . once ( ) ;
174- verify ( collection . delete ( 'PATH' , anything ( ) ) ) . once ( ) ;
189+ verify ( collection . delete ( 'PATH' ) ) . once ( ) ;
175190 } ) ;
176191
177192 test ( 'Verify envs are not applied if env activation is disabled' , async ( ) => {
@@ -187,7 +202,7 @@ suite('Terminal Environment Variable Collection Service', () => {
187202 ) . thenResolve ( envVars ) ;
188203
189204 when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
190- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
205+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
191206 reset ( configService ) ;
192207 when ( configService . getSettings ( anything ( ) ) ) . thenReturn ( ( {
193208 terminal : { activateEnvironment : false } ,
@@ -197,10 +212,10 @@ suite('Terminal Environment Variable Collection Service', () => {
197212 await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
198213
199214 verify ( collection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . never ( ) ;
200- verify ( collection . delete ( 'PATH' , anything ( ) ) ) . never ( ) ;
215+ verify ( collection . delete ( 'PATH' ) ) . never ( ) ;
201216 } ) ;
202217
203- test ( 'Verify correct scope is used when applying envs and setting description' , async ( ) => {
218+ test ( 'Verify correct options are used when applying envs and setting description' , async ( ) => {
204219 const envVars : NodeJS . ProcessEnv = { CONDA_PREFIX : 'prefix/to/conda' , ..._normCaseKeys ( process . env ) } ;
205220 delete envVars . PATH ;
206221 const resource = Uri . file ( 'a' ) ;
@@ -214,25 +229,16 @@ suite('Terminal Environment Variable Collection Service', () => {
214229 environmentActivationService . getActivatedEnvironmentVariables ( resource , undefined , undefined , customShell ) ,
215230 ) . thenResolve ( envVars ) ;
216231
217- when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenCall ( ( _e , _v , scope ) => {
218- assert . deepEqual ( scope , { workspaceFolder } ) ;
219- return Promise . resolve ( ) ;
220- } ) ;
221- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenCall ( ( _e , scope ) => {
222- assert . deepEqual ( scope , { workspaceFolder } ) ;
232+ when ( scopedCollection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenCall ( ( _e , _v , options ) => {
233+ assert . deepEqual ( options , { applyAtShellIntegration : true } ) ;
223234 return Promise . resolve ( ) ;
224235 } ) ;
225- let description = '' ;
226- when ( collection . setDescription ( anything ( ) , anything ( ) ) ) . thenCall ( ( d , scope ) => {
227- assert . deepEqual ( scope , { workspaceFolder } ) ;
228- description = d . value ;
229- } ) ;
236+ when ( scopedCollection . delete ( anything ( ) ) ) . thenResolve ( ) ;
230237
231238 await terminalEnvVarCollectionService . _applyCollection ( resource , customShell ) ;
232239
233- verify ( collection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . once ( ) ;
234- verify ( collection . delete ( 'PATH' , anything ( ) ) ) . once ( ) ;
235- expect ( description ) . to . equal ( `${ Interpreters . activateTerminalDescription } \`${ displayPath } \`` ) ;
240+ verify ( scopedCollection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . once ( ) ;
241+ verify ( scopedCollection . delete ( 'PATH' ) ) . once ( ) ;
236242 } ) ;
237243
238244 test ( 'Only relative changes to previously applied variables are applied to the collection' , async ( ) => {
@@ -251,7 +257,7 @@ suite('Terminal Environment Variable Collection Service', () => {
251257 ) . thenResolve ( envVars ) ;
252258
253259 when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
254- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
260+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
255261
256262 await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
257263
@@ -270,8 +276,8 @@ suite('Terminal Environment Variable Collection Service', () => {
270276
271277 await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
272278
273- verify ( collection . delete ( 'CONDA_PREFIX' , anything ( ) ) ) . once ( ) ;
274- verify ( collection . delete ( 'RANDOM_VAR' , anything ( ) ) ) . once ( ) ;
279+ verify ( collection . delete ( 'CONDA_PREFIX' ) ) . once ( ) ;
280+ verify ( collection . delete ( 'RANDOM_VAR' ) ) . once ( ) ;
275281 } ) ;
276282
277283 test ( 'If no activated variables are returned for custom shell, fallback to using default shell' , async ( ) => {
@@ -294,12 +300,12 @@ suite('Terminal Environment Variable Collection Service', () => {
294300 ) . thenResolve ( envVars ) ;
295301
296302 when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
297- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
303+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
298304
299305 await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
300306
301307 verify ( collection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . once ( ) ;
302- verify ( collection . delete ( anything ( ) , anything ( ) ) ) . never ( ) ;
308+ verify ( collection . delete ( anything ( ) ) ) . never ( ) ;
303309 } ) ;
304310
305311 test ( 'If no activated variables are returned for default shell, clear collection' , async ( ) => {
@@ -313,12 +319,10 @@ suite('Terminal Environment Variable Collection Service', () => {
313319 ) . thenResolve ( undefined ) ;
314320
315321 when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
316- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
317- when ( collection . setDescription ( anything ( ) , anything ( ) ) ) . thenReturn ( ) ;
322+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
318323
319324 await terminalEnvVarCollectionService . _applyCollection ( undefined , defaultShell ?. shell ) ;
320325
321- verify ( collection . clear ( anything ( ) ) ) . once ( ) ;
322- verify ( collection . setDescription ( anything ( ) , anything ( ) ) ) . never ( ) ;
326+ verify ( collection . clear ( ) ) . once ( ) ;
323327 } ) ;
324328} ) ;
0 commit comments