@@ -17,6 +17,10 @@ const terminalMock = {
17
17
} ,
18
18
} ;
19
19
20
+ const cancelTokenMock = {
21
+ onCancellationRequested : vi . fn ( ) ,
22
+ } ;
23
+
20
24
vi . mock ( "vscode" , ( ) => {
21
25
// mock Disposable
22
26
const disposableMock = vi . fn ( ) ;
@@ -28,7 +32,7 @@ vi.mock("vscode", () => {
28
32
showWarningMessage : vi . fn ( ) ,
29
33
showInformationMessage : vi . fn ( ) ,
30
34
withProgress : vi . fn ( ) . mockImplementation ( ( _ , progressCallback ) => {
31
- progressCallback ( ) ;
35
+ progressCallback ( _ , cancelTokenMock ) ;
32
36
} ) ,
33
37
createTerminal : vi . fn ( ) . mockImplementation ( ( ) => {
34
38
terminalMock . sendText = vi . fn ( ) ;
@@ -92,21 +96,44 @@ describe("Consumers of vscode window", () => {
92
96
) ;
93
97
} ) ;
94
98
95
- test ( "taskWithProgressMsg" , ( ) => {
96
- const taskMock = vi . fn ( ) ;
97
- taskWithProgressMsg (
98
- "Running a task with a progress notification" ,
99
- taskMock ,
100
- ) ;
101
- expect ( window . withProgress ) . toHaveBeenCalledWith (
102
- {
103
- location : 15 ,
104
- title : "Running a task with a progress notification" ,
105
- cancellable : false ,
106
- } ,
107
- expect . any ( Function ) ,
108
- ) ;
109
- expect ( taskMock ) . toHaveBeenCalled ( ) ;
99
+ describe ( "taskWithProgressMsg" , ( ) => {
100
+ test ( "not cancellable" , ( ) => {
101
+ const taskMock = vi . fn ( ) ;
102
+ taskWithProgressMsg (
103
+ "Running a task with a progress notification" ,
104
+ taskMock ,
105
+ ) ;
106
+ expect ( window . withProgress ) . toHaveBeenCalledWith (
107
+ {
108
+ location : 15 ,
109
+ title : "Running a task with a progress notification" ,
110
+ cancellable : false ,
111
+ } ,
112
+ expect . any ( Function ) ,
113
+ ) ;
114
+ expect ( taskMock ) . toHaveBeenCalled ( ) ;
115
+ expect ( cancelTokenMock . onCancellationRequested ) . not . toHaveBeenCalled ( ) ;
116
+ } ) ;
117
+
118
+ test ( "cancellable" , ( ) => {
119
+ const taskMock = vi . fn ( ) ;
120
+ taskWithProgressMsg (
121
+ "Running a task with a progress notification" ,
122
+ taskMock ,
123
+ ( ) => { } ,
124
+ ) ;
125
+ expect ( window . withProgress ) . toHaveBeenCalledWith (
126
+ {
127
+ location : 15 ,
128
+ title : "Running a task with a progress notification" ,
129
+ cancellable : true ,
130
+ } ,
131
+ expect . any ( Function ) ,
132
+ ) ;
133
+ // Cancel listener is registered
134
+ expect ( taskMock ) . toHaveBeenCalled ( ) ;
135
+ expect ( cancelTokenMock . onCancellationRequested ) . toHaveBeenCalled ( ) ;
136
+ } ) ;
110
137
} ) ;
111
138
112
139
describe ( "runTerminalCommand" , ( ) => {
0 commit comments