1+ /* eslint-disable global-require */
12// Copyright (c) Microsoft Corporation. All rights reserved.
23// Licensed under the MIT License.
34
@@ -8,35 +9,42 @@ import * as fs from 'fs-extra';
89import * as path from 'path' ;
910import { anything , capture , instance , mock , verify , when } from 'ts-mockito' ;
1011import { expect } from 'chai' ;
12+ import { WorkspaceFolder } from 'vscode-languageserver-protocol' ;
1113import * as Telemetry from '../../../../client/telemetry' ;
1214import { LanguageServerType } from '../../../../client/activation/types' ;
1315import { CommandManager } from '../../../../client/common/application/commandManager' ;
1416import { 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' ;
1622import { WorkspaceService } from '../../../../client/common/application/workspace' ;
1723import { IInterpreterService } from '../../../../client/interpreter/contracts' ;
1824import { MockWorkspaceConfiguration } from '../../../mocks/mockWorkspaceConfig' ;
19- import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants' ;
2025import { InterpreterService } from '../../../../client/interpreter/interpreterService' ;
21- import { Commands } from '../../../../client/common/constants' ;
26+ import { Commands , EXTENSION_ROOT_DIR } from '../../../../client/common/constants' ;
2227import { AllCommands } from '../../../../client/common/application/commands' ;
2328import { ConfigurationService } from '../../../../client/common/configuration/service' ;
2429import { IConfigurationService } from '../../../../client/common/types' ;
2530import { EventName } from '../../../../client/telemetry/constants' ;
2631import { EnvironmentType , PythonEnvironment } from '../../../../client/pythonEnvironments/info' ;
32+ import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants' ;
2733
2834suite ( 'Report Issue Command' , ( ) => {
2935 let reportIssueCommandHandler : ReportIssueCommandHandler ;
3036 let cmdManager : ICommandManager ;
3137 let workspaceService : IWorkspaceService ;
3238 let interpreterService : IInterpreterService ;
3339 let configurationService : IConfigurationService ;
40+ let appEnvironment : IApplicationEnvironment ;
3441
3542 setup ( async ( ) => {
3643 workspaceService = mock ( WorkspaceService ) ;
3744 cmdManager = mock ( CommandManager ) ;
3845 interpreterService = mock ( InterpreterService ) ;
3946 configurationService = mock ( ConfigurationService ) ;
47+ appEnvironment = mock < IApplicationEnvironment > ( ) ;
4048
4149 when ( cmdManager . executeCommand ( 'workbench.action.openIssueReporter' , anything ( ) ) ) . thenResolve ( ) ;
4250 when ( workspaceService . getConfiguration ( 'python' ) ) . thenReturn (
@@ -51,12 +59,13 @@ suite('Report Issue Command', () => {
5159 when ( interpreterService . getActiveInterpreter ( ) ) . thenResolve ( interpreter ) ;
5260 when ( configurationService . getSettings ( ) ) . thenReturn ( {
5361 experiments : {
54- enabled : true ,
62+ enabled : false ,
5563 optInto : [ ] ,
5664 optOutFrom : [ ] ,
5765 } ,
5866 initialize : true ,
5967 venvPath : 'path' ,
68+ pipenvPath : 'pipenv' ,
6069 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6170 } as any ) ;
6271
@@ -67,6 +76,7 @@ suite('Report Issue Command', () => {
6776 instance ( workspaceService ) ,
6877 instance ( interpreterService ) ,
6978 instance ( configurationService ) ,
79+ instance ( appEnvironment ) ,
7080 ) ;
7181 await reportIssueCommandHandler . activate ( ) ;
7282 } ) ;
@@ -75,7 +85,7 @@ suite('Report Issue Command', () => {
7585 sinon . restore ( ) ;
7686 } ) ;
7787
78- test ( 'Test if issue body is filled' , async ( ) => {
88+ test ( 'Test if issue body is filled correctly when including all the settings ' , async ( ) => {
7989 await reportIssueCommandHandler . openReportIssue ( ) ;
8090
8191 const templatePath = path . join (
@@ -100,6 +110,45 @@ suite('Report Issue Command', () => {
100110 const actual = args [ 1 ] . issueBody ;
101111 expect ( actual ) . to . be . equal ( expectedIssueBody ) ;
102112 } ) ;
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+ } ) ;
103152 test ( 'Should send telemetry event when run Report Issue Command' , async ( ) => {
104153 const sendTelemetryStub = sinon . stub ( Telemetry , 'sendTelemetryEvent' ) ;
105154 await reportIssueCommandHandler . openReportIssue ( ) ;
0 commit comments