Skip to content

Commit 9f1d179

Browse files
committed
Try to fix tests
1 parent 46a3b91 commit 9f1d179

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

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

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import {
1414
Uri,
1515
Terminal as VSCodeTerminal,
1616
WorkspaceConfiguration,
17+
TerminalDataWriteEvent,
1718
} from 'vscode';
18-
import { ITerminalManager, IWorkspaceService } from '../../../client/common/application/types';
19+
import { IApplicationShell, ITerminalManager, IWorkspaceService } from '../../../client/common/application/types';
1920
import { EXTENSION_ROOT_DIR } from '../../../client/common/constants';
2021
import { IPlatformService } from '../../../client/common/platform/types';
2122
import { TerminalService } from '../../../client/common/terminal/service';
@@ -56,6 +57,8 @@ suite('Terminal Service', () => {
5657
let useEnvExtensionStub: sinon.SinonStub;
5758
let interpreterService: TypeMoq.IMock<IInterpreterService>;
5859
let options: TypeMoq.IMock<TerminalCreationOptions>;
60+
let applicationShell: TypeMoq.IMock<IApplicationShell>;
61+
let onDidWriteTerminalDataEmitter: EventEmitter<TerminalDataWriteEvent>;
5962

6063
setup(() => {
6164
useEnvExtensionStub = sinon.stub(extapi, 'useEnvExtension');
@@ -118,6 +121,15 @@ suite('Terminal Service', () => {
118121
mockServiceContainer.setup((c) => c.get(ITerminalActivator)).returns(() => terminalActivator.object);
119122
mockServiceContainer.setup((c) => c.get(ITerminalAutoActivation)).returns(() => terminalAutoActivator.object);
120123
mockServiceContainer.setup((c) => c.get(IInterpreterService)).returns(() => interpreterService.object);
124+
125+
// Setup IApplicationShell mock with onDidWriteTerminalData
126+
applicationShell = TypeMoq.Mock.ofType<IApplicationShell>();
127+
onDidWriteTerminalDataEmitter = new EventEmitter<TerminalDataWriteEvent>();
128+
applicationShell
129+
.setup((a) => a.onDidWriteTerminalData)
130+
.returns(() => onDidWriteTerminalDataEmitter.event);
131+
mockServiceContainer.setup((c) => c.get(IApplicationShell)).returns(() => applicationShell.object);
132+
121133
getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration');
122134
isWindowsStub = sinon.stub(platform, 'isWindows');
123135
pythonConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
@@ -230,10 +242,12 @@ suite('Terminal Service', () => {
230242
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
231243
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
232244

233-
service.ensureTerminal();
234-
service.executeCommand(textToSend, true);
245+
await service.ensureTerminal();
246+
// Simulate REPL ready by firing the >>> prompt
247+
onDidWriteTerminalDataEmitter.fire({ terminal: terminal.object, data: '>>> ' });
248+
await service.executeCommand(textToSend, true);
235249

236-
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
250+
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.atLeastOnce());
237251
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
238252
});
239253

@@ -251,10 +265,12 @@ suite('Terminal Service', () => {
251265
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
252266
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
253267

254-
service.ensureTerminal();
255-
service.executeCommand(textToSend, true);
268+
await service.ensureTerminal();
269+
// Simulate REPL ready by firing the >>> prompt
270+
onDidWriteTerminalDataEmitter.fire({ terminal: terminal.object, data: '>>> ' });
271+
await service.executeCommand(textToSend, true);
256272

257-
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
273+
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.atLeastOnce());
258274
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
259275
});
260276

@@ -273,10 +289,12 @@ suite('Terminal Service', () => {
273289
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
274290
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
275291

276-
service.ensureTerminal();
277-
service.executeCommand(textToSend, true);
292+
await service.ensureTerminal();
293+
// Simulate REPL ready by firing the >>> prompt
294+
onDidWriteTerminalDataEmitter.fire({ terminal: terminal.object, data: '>>> ' });
295+
await service.executeCommand(textToSend, true);
278296

279-
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
297+
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.atLeastOnce());
280298
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
281299
});
282300

@@ -305,6 +323,8 @@ suite('Terminal Service', () => {
305323
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
306324

307325
await service.ensureTerminal();
326+
// Simulate REPL ready by firing the >>> prompt
327+
onDidWriteTerminalDataEmitter.fire({ terminal: terminal.object, data: '>>> ' });
308328
await service.executeCommand(textToSend, true);
309329

310330
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.once());
@@ -325,10 +345,12 @@ suite('Terminal Service', () => {
325345
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
326346
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
327347

328-
service.ensureTerminal();
329-
service.executeCommand(textToSend, true);
348+
await service.ensureTerminal();
349+
// Simulate REPL ready by firing the >>> prompt
350+
onDidWriteTerminalDataEmitter.fire({ terminal: terminal.object, data: '>>> ' });
351+
await service.executeCommand(textToSend, true);
330352

331-
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
353+
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.atLeastOnce());
332354
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
333355
});
334356

0 commit comments

Comments
 (0)