Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/externalTerminal/test/electron-main/externalTerminalService.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { deepStrictEqual, strictEqual } from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
8
import { DEFAULT_TERMINAL_OSX, IExternalTerminalConfiguration } from '../../common/externalTerminal.js';
9
import { LinuxExternalTerminalService, MacExternalTerminalService, WindowsExternalTerminalService } from '../../node/externalTerminalService.js';
10
11
const mockConfig = Object.freeze<IExternalTerminalConfiguration>({
12
terminal: {
13
explorerKind: 'external',
14
external: {
15
windowsExec: 'testWindowsShell',
16
osxExec: 'testOSXShell',
17
linuxExec: 'testLinuxShell'
18
}
19
}
20
});
21
22
suite('ExternalTerminalService', () => {
23
ensureNoDisposablesAreLeakedInTestSuite();
24
25
test(`WinTerminalService - uses terminal from configuration`, done => {
26
const testShell = 'cmd';
27
const testCwd = 'path/to/workspace';
28
const mockSpawner: any = {
29
spawn: (command: any, args: any, opts: any) => {
30
strictEqual(command, testShell, 'shell should equal expected');
31
strictEqual(args[args.length - 1], mockConfig.terminal.external.windowsExec);
32
strictEqual(opts.cwd, testCwd);
33
done();
34
return {
35
on: (evt: any) => evt
36
};
37
}
38
};
39
const testService = new WindowsExternalTerminalService();
40
testService.spawnTerminal(
41
mockSpawner,
42
mockConfig.terminal.external,
43
testShell,
44
testCwd
45
);
46
});
47
48
test(`WinTerminalService - uses default terminal when configuration.terminal.external.windowsExec is undefined`, done => {
49
const testShell = 'cmd';
50
const testCwd = 'path/to/workspace';
51
const mockSpawner: any = {
52
spawn: (command: any, args: any, opts: any) => {
53
strictEqual(args[args.length - 1], WindowsExternalTerminalService.getDefaultTerminalWindows());
54
done();
55
return {
56
on: (evt: any) => evt
57
};
58
}
59
};
60
mockConfig.terminal.external.windowsExec = undefined;
61
const testService = new WindowsExternalTerminalService();
62
testService.spawnTerminal(
63
mockSpawner,
64
mockConfig.terminal.external,
65
testShell,
66
testCwd
67
);
68
});
69
70
test(`WinTerminalService - cwd is correct regardless of case`, done => {
71
const testShell = 'cmd';
72
const testCwd = 'c:/foo';
73
const mockSpawner: any = {
74
spawn: (command: any, args: any, opts: any) => {
75
strictEqual(opts.cwd, 'C:/foo', 'cwd should be uppercase regardless of the case that\'s passed in');
76
done();
77
return {
78
on: (evt: any) => evt
79
};
80
}
81
};
82
const testService = new WindowsExternalTerminalService();
83
testService.spawnTerminal(
84
mockSpawner,
85
mockConfig.terminal.external,
86
testShell,
87
testCwd
88
);
89
});
90
91
test(`WinTerminalService - cmder should be spawned differently`, done => {
92
const testShell = 'cmd';
93
const testCwd = 'c:/foo';
94
const mockSpawner: any = {
95
spawn: (command: any, args: any, opts: any) => {
96
deepStrictEqual(args, ['C:/foo']);
97
strictEqual(opts, undefined);
98
done();
99
return { on: (evt: any) => evt };
100
}
101
};
102
const testService = new WindowsExternalTerminalService();
103
testService.spawnTerminal(
104
mockSpawner,
105
{ windowsExec: 'cmder' },
106
testShell,
107
testCwd
108
);
109
});
110
111
test(`WinTerminalService - windows terminal should open workspace directory`, done => {
112
const testShell = 'wt';
113
const testCwd = 'c:/foo';
114
const mockSpawner: any = {
115
spawn: (command: any, args: any, opts: any) => {
116
strictEqual(opts.cwd, 'C:/foo');
117
done();
118
return { on: (evt: any) => evt };
119
}
120
};
121
const testService = new WindowsExternalTerminalService();
122
testService.spawnTerminal(
123
mockSpawner,
124
mockConfig.terminal.external,
125
testShell,
126
testCwd
127
);
128
});
129
130
test(`MacTerminalService - uses terminal from configuration`, done => {
131
const testCwd = 'path/to/workspace';
132
const mockSpawner: any = {
133
spawn: (command: any, args: any, opts: any) => {
134
strictEqual(args[1], mockConfig.terminal.external.osxExec);
135
done();
136
return {
137
on: (evt: any) => evt
138
};
139
}
140
};
141
const testService = new MacExternalTerminalService();
142
testService.spawnTerminal(
143
mockSpawner,
144
mockConfig.terminal.external,
145
testCwd
146
);
147
});
148
149
test(`MacTerminalService - uses default terminal when configuration.terminal.external.osxExec is undefined`, done => {
150
const testCwd = 'path/to/workspace';
151
const mockSpawner: any = {
152
spawn: (command: any, args: any, opts: any) => {
153
strictEqual(args[1], DEFAULT_TERMINAL_OSX);
154
done();
155
return {
156
on: (evt: any) => evt
157
};
158
}
159
};
160
const testService = new MacExternalTerminalService();
161
testService.spawnTerminal(
162
mockSpawner,
163
{ osxExec: undefined },
164
testCwd
165
);
166
});
167
168
test(`LinuxTerminalService - uses terminal from configuration`, done => {
169
const testCwd = 'path/to/workspace';
170
const mockSpawner: any = {
171
spawn: (command: any, args: any, opts: any) => {
172
strictEqual(command, mockConfig.terminal.external.linuxExec);
173
strictEqual(opts.cwd, testCwd);
174
done();
175
return {
176
on: (evt: any) => evt
177
};
178
}
179
};
180
const testService = new LinuxExternalTerminalService();
181
testService.spawnTerminal(
182
mockSpawner,
183
mockConfig.terminal.external,
184
testCwd
185
);
186
});
187
188
test(`LinuxTerminalService - uses default terminal when configuration.terminal.external.linuxExec is undefined`, done => {
189
LinuxExternalTerminalService.getDefaultTerminalLinuxReady().then(defaultTerminalLinux => {
190
const testCwd = 'path/to/workspace';
191
const mockSpawner: any = {
192
spawn: (command: any, args: any, opts: any) => {
193
strictEqual(command, defaultTerminalLinux);
194
done();
195
return {
196
on: (evt: any) => evt
197
};
198
}
199
};
200
mockConfig.terminal.external.linuxExec = undefined;
201
const testService = new LinuxExternalTerminalService();
202
testService.spawnTerminal(
203
mockSpawner,
204
mockConfig.terminal.external,
205
testCwd
206
);
207
});
208
});
209
});
210
211