Skip to content

Commit cdc339a

Browse files
author
Kartik Raj
committed
Correct dummy implementations and adjust tests
1 parent 3126024 commit cdc339a

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/client/pythonEnvironments/collection/environmentsReducer.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { isEqual } from 'lodash';
4+
import { cloneDeep, isEqual } from 'lodash';
55
import { Event, EventEmitter } from 'vscode';
66
import { traceVerbose } from '../../common/logger';
77
import { areSameEnvironment, PythonEnvInfo, PythonEnvKind } from '../base/info';
@@ -94,6 +94,8 @@ async function resolveDifferencesInBackground(
9494
if (!isEqual(oldEnv, merged)) {
9595
didUpdate.fire({ old: oldEnv, new: merged });
9696
seen[oldIndex] = merged;
97+
} else {
98+
const x = 2;
9799
}
98100
state.pending -= 1;
99101
checkIfFinishedAndNotify(state, didUpdate);
@@ -115,10 +117,11 @@ function checkIfFinishedAndNotify(
115117
}
116118

117119
export function mergeEnvironments(environment: PythonEnvInfo, other: PythonEnvInfo): PythonEnvInfo {
120+
const result = cloneDeep(environment);
118121
// Preserve type information.
119122
// Possible we identified environment as unknown, but a later provider has identified env type.
120123
if (environment.kind === PythonEnvKind.Unknown && other.kind && other.kind !== PythonEnvKind.Unknown) {
121-
environment.kind = other.kind;
124+
result.kind = other.kind;
122125
}
123126
const props: (keyof PythonEnvInfo)[] = [
124127
'version',
@@ -131,11 +134,11 @@ export function mergeEnvironments(environment: PythonEnvInfo, other: PythonEnvIn
131134
'searchLocation',
132135
];
133136
props.forEach((prop) => {
134-
if (!environment[prop] && other[prop]) {
137+
if (!result[prop] && other[prop]) {
135138
// tslint:disable: no-any
136139
// eslint-disable-next-line @typescript-eslint/no-explicit-any
137-
(environment as any)[prop] = other[prop];
140+
(result as any)[prop] = other[prop];
138141
}
139142
});
140-
return environment;
143+
return result;
141144
}

src/test/pythonEnvironments/collection/environmentsReducer.unit.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { assert, expect } from 'chai';
5+
import { isEqual } from 'lodash';
56
import * as path from 'path';
67
import { EventEmitter } from 'vscode';
78
import { PythonEnvInfo, PythonEnvKind } from '../../../client/pythonEnvironments/base/info';
@@ -98,12 +99,14 @@ suite('Environments Reducer', () => {
9899

99100
// Assert
100101
const env12 = mergeEnvironments(env1, env2);
101-
const expectedUpdates = [
102-
{ old: env1, new: env12 },
103-
{ old: env12, new: mergeEnvironments(env12, env3) },
104-
null,
105-
];
106-
assert.deepEqual(expectedUpdates, onUpdatedEvents);
102+
const env123 = mergeEnvironments(env12, env3);
103+
const expectedUpdates: (PythonEnvUpdatedEvent | null)[] = [];
104+
if (isEqual(env12, env123)) {
105+
expectedUpdates.push({ old: env1, new: env12 }, null);
106+
} else {
107+
expectedUpdates.push({ old: env1, new: env12 }, { old: env12, new: env123 }, null);
108+
}
109+
assert.deepEqual(onUpdatedEvents, expectedUpdates);
107110
});
108111

109112
test('Updates to environments from the incoming iterator are passed on correctly followed by the null event', async () => {

0 commit comments

Comments
 (0)