@@ -7,7 +7,13 @@ import * as sinon from 'sinon';
7
7
import { assert , expect } from 'chai' ;
8
8
import { cloneDeep } from 'lodash' ;
9
9
import { 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' ;
11
17
import {
12
18
IApplicationShell ,
13
19
IApplicationEnvironment ,
@@ -39,7 +45,10 @@ suite('Terminal Environment Variable Collection Service', () => {
39
45
let context : IExtensionContext ;
40
46
let shell : IApplicationShell ;
41
47
let experimentService : IExperimentService ;
42
- let collection : EnvironmentVariableCollection ;
48
+ let collection : EnvironmentVariableCollection & {
49
+ getScopedEnvironmentVariableCollection ( scope : EnvironmentVariableScope ) : EnvironmentVariableCollection ;
50
+ } ;
51
+ let scopedCollection : EnvironmentVariableCollection ;
43
52
let applicationEnvironment : IApplicationEnvironment ;
44
53
let environmentActivationService : IEnvironmentActivationService ;
45
54
let workspaceService : IWorkspaceService ;
@@ -62,7 +71,13 @@ suite('Terminal Environment Variable Collection Service', () => {
62
71
interpreterService = mock < IInterpreterService > ( ) ;
63
72
context = mock < IExtensionContext > ( ) ;
64
73
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 ) ) ;
66
81
when ( context . environmentVariableCollection ) . thenReturn ( instance ( collection ) ) ;
67
82
experimentService = mock < IExperimentService > ( ) ;
68
83
when ( experimentService . inExperimentSync ( TerminalEnvVarActivation . experiment ) ) . thenReturn ( true ) ;
@@ -166,12 +181,12 @@ suite('Terminal Environment Variable Collection Service', () => {
166
181
) . thenResolve ( envVars ) ;
167
182
168
183
when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
169
- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
184
+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
170
185
171
186
await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
172
187
173
188
verify ( collection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . once ( ) ;
174
- verify ( collection . delete ( 'PATH' , anything ( ) ) ) . once ( ) ;
189
+ verify ( collection . delete ( 'PATH' ) ) . once ( ) ;
175
190
} ) ;
176
191
177
192
test ( 'Verify envs are not applied if env activation is disabled' , async ( ) => {
@@ -187,7 +202,7 @@ suite('Terminal Environment Variable Collection Service', () => {
187
202
) . thenResolve ( envVars ) ;
188
203
189
204
when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
190
- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
205
+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
191
206
reset ( configService ) ;
192
207
when ( configService . getSettings ( anything ( ) ) ) . thenReturn ( ( {
193
208
terminal : { activateEnvironment : false } ,
@@ -197,10 +212,10 @@ suite('Terminal Environment Variable Collection Service', () => {
197
212
await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
198
213
199
214
verify ( collection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . never ( ) ;
200
- verify ( collection . delete ( 'PATH' , anything ( ) ) ) . never ( ) ;
215
+ verify ( collection . delete ( 'PATH' ) ) . never ( ) ;
201
216
} ) ;
202
217
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 ( ) => {
204
219
const envVars : NodeJS . ProcessEnv = { CONDA_PREFIX : 'prefix/to/conda' , ..._normCaseKeys ( process . env ) } ;
205
220
delete envVars . PATH ;
206
221
const resource = Uri . file ( 'a' ) ;
@@ -214,25 +229,16 @@ suite('Terminal Environment Variable Collection Service', () => {
214
229
environmentActivationService . getActivatedEnvironmentVariables ( resource , undefined , undefined , customShell ) ,
215
230
) . thenResolve ( envVars ) ;
216
231
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 } ) ;
223
234
return Promise . resolve ( ) ;
224
235
} ) ;
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 ( ) ;
230
237
231
238
await terminalEnvVarCollectionService . _applyCollection ( resource , customShell ) ;
232
239
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 ( ) ;
236
242
} ) ;
237
243
238
244
test ( 'Only relative changes to previously applied variables are applied to the collection' , async ( ) => {
@@ -251,7 +257,7 @@ suite('Terminal Environment Variable Collection Service', () => {
251
257
) . thenResolve ( envVars ) ;
252
258
253
259
when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
254
- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
260
+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
255
261
256
262
await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
257
263
@@ -270,8 +276,8 @@ suite('Terminal Environment Variable Collection Service', () => {
270
276
271
277
await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
272
278
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 ( ) ;
275
281
} ) ;
276
282
277
283
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', () => {
294
300
) . thenResolve ( envVars ) ;
295
301
296
302
when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
297
- when ( collection . delete ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
303
+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
298
304
299
305
await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
300
306
301
307
verify ( collection . replace ( 'CONDA_PREFIX' , 'prefix/to/conda' , anything ( ) ) ) . once ( ) ;
302
- verify ( collection . delete ( anything ( ) , anything ( ) ) ) . never ( ) ;
308
+ verify ( collection . delete ( anything ( ) ) ) . never ( ) ;
303
309
} ) ;
304
310
305
311
test ( 'If no activated variables are returned for default shell, clear collection' , async ( ) => {
@@ -313,12 +319,10 @@ suite('Terminal Environment Variable Collection Service', () => {
313
319
) . thenResolve ( undefined ) ;
314
320
315
321
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 ( ) ;
318
323
319
324
await terminalEnvVarCollectionService . _applyCollection ( undefined , defaultShell ?. shell ) ;
320
325
321
- verify ( collection . clear ( anything ( ) ) ) . once ( ) ;
322
- verify ( collection . setDescription ( anything ( ) , anything ( ) ) ) . never ( ) ;
326
+ verify ( collection . clear ( ) ) . once ( ) ;
323
327
} ) ;
324
328
} ) ;
0 commit comments