Skip to content

Commit

Permalink
attach callback to executeCommand so onDidEndTerminalShellExecutionEm…
Browse files Browse the repository at this point in the history
…itter fires
  • Loading branch information
anthonykim1 committed Sep 11, 2024
1 parent 923df5c commit 16839c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/client/common/terminal/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 27 additions & 2 deletions src/test/common/terminals/service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,34 @@ suite('Terminal Service', () => {
terminal = TypeMoq.Mock.ofType<VSCodeTerminal>();
terminalShellIntegration = TypeMoq.Mock.ofType<TerminalShellIntegration>();
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<TerminalShellExecution> = TypeMoq.Mock.ofType<TerminalShellExecution>();

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<string> {
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<ITerminalManager>();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 16839c9

Please sign in to comment.