Skip to content

Commit cb66272

Browse files
author
Kartik Raj
committed
Never replace
1 parent 547706a commit cb66272

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"--ui=tdd",
161161
"--recursive",
162162
"--colors",
163-
//"--grep", "<suite name>",
163+
"--grep", "Terminal Environment Variable Collection",
164164
"--timeout=300000"
165165
],
166166
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],

src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ suite('Terminal Environment Variable Collection Service', () => {
216216
assert.deepEqual(opts, { applyAtProcessCreation: false, applyAtShellIntegration: true });
217217
});
218218

219-
test('Prepend PATH instead of replacing it, where possible', async () => {
219+
test('Prepend only "prepend portion of PATH" where applicable', async () => {
220220
const processEnv = { PATH: 'hello/1/2/3' };
221221
reset(environmentActivationService);
222222
when(environmentActivationService.getProcessEnvironmentVariables(anything(), anything())).thenResolve(
@@ -248,6 +248,38 @@ suite('Terminal Environment Variable Collection Service', () => {
248248
assert.deepEqual(opts, { applyAtProcessCreation: true, applyAtShellIntegration: true });
249249
});
250250

251+
test('Prepend full PATH otherwise', async () => {
252+
const processEnv = { PATH: 'hello/1/2/3' };
253+
reset(environmentActivationService);
254+
when(environmentActivationService.getProcessEnvironmentVariables(anything(), anything())).thenResolve(
255+
processEnv,
256+
);
257+
const finalPath = 'hello/3/2/1';
258+
const envVars: NodeJS.ProcessEnv = { PATH: finalPath };
259+
when(
260+
environmentActivationService.getActivatedEnvironmentVariables(
261+
anything(),
262+
undefined,
263+
undefined,
264+
customShell,
265+
),
266+
).thenResolve(envVars);
267+
268+
when(collection.replace(anything(), anything(), anything())).thenResolve();
269+
when(collection.delete(anything())).thenResolve();
270+
let opts: EnvironmentVariableMutatorOptions | undefined;
271+
when(collection.prepend('PATH', anything(), anything())).thenCall((_, _v, o) => {
272+
opts = o;
273+
});
274+
275+
await terminalEnvVarCollectionService._applyCollection(undefined, customShell);
276+
277+
verify(collection.clear()).once();
278+
verify(collection.prepend('PATH', finalPath, anything())).once();
279+
verify(collection.replace('PATH', anything(), anything())).never();
280+
assert.deepEqual(opts, { applyAtProcessCreation: true, applyAtShellIntegration: true });
281+
});
282+
251283
test('Verify envs are not applied if env activation is disabled', async () => {
252284
const envVars: NodeJS.ProcessEnv = { CONDA_PREFIX: 'prefix/to/conda', ...process.env };
253285
when(

0 commit comments

Comments
 (0)