@@ -13,22 +13,184 @@ import { TestConfigurationService } from 'vs/platform/configuration/test/common/
13
13
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock' ;
14
14
import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities' ;
15
15
import { TerminalCapabilityStore } from 'vs/platform/terminal/common/capabilities/terminalCapabilityStore' ;
16
- import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace' ;
17
- import { ITerminalConfigurationService , ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal' ;
16
+ import { IWorkspaceFolder , IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
17
+ import { ITerminalConfigurationService , ITerminalInstance , ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal' ;
18
18
import { TerminalConfigurationService } from 'vs/workbench/contrib/terminal/browser/terminalConfigurationService' ;
19
- import { TerminalLabelComputer , parseExitResult } from 'vs/workbench/contrib/terminal/browser/terminalInstance' ;
20
- import { ProcessState } from 'vs/workbench/contrib/terminal/common/terminal' ;
19
+ import { TerminalLabelComputer , parseExitResult , TerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminalInstance' ;
20
+ import { ProcessState , ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal' ;
21
21
import { fixPath } from 'vs/workbench/services/search/test/browser/queryBuilder.test' ;
22
- import { workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices' ;
22
+ import { workbenchInstantiationService , TestEnvironmentService , TestLayoutService , TestLifecycleService , TestPathService , TestTerminalProfileResolverService } from 'vs/workbench/test/browser/workbenchTestServices' ;
23
+ import { TestContextService , TestExtensionService , TestHistoryService , TestStorageService } from 'vs/workbench/test/common/workbenchTestServices' ;
24
+ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
25
+ import { TestAccessibilityService } from 'vs/platform/accessibility/test/common/testAccessibilityService' ;
26
+ import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService' ;
27
+ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
28
+ import { ContextMenuService } from 'vs/platform/contextview/browser/contextMenuService' ;
29
+ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
30
+ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
31
+ import { MockKeybindingService } from 'vs/platform/keybinding/test/common/mockKeybindingService' ;
32
+ import { ILayoutService } from 'vs/platform/layout/browser/layoutService' ;
33
+ import { NullLogService } from 'vs/platform/log/common/log' ;
34
+ import { IProductService } from 'vs/platform/product/common/productService' ;
35
+ import { IStorageService } from 'vs/platform/storage/common/storage' ;
36
+ import { ITerminalChildProcess , ITerminalLogService , ITerminalProfile } from 'vs/platform/terminal/common/terminal' ;
37
+ import { IThemeService } from 'vs/platform/theme/common/themeService' ;
38
+ import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService' ;
39
+ import { IViewDescriptorService } from 'vs/workbench/common/views' ;
40
+ import { IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable' ;
41
+ import { EnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariableService' ;
42
+ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
43
+ import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
44
+ import { IHistoryService } from 'vs/workbench/services/history/common/history' ;
45
+ import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
46
+ import { IPathService } from 'vs/workbench/services/path/common/pathService' ;
47
+ import { Event } from 'vs/base/common/event' ;
48
+ import { Disposable } from 'vs/base/common/lifecycle' ;
49
+ import { TestViewDescriptorService } from 'vs/workbench/contrib/terminal/test/browser/xterm/xtermTerminal.test' ;
23
50
24
51
const root1 = '/foo/root1' ;
25
52
const ROOT_1 = fixPath ( root1 ) ;
26
53
const root2 = '/foo/root2' ;
27
54
const ROOT_2 = fixPath ( root2 ) ;
28
55
56
+ class MockTerminalProfileResolverService extends TestTerminalProfileResolverService {
57
+ override async getDefaultProfile ( ) : Promise < ITerminalProfile > {
58
+ return {
59
+ profileName : "my-sh" ,
60
+ path : "/usr/bin/zsh" ,
61
+ env : {
62
+ TEST : "TEST" ,
63
+ } ,
64
+ isDefault : true ,
65
+ isUnsafePath : false ,
66
+ isFromPath : true ,
67
+ icon : {
68
+ id : "terminal-linux" ,
69
+ } ,
70
+ color : "terminal.ansiYellow" ,
71
+ } ;
72
+ }
73
+ }
74
+
75
+ const terminalShellTypeContextKey = {
76
+ set : ( ) => { } ,
77
+ reset : ( ) => { } ,
78
+ get : ( ) => undefined
79
+ } ;
80
+
81
+ const terminalInRunCommandPicker = {
82
+ set : ( ) => { } ,
83
+ reset : ( ) => { } ,
84
+ get : ( ) => undefined
85
+ } ;
86
+
87
+ class TestTerminalChildProcess extends Disposable implements ITerminalChildProcess {
88
+ id : number = 0 ;
89
+ get capabilities ( ) { return [ ] ; }
90
+ constructor (
91
+ readonly shouldPersist : boolean
92
+ ) {
93
+ super ( ) ;
94
+ }
95
+ updateProperty ( property : any , value : any ) : Promise < void > {
96
+ throw new Error ( 'Method not implemented.' ) ;
97
+ }
98
+
99
+ onProcessOverrideDimensions ?: Event < any > | undefined ;
100
+ onProcessResolvedShellLaunchConfig ?: Event < any > | undefined ;
101
+ onDidChangeHasChildProcesses ?: Event < any > | undefined ;
102
+
103
+ onDidChangeProperty = Event . None ;
104
+ onProcessData = Event . None ;
105
+ onProcessExit = Event . None ;
106
+ onProcessReady = Event . None ;
107
+ onProcessTitleChanged = Event . None ;
108
+ onProcessShellTypeChanged = Event . None ;
109
+ async start ( ) : Promise < undefined > { return undefined ; }
110
+ shutdown ( immediate : boolean ) : void { }
111
+ input ( data : string ) : void { }
112
+ resize ( cols : number , rows : number ) : void { }
113
+ clearBuffer ( ) : void { }
114
+ acknowledgeDataEvent ( charCount : number ) : void { }
115
+ async setUnicodeVersion ( version : '6' | '11' ) : Promise < void > { }
116
+ async getInitialCwd ( ) : Promise < string > { return '' ; }
117
+ async getCwd ( ) : Promise < string > { return '' ; }
118
+ async processBinary ( data : string ) : Promise < void > { }
119
+ refreshProperty ( property : any ) : Promise < any > { return Promise . resolve ( '' ) ; }
120
+ }
121
+
122
+ class TestTerminalInstanceService extends Disposable implements Partial < ITerminalInstanceService > {
123
+ getBackend ( ) {
124
+ return {
125
+ onPtyHostExit : Event . None ,
126
+ onPtyHostUnresponsive : Event . None ,
127
+ onPtyHostResponsive : Event . None ,
128
+ onPtyHostRestart : Event . None ,
129
+ onDidMoveWindowInstance : Event . None ,
130
+ onDidRequestDetach : Event . None ,
131
+ createProcess : (
132
+ shellLaunchConfig : any ,
133
+ cwd : string ,
134
+ cols : number ,
135
+ rows : number ,
136
+ unicodeVersion : '6' | '11' ,
137
+ env : any ,
138
+ windowsEnableConpty : boolean ,
139
+ shouldPersist : boolean
140
+ ) => this . _register ( new TestTerminalChildProcess ( shouldPersist ) ) ,
141
+ getLatency : ( ) => Promise . resolve ( [ ] )
142
+ } as any ;
143
+ }
144
+ }
145
+
29
146
suite ( 'Workbench - TerminalInstance' , ( ) => {
30
147
const store = ensureNoDisposablesAreLeakedInTestSuite ( ) ;
31
148
149
+ suite ( 'TerminalInstance' , ( ) => {
150
+ let terminalInstance : ITerminalInstance ;
151
+ test ( 'should create an instance of TerminalInstance with env from default profile' , async ( ) => {
152
+ const instantiationService = workbenchInstantiationService ( undefined , store ) ;
153
+ instantiationService . stub ( IConfigurationService , new TestConfigurationService ( {
154
+ terminal : {
155
+ integrated : {
156
+ fontFamily : 'monospace' ,
157
+ scrollback : 1000 ,
158
+ fastScrollSensitivity : 2 ,
159
+ mouseWheelScrollSensitivity : 1 ,
160
+ unicodeVersion : '6' ,
161
+ shellIntegration : {
162
+ enabled : true
163
+ } ,
164
+ }
165
+ } ,
166
+ } ) ) ;
167
+ instantiationService . stub ( IContextKeyService , store . add ( instantiationService . createInstance ( ContextKeyService ) ) ) ;
168
+ instantiationService . stub ( IWorkbenchEnvironmentService , TestEnvironmentService ) ;
169
+ const mockTerminalProfileResolverService = new MockTerminalProfileResolverService ( ) ;
170
+ instantiationService . set ( ITerminalProfileResolverService , mockTerminalProfileResolverService ) ;
171
+ instantiationService . stub ( IWorkspaceContextService , new TestContextService ( ) ) ;
172
+ instantiationService . stub ( IHistoryService , new TestHistoryService ( ) ) ;
173
+ instantiationService . stub ( ITerminalLogService , store . add ( new NullLogService ( ) ) ) ;
174
+ instantiationService . stub ( IKeybindingService , new MockKeybindingService ( ) ) ;
175
+ instantiationService . stub ( ITerminalConfigurationService , store . add ( instantiationService . createInstance ( TerminalConfigurationService ) ) ) ;
176
+ instantiationService . stub ( ILayoutService , new TestLayoutService ( ) ) ;
177
+ instantiationService . stub ( IThemeService , new TestThemeService ( ) ) ;
178
+ instantiationService . stub ( IViewDescriptorService , new TestViewDescriptorService ( ) ) ;
179
+ instantiationService . stub ( ILifecycleService , store . add ( new TestLifecycleService ( ) ) ) ;
180
+ instantiationService . stub ( IContextMenuService , store . add ( instantiationService . createInstance ( ContextMenuService ) ) ) ;
181
+ instantiationService . stub ( IAccessibilityService , new TestAccessibilityService ( ) ) ;
182
+ instantiationService . stub ( IPathService , new TestPathService ( ) ) ;
183
+ instantiationService . stub ( IProductService , { } ) ;
184
+ instantiationService . stub ( IExtensionService , new TestExtensionService ( ) ) ;
185
+ instantiationService . stub ( IStorageService , store . add ( new TestStorageService ( ) ) ) ;
186
+ instantiationService . stub ( IEnvironmentVariableService , store . add ( instantiationService . createInstance ( EnvironmentVariableService ) ) ) ;
187
+ instantiationService . stub ( ITerminalInstanceService , store . add ( new TestTerminalInstanceService ( ) ) ) ;
188
+ terminalInstance = store . add ( instantiationService . createInstance ( TerminalInstance , terminalShellTypeContextKey , terminalInRunCommandPicker , { } ) ) ;
189
+ // //Wait for the teminalInstance._xtermReadyPromise to resolve
190
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
191
+ deepStrictEqual ( terminalInstance . shellLaunchConfig . env , { TEST : 'TEST' } ) ;
192
+ } ) ;
193
+ } ) ;
32
194
suite ( 'parseExitResult' , ( ) => {
33
195
test ( 'should return no message for exit code = undefined' , ( ) => {
34
196
deepStrictEqual (
0 commit comments