Skip to content

Commit 6139608

Browse files
committed
add tests
1 parent b9fd274 commit 6139608

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/test/common/terminals/service.unit.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
2424
import { ITerminalAutoActivation } from '../../../client/terminals/types';
2525
import { createPythonInterpreter } from '../../utils/interpreters';
2626
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis';
27+
import * as platformService from '../../../client/common/platform/platformService';
2728

2829
suite('Terminal Service', () => {
2930
let service: TerminalService;
@@ -42,6 +43,7 @@ suite('Terminal Service', () => {
4243
let getConfigurationStub: sinon.SinonStub;
4344
let pythonConfig: TypeMoq.IMock<WorkspaceConfiguration>;
4445
let editorConfig: TypeMoq.IMock<WorkspaceConfiguration>;
46+
let isWindowsStub: sinon.SinonStub;
4547

4648
setup(() => {
4749
terminal = TypeMoq.Mock.ofType<VSCodeTerminal>();
@@ -94,6 +96,7 @@ suite('Terminal Service', () => {
9496
mockServiceContainer.setup((c) => c.get(ITerminalActivator)).returns(() => terminalActivator.object);
9597
mockServiceContainer.setup((c) => c.get(ITerminalAutoActivation)).returns(() => terminalAutoActivator.object);
9698
getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration');
99+
isWindowsStub = sinon.stub(platformService.object, 'isWindows');
97100
pythonConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
98101
editorConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
99102
getConfigurationStub.callsFake((section: string) => {
@@ -231,7 +234,30 @@ suite('Terminal Service', () => {
231234
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
232235
});
233236

234-
test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled', async () => {
237+
test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux', async () => {
238+
isWindowsStub.returns(false);
239+
pythonConfig
240+
.setup((p) => p.get('terminal.shellIntegration.enabled'))
241+
.returns(() => true)
242+
.verifiable(TypeMoq.Times.once());
243+
244+
terminalHelper
245+
.setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
246+
.returns(() => Promise.resolve(undefined));
247+
service = new TerminalService(mockServiceContainer.object);
248+
const textToSend = 'Some Text';
249+
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
250+
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
251+
252+
service.ensureTerminal();
253+
service.executeCommand(textToSend, true);
254+
255+
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
256+
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.never());
257+
});
258+
259+
test('Ensure sendText IS called even when Python shell integration and terminal shell integration are both enabled - Window', async () => {
260+
isWindowsStub.returns(true);
235261
pythonConfig
236262
.setup((p) => p.get('terminal.shellIntegration.enabled'))
237263
.returns(() => true)

0 commit comments

Comments
 (0)