forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreportIssueCommand.unit.test.ts
More file actions
91 lines (79 loc) · 4.13 KB
/
reportIssueCommand.unit.test.ts
File metadata and controls
91 lines (79 loc) · 4.13 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as sinon from 'sinon';
import * as fs from 'fs-extra';
import * as path from 'path';
import { anything, capture, instance, mock, verify, when } from 'ts-mockito';
import { expect } from 'chai';
import { LanguageServerType } from '../../../../client/activation/types';
import { CommandManager } from '../../../../client/common/application/commandManager';
import { ReportIssueCommandHandler } from '../../../../client/common/application/commands/reportIssueCommand';
import { ICommandManager, IWorkspaceService } from '../../../../client/common/application/types';
import { WorkspaceService } from '../../../../client/common/application/workspace';
import { IInterpreterService, IInterpreterVersionService } from '../../../../client/interpreter/contracts';
import { InterpreterVersionService } from '../../../../client/interpreter/interpreterVersion';
import { PythonEnvKind } from '../../../../client/pythonEnvironments/base/info';
import * as EnvIdentifier from '../../../../client/pythonEnvironments/common/environmentIdentifier';
import { MockWorkspaceConfiguration } from '../../../startPage/mockWorkspaceConfig';
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants';
import { InterpreterService } from '../../../../client/interpreter/interpreterService';
import * as Logging from '../../../../client/logging/_global';
suite('Report Issue Command', () => {
let reportIssueCommandHandler: ReportIssueCommandHandler;
let cmdManager: ICommandManager;
let workspaceService: IWorkspaceService;
let interpreterVersionService: IInterpreterVersionService;
let interpreterService: IInterpreterService;
let identifyEnvironmentStub: sinon.SinonStub;
let getPythonOutputContentStub: sinon.SinonStub;
setup(async () => {
interpreterVersionService = mock(InterpreterVersionService);
workspaceService = mock(WorkspaceService);
cmdManager = mock(CommandManager);
interpreterService = mock(InterpreterService);
when(cmdManager.executeCommand('workbench.action.openIssueReporter', anything())).thenResolve();
when(interpreterVersionService.getVersion(anything(), anything())).thenResolve('3.9.0');
when(workspaceService.getConfiguration('python')).thenReturn(
new MockWorkspaceConfiguration({
languageServer: LanguageServerType.Node,
}),
);
when(interpreterService.getActiveInterpreter(anything())).thenResolve(undefined);
identifyEnvironmentStub = sinon.stub(EnvIdentifier, 'identifyEnvironment');
identifyEnvironmentStub.resolves(PythonEnvKind.Venv);
cmdManager = mock(CommandManager);
getPythonOutputContentStub = sinon.stub(Logging, 'getPythonOutputChannelContent');
getPythonOutputContentStub.resolves('Python Output');
reportIssueCommandHandler = new ReportIssueCommandHandler(
instance(cmdManager),
instance(workspaceService),
instance(interpreterService),
instance(interpreterVersionService),
);
await reportIssueCommandHandler.activate();
});
teardown(() => {
identifyEnvironmentStub.restore();
getPythonOutputContentStub.restore();
});
test('Test if issue body is filled', async () => {
await reportIssueCommandHandler.openReportIssue();
const templatePath = path.join(
EXTENSION_ROOT_DIR_FOR_TESTS,
'src',
'test',
'common',
'application',
'commands',
'issueTemplateVenv1.md',
);
const expectedIssueBody = fs.readFileSync(templatePath, 'utf8');
const args = capture<'workbench.action.openIssueReporter', { extensionId: string; issueBody: string }>(
cmdManager.executeCommand,
).last();
verify(cmdManager.registerCommand('python.reportIssue', anything(), anything())).once();
verify(cmdManager.executeCommand('workbench.action.openIssueReporter', anything())).once();
expect(args[1].issueBody).to.be.equal(expectedIssueBody);
});
});