33
44import { expect } from 'chai' ;
55import * as path from 'path' ;
6+ import * as sinon from 'sinon' ;
67import * as TypeMoq from 'typemoq' ;
78import {
89 Disposable ,
@@ -22,6 +23,7 @@ import { IDisposableRegistry } from '../../../client/common/types';
2223import { IServiceContainer } from '../../../client/ioc/types' ;
2324import { ITerminalAutoActivation } from '../../../client/terminals/types' ;
2425import { createPythonInterpreter } from '../../utils/interpreters' ;
26+ import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis' ;
2527
2628suite ( 'Terminal Service' , ( ) => {
2729 let service : TerminalService ;
@@ -37,6 +39,9 @@ suite('Terminal Service', () => {
3739 let terminalShellIntegration : TypeMoq . IMock < TerminalShellIntegration > ;
3840 let onDidEndTerminalShellExecutionEmitter : EventEmitter < TerminalShellExecutionEndEvent > ;
3941 let event : TerminalShellExecutionEndEvent ;
42+ let getConfigurationStub : sinon . SinonStub ;
43+ let pythonConfig : TypeMoq . IMock < WorkspaceConfiguration > ;
44+ let editorConfig : TypeMoq . IMock < WorkspaceConfiguration > ;
4045
4146 setup ( ( ) => {
4247 terminal = TypeMoq . Mock . ofType < VSCodeTerminal > ( ) ;
@@ -88,12 +93,22 @@ suite('Terminal Service', () => {
8893 mockServiceContainer . setup ( ( c ) => c . get ( IWorkspaceService ) ) . returns ( ( ) => workspaceService . object ) ;
8994 mockServiceContainer . setup ( ( c ) => c . get ( ITerminalActivator ) ) . returns ( ( ) => terminalActivator . object ) ;
9095 mockServiceContainer . setup ( ( c ) => c . get ( ITerminalAutoActivation ) ) . returns ( ( ) => terminalAutoActivator . object ) ;
96+ getConfigurationStub = sinon . stub ( workspaceApis , 'getConfiguration' ) ;
97+ pythonConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
98+ editorConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
99+ getConfigurationStub . callsFake ( ( section : string ) => {
100+ if ( section === 'python' ) {
101+ return pythonConfig . object ;
102+ }
103+ return editorConfig . object ;
104+ } ) ;
91105 } ) ;
92106 teardown ( ( ) => {
93107 if ( service ) {
94108 service . dispose ( ) ;
95109 }
96110 disposables . filter ( ( item ) => ! ! item ) . forEach ( ( item ) => item . dispose ( ) ) ;
111+ sinon . restore ( ) ;
97112 } ) ;
98113
99114 test ( 'Ensure terminal is disposed' , async ( ) => {
@@ -103,13 +118,15 @@ suite('Terminal Service', () => {
103118 const os : string = 'windows' ;
104119 service = new TerminalService ( mockServiceContainer . object ) ;
105120 const shellPath = 'powershell.exe' ;
121+ // TODO: switch over legacy Terminal code to use workspace getConfiguration from workspaceApis instead of directly from vscode.workspace
106122 workspaceService
107123 . setup ( ( w ) => w . getConfiguration ( TypeMoq . It . isValue ( 'terminal.integrated.shell' ) ) )
108124 . returns ( ( ) => {
109125 const workspaceConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
110126 workspaceConfig . setup ( ( c ) => c . get ( os ) ) . returns ( ( ) => shellPath ) ;
111127 return workspaceConfig . object ;
112128 } ) ;
129+ pythonConfig . setup ( ( p ) => p . get ( 'terminal.shellIntegration.enabled' ) ) . returns ( ( ) => false ) ;
113130
114131 platformService . setup ( ( p ) => p . isWindows ) . returns ( ( ) => os === 'windows' ) ;
115132 platformService . setup ( ( p ) => p . isLinux ) . returns ( ( ) => os === 'linux' ) ;
@@ -134,6 +151,7 @@ suite('Terminal Service', () => {
134151 } ) ;
135152
136153 test ( 'Ensure command is sent to terminal and it is shown' , async ( ) => {
154+ pythonConfig . setup ( ( p ) => p . get ( 'terminal.shellIntegration.enabled' ) ) . returns ( ( ) => false ) ;
137155 terminalHelper
138156 . setup ( ( helper ) => helper . getEnvironmentActivationCommands ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
139157 . returns ( ( ) => Promise . resolve ( undefined ) ) ;
0 commit comments