Skip to content

Commit f2b9ac5

Browse files
committed
make tests realistic for paths
1 parent fb4fa59 commit f2b9ac5

1 file changed

Lines changed: 28 additions & 17 deletions

File tree

src/test/features/projectManager.fileEvents.unit.test.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import * as settingHelpers from '../../features/settings/settingHelpers';
88
import { PythonProjectsImpl } from '../../internal.api';
99
import { MockWorkspaceConfiguration } from '../mocks/mockWorkspaceConfig';
1010

11+
/**
12+
* Returns a platform-appropriate workspace path for testing.
13+
* On Windows, paths must include a drive letter to work correctly with path.resolve().
14+
*/
15+
function getTestWorkspacePath(): string {
16+
return process.platform === 'win32' ? 'C:\\workspace' : '/workspace';
17+
}
18+
1119
/**
1220
* Tests for project manager file event handling (delete/rename).
1321
*
@@ -28,7 +36,7 @@ suite('Project Manager File Event Handling', () => {
2836
let updatePythonProjectSettingPathStub: sinon.SinonStub;
2937
let clock: sinon.SinonFakeTimers;
3038

31-
const workspaceUri = Uri.file('/workspace');
39+
const workspaceUri = Uri.file(getTestWorkspacePath());
3240
const workspaceFolder: WorkspaceFolder = {
3341
uri: workspaceUri,
3442
name: 'workspace',
@@ -105,7 +113,7 @@ suite('Project Manager File Event Handling', () => {
105113

106114
suite('handleDeletedFiles', () => {
107115
test('should remove project and update settings when project folder is deleted', async () => {
108-
const projectUri = Uri.file('/workspace/my-project');
116+
const projectUri = Uri.file(`${getTestWorkspacePath()}/my-project`);
109117
const pm = new PythonProjectManagerImpl();
110118
pm.initialize();
111119

@@ -176,7 +184,7 @@ suite('Project Manager File Event Handling', () => {
176184
});
177185

178186
test('should not affect untracked folders', async () => {
179-
const untrackedUri = Uri.file('/workspace/not-a-project');
187+
const untrackedUri = Uri.file(`${getTestWorkspacePath()}/not-a-project`);
180188
const pm = new PythonProjectManagerImpl();
181189
pm.initialize();
182190

@@ -198,8 +206,8 @@ suite('Project Manager File Event Handling', () => {
198206

199207
suite('handleRenamedFiles', () => {
200208
test('should update project path in settings when project folder is renamed', async () => {
201-
const oldUri = Uri.file('/workspace/old-name');
202-
const newUri = Uri.file('/workspace/new-name');
209+
const oldUri = Uri.file(`${getTestWorkspacePath()}/old-name`);
210+
const newUri = Uri.file(`${getTestWorkspacePath()}/new-name`);
203211
const pm = new PythonProjectManagerImpl();
204212
pm.initialize();
205213

@@ -236,7 +244,7 @@ suite('Project Manager File Event Handling', () => {
236244
const pm = new PythonProjectManagerImpl();
237245
pm.initialize();
238246

239-
const newUri = Uri.file('/new-workspace');
247+
const newUri = Uri.file(process.platform === 'win32' ? 'C:\\new-workspace' : '/new-workspace');
240248

241249
// Fire rename event for workspace root
242250
renameFilesEmitter.fire({ files: [{ oldUri: workspaceUri, newUri }] });
@@ -254,8 +262,8 @@ suite('Project Manager File Event Handling', () => {
254262
});
255263

256264
test('should not affect untracked folder renames', async () => {
257-
const oldUri = Uri.file('/workspace/untracked');
258-
const newUri = Uri.file('/workspace/untracked-renamed');
265+
const oldUri = Uri.file(`${getTestWorkspacePath()}/untracked`);
266+
const newUri = Uri.file(`${getTestWorkspacePath()}/untracked-renamed`);
259267
const pm = new PythonProjectManagerImpl();
260268
pm.initialize();
261269

@@ -287,7 +295,8 @@ suite('updatePythonProjectSettingPath', () => {
287295
});
288296

289297
test('should update project path in pythonProjects setting', async () => {
290-
const workspaceUri = Uri.file('/workspace');
298+
const workspacePath = getTestWorkspacePath();
299+
const workspaceUri = Uri.file(workspacePath);
291300
const workspaceFolder: WorkspaceFolder = {
292301
uri: workspaceUri,
293302
name: 'workspace',
@@ -315,8 +324,8 @@ suite('updatePythonProjectSettingPath', () => {
315324
};
316325
sinon.stub(workspaceApis, 'getConfiguration').returns(mockConfig);
317326

318-
const oldUri = Uri.file('/workspace/old-project');
319-
const newUri = Uri.file('/workspace/new-project');
327+
const oldUri = Uri.file(`${workspacePath}/old-project`);
328+
const newUri = Uri.file(`${workspacePath}/new-project`);
320329

321330
await settingHelpers.updatePythonProjectSettingPath(oldUri, newUri);
322331

@@ -327,7 +336,8 @@ suite('updatePythonProjectSettingPath', () => {
327336
});
328337

329338
test('should not update if project not found in settings', async () => {
330-
const workspaceUri = Uri.file('/workspace');
339+
const workspacePath = getTestWorkspacePath();
340+
const workspaceUri = Uri.file(workspacePath);
331341
const workspaceFolder: WorkspaceFolder = {
332342
uri: workspaceUri,
333343
name: 'workspace',
@@ -355,16 +365,17 @@ suite('updatePythonProjectSettingPath', () => {
355365
};
356366
sinon.stub(workspaceApis, 'getConfiguration').returns(mockConfig);
357367

358-
const oldUri = Uri.file('/workspace/non-existent');
359-
const newUri = Uri.file('/workspace/renamed');
368+
const oldUri = Uri.file(`${workspacePath}/non-existent`);
369+
const newUri = Uri.file(`${workspacePath}/renamed`);
360370

361371
await settingHelpers.updatePythonProjectSettingPath(oldUri, newUri);
362372

363373
assert.strictEqual(updateCalls.length, 0, 'Should not update settings when project not found');
364374
});
365375

366376
test('should preserve envManager and packageManager when updating path', async () => {
367-
const workspaceUri = Uri.file('/workspace');
377+
const workspacePath = getTestWorkspacePath();
378+
const workspaceUri = Uri.file(workspacePath);
368379
const workspaceFolder: WorkspaceFolder = {
369380
uri: workspaceUri,
370381
name: 'workspace',
@@ -392,8 +403,8 @@ suite('updatePythonProjectSettingPath', () => {
392403
};
393404
sinon.stub(workspaceApis, 'getConfiguration').returns(mockConfig);
394405

395-
const oldUri = Uri.file('/workspace/pyenv-project');
396-
const newUri = Uri.file('/workspace/pyenv-project-renamed');
406+
const oldUri = Uri.file(`${workspacePath}/pyenv-project`);
407+
const newUri = Uri.file(`${workspacePath}/pyenv-project-renamed`);
397408

398409
await settingHelpers.updatePythonProjectSettingPath(oldUri, newUri);
399410

0 commit comments

Comments
 (0)