Skip to content

Commit 6f0d49f

Browse files
committed
test(terminal): assert shell integration wait ordering
1 parent f093331 commit 6f0d49f

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/test/features/terminal/runInTerminal.unit.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ suite('runInTerminal', () => {
1818
test('waits for shell integration before executing a command', async () => {
1919
sinon.stub(shellDetector, 'identifyTerminalShell').returns('fish');
2020
const waitForShellIntegrationStub = sinon.stub(terminalUtils, 'waitForShellIntegration');
21+
let resolveWaitForShellIntegration!: (result: boolean) => void;
22+
const waitForShellIntegrationPromise = new Promise<boolean>((resolve) => {
23+
resolveWaitForShellIntegration = resolve;
24+
});
2125

2226
const execution = {} as TerminalShellExecution;
2327
const shellIntegration = {
@@ -28,10 +32,7 @@ suite('runInTerminal', () => {
2832
shellIntegration: undefined,
2933
sendText: sinon.stub(),
3034
} as unknown as Terminal;
31-
waitForShellIntegrationStub.callsFake(async () => {
32-
(terminal as { shellIntegration?: typeof shellIntegration }).shellIntegration = shellIntegration;
33-
return true;
34-
});
35+
waitForShellIntegrationStub.returns(waitForShellIntegrationPromise);
3536

3637
let endListener: ((event: TerminalShellExecutionEndEvent) => void) | undefined;
3738
sinon.stub(windowApis, 'onDidEndTerminalShellExecution').callsFake((listener) => {
@@ -44,6 +45,13 @@ suite('runInTerminal', () => {
4445
await new Promise<void>((resolve) => setImmediate(resolve));
4546

4647
sinon.assert.calledOnce(waitForShellIntegrationStub);
48+
sinon.assert.notCalled(terminal.sendText as sinon.SinonStub);
49+
sinon.assert.notCalled(shellIntegration.executeCommand);
50+
51+
(terminal as { shellIntegration?: typeof shellIntegration }).shellIntegration = shellIntegration;
52+
resolveWaitForShellIntegration(true);
53+
await new Promise<void>((resolve) => setImmediate(resolve));
54+
4755
sinon.assert.notCalled(terminal.sendText as sinon.SinonStub);
4856
sinon.assert.calledOnce(shellIntegration.executeCommand);
4957
assert.ok(endListener, 'shell execution end listener should be registered');

0 commit comments

Comments
 (0)