1
+ /* eslint-disable global-require */
1
2
// Copyright (c) Microsoft Corporation. All rights reserved.
2
3
// Licensed under the MIT License.
3
4
@@ -8,35 +9,42 @@ import * as fs from 'fs-extra';
8
9
import * as path from 'path' ;
9
10
import { anything , capture , instance , mock , verify , when } from 'ts-mockito' ;
10
11
import { expect } from 'chai' ;
12
+ import { WorkspaceFolder } from 'vscode-languageserver-protocol' ;
11
13
import * as Telemetry from '../../../../client/telemetry' ;
12
14
import { LanguageServerType } from '../../../../client/activation/types' ;
13
15
import { CommandManager } from '../../../../client/common/application/commandManager' ;
14
16
import { ReportIssueCommandHandler } from '../../../../client/common/application/commands/reportIssueCommand' ;
15
- import { ICommandManager , IWorkspaceService } from '../../../../client/common/application/types' ;
17
+ import {
18
+ IApplicationEnvironment ,
19
+ ICommandManager ,
20
+ IWorkspaceService ,
21
+ } from '../../../../client/common/application/types' ;
16
22
import { WorkspaceService } from '../../../../client/common/application/workspace' ;
17
23
import { IInterpreterService } from '../../../../client/interpreter/contracts' ;
18
24
import { MockWorkspaceConfiguration } from '../../../mocks/mockWorkspaceConfig' ;
19
- import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants' ;
20
25
import { InterpreterService } from '../../../../client/interpreter/interpreterService' ;
21
- import { Commands } from '../../../../client/common/constants' ;
26
+ import { Commands , EXTENSION_ROOT_DIR } from '../../../../client/common/constants' ;
22
27
import { AllCommands } from '../../../../client/common/application/commands' ;
23
28
import { ConfigurationService } from '../../../../client/common/configuration/service' ;
24
29
import { IConfigurationService } from '../../../../client/common/types' ;
25
30
import { EventName } from '../../../../client/telemetry/constants' ;
26
31
import { EnvironmentType , PythonEnvironment } from '../../../../client/pythonEnvironments/info' ;
32
+ import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants' ;
27
33
28
34
suite ( 'Report Issue Command' , ( ) => {
29
35
let reportIssueCommandHandler : ReportIssueCommandHandler ;
30
36
let cmdManager : ICommandManager ;
31
37
let workspaceService : IWorkspaceService ;
32
38
let interpreterService : IInterpreterService ;
33
39
let configurationService : IConfigurationService ;
40
+ let appEnvironment : IApplicationEnvironment ;
34
41
35
42
setup ( async ( ) => {
36
43
workspaceService = mock ( WorkspaceService ) ;
37
44
cmdManager = mock ( CommandManager ) ;
38
45
interpreterService = mock ( InterpreterService ) ;
39
46
configurationService = mock ( ConfigurationService ) ;
47
+ appEnvironment = mock < IApplicationEnvironment > ( ) ;
40
48
41
49
when ( cmdManager . executeCommand ( 'workbench.action.openIssueReporter' , anything ( ) ) ) . thenResolve ( ) ;
42
50
when ( workspaceService . getConfiguration ( 'python' ) ) . thenReturn (
@@ -51,12 +59,13 @@ suite('Report Issue Command', () => {
51
59
when ( interpreterService . getActiveInterpreter ( ) ) . thenResolve ( interpreter ) ;
52
60
when ( configurationService . getSettings ( ) ) . thenReturn ( {
53
61
experiments : {
54
- enabled : true ,
62
+ enabled : false ,
55
63
optInto : [ ] ,
56
64
optOutFrom : [ ] ,
57
65
} ,
58
66
initialize : true ,
59
67
venvPath : 'path' ,
68
+ pipenvPath : 'pipenv' ,
60
69
// eslint-disable-next-line @typescript-eslint/no-explicit-any
61
70
} as any ) ;
62
71
@@ -67,6 +76,7 @@ suite('Report Issue Command', () => {
67
76
instance ( workspaceService ) ,
68
77
instance ( interpreterService ) ,
69
78
instance ( configurationService ) ,
79
+ instance ( appEnvironment ) ,
70
80
) ;
71
81
await reportIssueCommandHandler . activate ( ) ;
72
82
} ) ;
@@ -75,7 +85,7 @@ suite('Report Issue Command', () => {
75
85
sinon . restore ( ) ;
76
86
} ) ;
77
87
78
- test ( 'Test if issue body is filled' , async ( ) => {
88
+ test ( 'Test if issue body is filled correctly when including all the settings ' , async ( ) => {
79
89
await reportIssueCommandHandler . openReportIssue ( ) ;
80
90
81
91
const templatePath = path . join (
@@ -100,6 +110,45 @@ suite('Report Issue Command', () => {
100
110
const actual = args [ 1 ] . issueBody ;
101
111
expect ( actual ) . to . be . equal ( expectedIssueBody ) ;
102
112
} ) ;
113
+
114
+ test ( 'Test if issue body is filled when only including settings which are explicitly set' , async ( ) => {
115
+ // eslint-disable-next-line import/no-dynamic-require
116
+ when ( appEnvironment . packageJson ) . thenReturn ( require ( path . join ( EXTENSION_ROOT_DIR , 'package.json' ) ) ) ;
117
+ when ( workspaceService . workspaceFolders ) . thenReturn ( [
118
+ instance ( mock ( WorkspaceFolder ) ) ,
119
+ instance ( mock ( WorkspaceFolder ) ) ,
120
+ ] ) ; // Multiroot scenario
121
+ reportIssueCommandHandler = new ReportIssueCommandHandler (
122
+ instance ( cmdManager ) ,
123
+ instance ( workspaceService ) ,
124
+ instance ( interpreterService ) ,
125
+ instance ( configurationService ) ,
126
+ instance ( appEnvironment ) ,
127
+ ) ;
128
+ await reportIssueCommandHandler . activate ( ) ;
129
+ await reportIssueCommandHandler . openReportIssue ( ) ;
130
+
131
+ const templatePath = path . join (
132
+ EXTENSION_ROOT_DIR_FOR_TESTS ,
133
+ 'src' ,
134
+ 'test' ,
135
+ 'common' ,
136
+ 'application' ,
137
+ 'commands' ,
138
+ 'issueTemplateVenv2.md' ,
139
+ ) ;
140
+ const expectedIssueBody = fs . readFileSync ( templatePath , 'utf8' ) ;
141
+
142
+ const args : [ string , { extensionId : string ; issueBody : string } ] = capture <
143
+ AllCommands ,
144
+ { extensionId : string ; issueBody : string }
145
+ > ( cmdManager . executeCommand ) . last ( ) ;
146
+
147
+ verify ( cmdManager . executeCommand ( 'workbench.action.openIssueReporter' , anything ( ) ) ) . once ( ) ;
148
+ expect ( args [ 0 ] ) . to . be . equal ( 'workbench.action.openIssueReporter' ) ;
149
+ const actual = args [ 1 ] . issueBody ;
150
+ expect ( actual ) . to . be . equal ( expectedIssueBody ) ;
151
+ } ) ;
103
152
test ( 'Should send telemetry event when run Report Issue Command' , async ( ) => {
104
153
const sendTelemetryStub = sinon . stub ( Telemetry , 'sendTelemetryEvent' ) ;
105
154
await reportIssueCommandHandler . openReportIssue ( ) ;
0 commit comments