From 16839c9092ce70d0ede1cd6c7741c05324fa1820 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 10 Sep 2024 23:36:28 -0700 Subject: [PATCH] attach callback to executeCommand so onDidEndTerminalShellExecutionEmitter fires --- src/client/common/terminal/service.ts | 3 ++ .../common/terminals/service.unit.test.ts | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index d218fe9dd54e..fbbc4f1d8091 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -111,6 +111,9 @@ export class TerminalService implements ITerminalService, Disposable { if (listener) { this.executeCommandListeners.add(listener); } + // setTimeout(() => { + // resolve(undefined); + // }, 10000); // This would be a work around for testing scenario -- would it be a good design outside of testing case? }); } else { terminal.sendText(commandLine); diff --git a/src/test/common/terminals/service.unit.test.ts b/src/test/common/terminals/service.unit.test.ts index ee0bf8384aeb..b6f88e7e4dbb 100644 --- a/src/test/common/terminals/service.unit.test.ts +++ b/src/test/common/terminals/service.unit.test.ts @@ -42,11 +42,34 @@ suite('Terminal Service', () => { terminal = TypeMoq.Mock.ofType(); terminalShellIntegration = TypeMoq.Mock.ofType(); terminal.setup((t) => t.shellIntegration).returns(() => terminalShellIntegration.object); - // terminal.setup((t) => t.shellIntegration).returns(() => undefined); + // terminal.setup((t) => t.shellIntegration).returns(() => undefined); -- always disable shell integration => passes test const shellExecution: TypeMoq.IMock = TypeMoq.Mock.ofType(); terminalShellIntegration .setup((t) => t.executeCommand(TypeMoq.It.isAny())) + .callback(() => { + const execution: TerminalShellExecution = { + commandLine: { + value: 'dummy text', + isTrusted: true, + confidence: 2, + }, + cwd: undefined, + read: function (): AsyncIterable { + throw new Error('Function not implemented.'); + }, + }; + const exitCode = 0; + + const event: TerminalShellExecutionEndEvent = { + execution, + exitCode, + terminal: terminal.object, + shellIntegration: terminalShellIntegration.object, + }; + + onDidEndTerminalShellExecutionEmitter.fire(event); + }) .returns(() => shellExecution.object); terminalManager = TypeMoq.Mock.ofType(); @@ -81,8 +104,10 @@ suite('Terminal Service', () => { // Add a listener to capture the event argument onDidEndTerminalShellExecutionEmitter.event((e) => { try { - expect(e.execution).to.equal(execution); + expect(e.execution.commandLine.value).to.equal(execution.commandLine.value); expect(e.exitCode).to.equal(exitCode); + // resolve + return; } catch (error) { console.error(error); }