Skip to content

Commit 701b5a7

Browse files
author
Eric Wheeler
committed
test: align terminal tests with shell integration safeguards
Update TerminalProcessExec tests to properly handle shell integration event sequences: - Set terminal.running=true before command execution - Remove duplicate command execution that could trigger extra events - Replace arbitrary timeout with event-based waiting for output - Ensure proper event sequence (run -> start -> output -> end) This aligns the tests with the safeguards added in 62ffa79 that prevent spurious shell integration events from corrupting terminal state. Signed-off-by: Eric Wheeler <[email protected]>
1 parent 62ffa79 commit 701b5a7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/integrations/terminal/__tests__/TerminalProcessExec.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ async function testTerminalCommand(
129129
sendText: jest.fn(),
130130
}
131131

132-
// Create terminal info
132+
// Create terminal info with running state
133133
const mockTerminalInfo = new Terminal(1, mockTerminal, "/test/path")
134+
mockTerminalInfo.running = true
134135

135136
// Add the terminal to the registry
136137
TerminalRegistry["terminals"] = [mockTerminalInfo]
@@ -150,9 +151,6 @@ async function testTerminalCommand(
150151
}
151152
})
152153

153-
// Execute the command
154-
terminalProcess.run(command)
155-
156154
// Set up event listeners to capture output
157155
let capturedOutput = ""
158156
terminalProcess.on("completed", (output) => {
@@ -181,6 +179,9 @@ async function testTerminalCommand(
181179
// Get the event handlers from the mock
182180
const eventHandlers = (vscode as any).__eventHandlers
183181

182+
// Execute the command first to set up the process
183+
terminalProcess.run(command)
184+
184185
// Trigger the start terminal shell execution event through VSCode mock
185186
if (eventHandlers.startTerminalShellExecution) {
186187
eventHandlers.startTerminalShellExecution({
@@ -192,10 +193,12 @@ async function testTerminalCommand(
192193
})
193194
}
194195

195-
// Wait a short time to ensure stream processing has started
196-
await new Promise((resolve) => setTimeout(resolve, 100))
196+
// Wait for some output to be processed
197+
await new Promise<void>((resolve) => {
198+
terminalProcess.once("line", () => resolve())
199+
})
197200

198-
// Trigger the end terminal shell execution event through VSCode mock
201+
// Then trigger the end event
199202
if (eventHandlers.endTerminalShellExecution) {
200203
eventHandlers.endTerminalShellExecution({
201204
terminal: mockTerminal,

0 commit comments

Comments
 (0)