4
4
import { expect } from 'chai' ;
5
5
import * as path from 'path' ;
6
6
import * as TypeMoq from 'typemoq' ;
7
- import { Disposable , Terminal as VSCodeTerminal , WorkspaceConfiguration } from 'vscode' ;
7
+ import {
8
+ Disposable ,
9
+ EventEmitter ,
10
+ TerminalShellExecution ,
11
+ TerminalShellExecutionEndEvent ,
12
+ TerminalShellIntegration ,
13
+ Terminal as VSCodeTerminal ,
14
+ WorkspaceConfiguration ,
15
+ } from 'vscode' ;
8
16
import { ITerminalManager , IWorkspaceService } from '../../../client/common/application/types' ;
9
17
import { EXTENSION_ROOT_DIR } from '../../../client/common/constants' ;
10
18
import { IPlatformService } from '../../../client/common/platform/types' ;
@@ -26,9 +34,44 @@ suite('Terminal Service', () => {
26
34
let disposables : Disposable [ ] = [ ] ;
27
35
let mockServiceContainer : TypeMoq . IMock < IServiceContainer > ;
28
36
let terminalAutoActivator : TypeMoq . IMock < ITerminalAutoActivation > ;
37
+ let terminalShellIntegration : TypeMoq . IMock < TerminalShellIntegration > ;
38
+ let onDidEndTerminalShellExecutionEmitter : EventEmitter < TerminalShellExecutionEndEvent > ;
39
+ let event : TerminalShellExecutionEndEvent ;
40
+
29
41
setup ( ( ) => {
30
42
terminal = TypeMoq . Mock . ofType < VSCodeTerminal > ( ) ;
43
+ terminalShellIntegration = TypeMoq . Mock . ofType < TerminalShellIntegration > ( ) ;
44
+ terminal . setup ( ( t ) => t . shellIntegration ) . returns ( ( ) => terminalShellIntegration . object ) ;
45
+
46
+ onDidEndTerminalShellExecutionEmitter = new EventEmitter < TerminalShellExecutionEndEvent > ( ) ;
31
47
terminalManager = TypeMoq . Mock . ofType < ITerminalManager > ( ) ;
48
+ const execution : TerminalShellExecution = {
49
+ commandLine : {
50
+ value : 'dummy text' ,
51
+ isTrusted : true ,
52
+ confidence : 2 ,
53
+ } ,
54
+ cwd : undefined ,
55
+ read : function ( ) : AsyncIterable < string > {
56
+ throw new Error ( 'Function not implemented.' ) ;
57
+ } ,
58
+ } ;
59
+
60
+ event = {
61
+ execution,
62
+ exitCode : 0 ,
63
+ terminal : terminal . object ,
64
+ shellIntegration : terminalShellIntegration . object ,
65
+ } ;
66
+
67
+ terminalShellIntegration . setup ( ( t ) => t . executeCommand ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => execution ) ;
68
+
69
+ terminalManager
70
+ . setup ( ( t ) => t . onDidEndTerminalShellExecution )
71
+ . returns ( ( ) => {
72
+ setTimeout ( ( ) => onDidEndTerminalShellExecutionEmitter . fire ( event ) , 100 ) ;
73
+ return onDidEndTerminalShellExecutionEmitter . event ;
74
+ } ) ;
32
75
platformService = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
33
76
workspaceService = TypeMoq . Mock . ofType < IWorkspaceService > ( ) ;
34
77
terminalHelper = TypeMoq . Mock . ofType < ITerminalHelper > ( ) ;
@@ -37,6 +80,7 @@ suite('Terminal Service', () => {
37
80
disposables = [ ] ;
38
81
39
82
mockServiceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
83
+
40
84
mockServiceContainer . setup ( ( c ) => c . get ( ITerminalManager ) ) . returns ( ( ) => terminalManager . object ) ;
41
85
mockServiceContainer . setup ( ( c ) => c . get ( ITerminalHelper ) ) . returns ( ( ) => terminalHelper . object ) ;
42
86
mockServiceContainer . setup ( ( c ) => c . get ( IPlatformService ) ) . returns ( ( ) => platformService . object ) ;
@@ -75,10 +119,16 @@ suite('Terminal Service', () => {
75
119
. setup ( ( h ) => h . buildCommandForTerminal ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
76
120
. returns ( ( ) => 'dummy text' ) ;
77
121
122
+ terminalManager
123
+ . setup ( ( t ) => t . onDidEndTerminalShellExecution )
124
+ . returns ( ( ) => {
125
+ setTimeout ( ( ) => onDidEndTerminalShellExecutionEmitter . fire ( event ) , 100 ) ;
126
+ return onDidEndTerminalShellExecutionEmitter . event ;
127
+ } ) ;
78
128
// Sending a command will cause the terminal to be created
79
129
await service . sendCommand ( '' , [ ] ) ;
80
130
81
- terminal . verify ( ( t ) => t . show ( TypeMoq . It . isValue ( true ) ) , TypeMoq . Times . exactly ( 2 ) ) ;
131
+ terminal . verify ( ( t ) => t . show ( TypeMoq . It . isValue ( true ) ) , TypeMoq . Times . atLeastOnce ( ) ) ;
82
132
service . dispose ( ) ;
83
133
terminal . verify ( ( t ) => t . dispose ( ) , TypeMoq . Times . exactly ( 1 ) ) ;
84
134
} ) ;
@@ -99,10 +149,10 @@ suite('Terminal Service', () => {
99
149
100
150
await service . sendCommand ( commandToSend , args ) ;
101
151
102
- terminal . verify ( ( t ) => t . show ( TypeMoq . It . isValue ( true ) ) , TypeMoq . Times . exactly ( 2 ) ) ;
152
+ terminal . verify ( ( t ) => t . show ( TypeMoq . It . isValue ( true ) ) , TypeMoq . Times . atLeastOnce ( ) ) ;
103
153
terminal . verify (
104
154
( t ) => t . sendText ( TypeMoq . It . isValue ( commandToExpect ) , TypeMoq . It . isValue ( true ) ) ,
105
- TypeMoq . Times . exactly ( 1 ) ,
155
+ TypeMoq . Times . never ( ) ,
106
156
) ;
107
157
} ) ;
108
158
0 commit comments