Skip to content

Commit e7083cf

Browse files
committed
fix tests
1 parent 3a8220b commit e7083cf

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

src/test/managers/builtin/helpers.shouldUseUv.unit.test.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ suite('Helpers - shouldUseUv', () => {
3131
clear: sinon.stub(),
3232
};
3333
getWorkspacePersistentStateStub.returns(Promise.resolve(mockPersistentState));
34-
// By default, return empty UV environments list
35-
mockPersistentState.get.resolves([]);
3634

3735
// Mock UV-related functions
3836
isUvInstalledStub = sinon.stub(helpers, 'isUvInstalled');
3937
getUvEnvironmentsStub = sinon.stub(uvEnvironments, 'getUvEnvironments');
4038

41-
// Set default behaviors
42-
isUvInstalledStub.resolves(false); // Default to UV not installed
43-
getUvEnvironmentsStub.resolves([]); // Default to no UV environments
39+
// No default behaviors set - each test configures what it needs
4440
// Create a more complete mock for LogOutputChannel
4541
mockLog = {
4642
info: sinon.stub(),
@@ -66,88 +62,93 @@ suite('Helpers - shouldUseUv', () => {
6662
});
6763

6864
test('should return true when alwaysUseUv is true and UV is installed', async () => {
69-
// Arrange: alwaysUseUv is true and UV is installed
65+
// Mock - alwaysUseUv is true and UV is installed
7066
mockConfig.get.withArgs('alwaysUseUv', true).returns(true);
7167
isUvInstalledStub.resolves(true);
68+
getUvEnvironmentsStub.resolves([]);
7269

73-
// Act
70+
// Run
7471
const result = await shouldUseUv(mockLog);
7572

76-
// Assert: Should return true when setting is true and UV is installed
73+
// Assert - Should return true when setting is true and UV is installed
7774
assert.strictEqual(result, true);
7875
});
7976

8077
test('should return false when alwaysUseUv is false', async () => {
81-
// Arrange: alwaysUseUv is false
78+
// Mock - alwaysUseUv is false
8279
mockConfig.get.withArgs('alwaysUseUv', true).returns(false);
80+
getUvEnvironmentsStub.resolves([]);
8381

84-
// Act
82+
// Run
8583
const result = await shouldUseUv(mockLog);
8684

87-
// Assert: Should not use UV when setting is false
85+
// Assert - Should not use UV when setting is false
8886
assert.strictEqual(result, false);
8987
});
9088

9189
test('should return true for UV environment path when UV is installed', async () => {
92-
// Arrange: Mock UV environments list with test path and UV is installed
90+
// Mock - UV environments list with test path and UV is installed
9391
const uvEnvPath = '/path/to/uv/env';
94-
getUvEnvironmentsStub.resolves([uvEnvPath]); // Mock the UV env in the list
95-
isUvInstalledStub.resolves(true); // Mock UV as installed
92+
getUvEnvironmentsStub.resolves([uvEnvPath]);
93+
isUvInstalledStub.resolves(true);
9694
mockConfig.get.withArgs('alwaysUseUv', true).returns(false);
9795

98-
// Act
96+
// Run
9997
const result = await shouldUseUv(mockLog, uvEnvPath);
10098

101-
// Assert: Should return true for UV environments when UV is installed
99+
// Assert - Should return true for UV environments when UV is installed
102100
assert.strictEqual(result, true);
103101
});
104102

105103
test('should return false for non-UV environment when alwaysUseUv is false', async () => {
106-
// Arrange: Non-UV environment, alwaysUseUv is false
104+
// Mock - Non-UV environment, alwaysUseUv is false
107105
const nonUvEnvPath = '/path/to/regular/env';
108106
mockConfig.get.withArgs('alwaysUseUv', true).returns(false);
107+
getUvEnvironmentsStub.resolves([]);
109108

110-
// Act
109+
// Run
111110
const result = await shouldUseUv(mockLog, nonUvEnvPath);
112111

113-
// Assert: Should not use UV for non-UV environments when setting is false
112+
// Assert - Should not use UV for non-UV environments when setting is false
114113
assert.strictEqual(result, false);
115114
});
116115

117116
test('should check setting when alwaysUseUv is true for non-UV environment', async () => {
118-
// Arrange: Non-UV environment, alwaysUseUv is true, UV is installed
117+
// Mock - Non-UV environment, alwaysUseUv is true, UV is installed
119118
const nonUvEnvPath = '/path/to/regular/env';
120119
mockConfig.get.withArgs('alwaysUseUv', true).returns(true);
121-
isUvInstalledStub.resolves(true); // UV is installed
122-
getUvEnvironmentsStub.resolves([]); // No UV environments (so path is not UV)
120+
isUvInstalledStub.resolves(true);
121+
getUvEnvironmentsStub.resolves([]);
123122

124-
// Act
123+
// Run
125124
const result = await shouldUseUv(mockLog, nonUvEnvPath);
126125

127-
// Assert: Should return true when alwaysUseUv is true and UV is installed
126+
// Assert - Should return true when alwaysUseUv is true and UV is installed
128127
assert.strictEqual(result, true);
129128
});
130129

131130
test('should use default value true when alwaysUseUv setting is not configured', async () => {
132-
// Arrange: Setting not configured, should use default of true, UV is installed
131+
// Mock - Setting not configured, should use default of true, UV is installed
133132
mockConfig.get.withArgs('alwaysUseUv', true).returns(true);
134133
isUvInstalledStub.resolves(true);
134+
getUvEnvironmentsStub.resolves([]);
135135

136-
// Act
136+
// Run
137137
const result = await shouldUseUv(mockLog);
138138

139-
// Assert: Should return true with default setting when UV is installed
139+
// Assert - Should return true with default setting when UV is installed
140140
assert.strictEqual(result, true);
141141
});
142142

143143
test('should respect alwaysUseUv setting when no environment path provided', async () => {
144-
// Arrange: No environment path specified, alwaysUseUv is false
144+
// Mock - No environment path specified, alwaysUseUv is false
145145
mockConfig.get.withArgs('alwaysUseUv', true).returns(false);
146+
getUvEnvironmentsStub.resolves([]);
146147

147-
// Act
148+
// Run
148149
const result = await shouldUseUv(mockLog);
149150

150-
// Assert: Should not use UV when setting is false
151+
// Assert - Should not use UV when setting is false
151152
assert.strictEqual(result, false);
152153
});
153154
});

0 commit comments

Comments
 (0)