-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathreportIssue.unit.test.ts
More file actions
112 lines (93 loc) · 4.48 KB
/
reportIssue.unit.test.ts
File metadata and controls
112 lines (93 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as assert from 'assert';
import * as typeMoq from 'typemoq';
import * as vscode from 'vscode';
import { PythonEnvironment, PythonEnvironmentId } from '../../api';
import { EnvironmentManagers, PythonProjectManager } from '../../internal.api';
import { PythonProject } from '../../api';
// We need to mock the extension's activate function to test the collectEnvironmentInfo function
// Since it's a local function, we'll test the command registration instead
suite('Report Issue Command Tests', () => {
let mockEnvManagers: typeMoq.IMock<EnvironmentManagers>;
let mockProjectManager: typeMoq.IMock<PythonProjectManager>;
setup(() => {
mockEnvManagers = typeMoq.Mock.ofType<EnvironmentManagers>();
mockProjectManager = typeMoq.Mock.ofType<PythonProjectManager>();
});
test('should handle environment collection with empty data', () => {
mockEnvManagers.setup((em) => em.managers).returns(() => []);
mockProjectManager.setup((pm) => pm.getProjects(typeMoq.It.isAny())).returns(() => []);
// Test that empty collections are handled gracefully
const managers = mockEnvManagers.object.managers;
const projects = mockProjectManager.object.getProjects();
assert.strictEqual(managers.length, 0);
assert.strictEqual(projects.length, 0);
});
test('should handle environment collection with mock data', async () => {
// Create mock environment
const mockEnvId: PythonEnvironmentId = {
id: 'test-env-id',
managerId: 'test-manager'
};
const mockEnv: PythonEnvironment = {
envId: mockEnvId,
name: 'Test Environment',
displayName: 'Test Environment 3.9',
displayPath: '/path/to/python',
version: '3.9.0',
environmentPath: vscode.Uri.file('/path/to/env'),
execInfo: {
run: {
executable: '/path/to/python',
args: []
}
},
sysPrefix: '/path/to/env'
};
const mockManager = {
id: 'test-manager',
displayName: 'Test Manager',
getEnvironments: async () => [mockEnv]
} as any;
// Create mock project
const mockProject: PythonProject = {
uri: vscode.Uri.file('/path/to/project'),
name: 'Test Project'
};
mockEnvManagers.setup((em) => em.managers).returns(() => [mockManager]);
mockProjectManager.setup((pm) => pm.getProjects(typeMoq.It.isAny())).returns(() => [mockProject]);
mockEnvManagers.setup((em) => em.getEnvironment(typeMoq.It.isAny())).returns(() => Promise.resolve(mockEnv));
// Verify mocks are set up correctly
const managers = mockEnvManagers.object.managers;
const projects = mockProjectManager.object.getProjects();
assert.strictEqual(managers.length, 1);
assert.strictEqual(projects.length, 1);
assert.strictEqual(managers[0].id, 'test-manager');
assert.strictEqual(projects[0].name, 'Test Project');
});
test('should handle errors gracefully during environment collection', async () => {
const mockManager = {
id: 'error-manager',
displayName: 'Error Manager',
getEnvironments: async () => {
throw new Error('Test error');
}
} as any;
mockEnvManagers.setup((em) => em.managers).returns(() => [mockManager]);
mockProjectManager.setup((pm) => pm.getProjects(typeMoq.It.isAny())).returns(() => []);
// Verify that error conditions don't break the test setup
const managers = mockEnvManagers.object.managers;
assert.strictEqual(managers.length, 1);
assert.strictEqual(managers[0].id, 'error-manager');
});
test('should register report issue command', () => {
// Basic test to ensure command registration structure would work
// The actual command registration happens during extension activation
// This tests the mock setup and basic functionality
mockEnvManagers.setup((em) => em.managers).returns(() => []);
mockProjectManager.setup((pm) => pm.getProjects(typeMoq.It.isAny())).returns(() => []);
// Verify basic setup works
assert.notStrictEqual(mockEnvManagers.object, undefined);
assert.notStrictEqual(mockProjectManager.object, undefined);
});
});