4
4
'use strict' ;
5
5
6
6
import * as assert from 'assert' ;
7
- import { anyString , anything , instance , mock , verify , when } from 'ts-mockito' ;
7
+ import * as sinon from 'sinon' ;
8
+ import { anyString , mock , when } from 'ts-mockito' ;
8
9
import { DebugSession , WorkspaceFolder } from 'vscode' ;
9
10
import { DebugProtocol } from 'vscode-debugprotocol' ;
10
- import { ApplicationShell } from '../../../../client/common/application/applicationShell' ;
11
- import { IApplicationShell } from '../../../../client/common/application/types' ;
12
11
import { ConfigurationService } from '../../../../client/common/configuration/service' ;
13
- import { BrowserService } from '../../../../client/common/net/browser' ;
14
- import { IBrowserService , IPythonSettings } from '../../../../client/common/types' ;
15
12
import { createDeferred , sleep } from '../../../../client/common/utils/async' ;
16
13
import { Common } from '../../../../client/common/utils/localize' ;
17
14
import { OutdatedDebuggerPromptFactory } from '../../../../client/debugger/extension/adapter/outdatedDebuggerPrompt' ;
18
15
import { clearTelemetryReporter } from '../../../../client/telemetry' ;
16
+ import * as browser from '../../../../client/debugger/extension/adapter/browser' ;
17
+ import * as common from '../../../../client/debugger/extension/configuration/utils/common' ;
18
+ import { IPythonSettings } from '../../../../client/common/types' ;
19
19
20
20
suite ( 'Debugging - Outdated Debugger Prompt tests.' , ( ) => {
21
21
let promptFactory : OutdatedDebuggerPromptFactory ;
22
- let appShell : IApplicationShell ;
23
- let browserService : IBrowserService ;
22
+ let showInformationMessageStub : sinon . SinonStub ;
23
+ let browserLaunchStub : sinon . SinonStub ;
24
24
25
25
const ptvsdOutputEvent : DebugProtocol . OutputEvent = {
26
26
seq : 1 ,
@@ -42,12 +42,14 @@ suite('Debugging - Outdated Debugger Prompt tests.', () => {
42
42
experiments : { enabled : true } ,
43
43
} as any ) as IPythonSettings ) ;
44
44
45
- appShell = mock ( ApplicationShell ) ;
46
- browserService = mock ( BrowserService ) ;
47
- promptFactory = new OutdatedDebuggerPromptFactory ( instance ( appShell ) , instance ( browserService ) ) ;
45
+ showInformationMessageStub = sinon . stub ( common , 'showInformationMessage' ) ;
46
+ browserLaunchStub = sinon . stub ( browser , 'launch' ) ;
47
+
48
+ promptFactory = new OutdatedDebuggerPromptFactory ( ) ;
48
49
} ) ;
49
50
50
51
teardown ( ( ) => {
52
+ sinon . restore ( ) ;
51
53
clearTelemetryReporter ( ) ;
52
54
} ) ;
53
55
@@ -67,33 +69,38 @@ suite('Debugging - Outdated Debugger Prompt tests.', () => {
67
69
} ;
68
70
}
69
71
70
- test ( 'Show prompt when attaching to ptvsd, more info is NOT clicked' , async ( ) => {
71
- when ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( undefined ) ) ;
72
-
72
+ test . only ( 'Show prompt when attaching to ptvsd, more info is NOT clicked' , async ( ) => {
73
+ // when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(undefined));
74
+ showInformationMessageStub . returns ( Promise . resolve ( undefined ) ) ;
73
75
const session = createSession ( ) ;
74
76
const prompter = await promptFactory . createDebugAdapterTracker ( session ) ;
75
77
if ( prompter ) {
76
78
prompter . onDidSendMessage ! ( ptvsdOutputEvent ) ;
77
79
}
78
80
79
- verify ( browserService . launch ( anyString ( ) ) ) . never ( ) ;
81
+ browserLaunchStub . neverCalledWith ( anyString ( ) ) ;
82
+
80
83
// First call should show info once
81
- verify ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . once ( ) ;
84
+
85
+ sinon . assert . calledOnce ( showInformationMessageStub ) ;
82
86
assert ( prompter ) ;
83
87
84
88
prompter ! . onDidSendMessage ! ( ptvsdOutputEvent ) ;
85
89
// Can't use deferred promise here
86
90
await sleep ( 1 ) ;
87
91
88
- verify ( browserService . launch ( anyString ( ) ) ) . never ( ) ;
92
+ browserLaunchStub . neverCalledWith ( anyString ( ) ) ;
89
93
// Second time it should not be called, so overall count is one.
90
- verify ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . once ( ) ;
94
+ sinon . assert . calledOnce ( showInformationMessageStub ) ;
91
95
} ) ;
92
96
93
97
test ( 'Show prompt when attaching to ptvsd, more info is clicked' , async ( ) => {
94
- when ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( Common . moreInfo ) ) ;
98
+ // when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(Common.moreInfo));
99
+ showInformationMessageStub . returns ( Promise . resolve ( Common . moreInfo ) ) ;
100
+
95
101
const deferred = createDeferred ( ) ;
96
- when ( browserService . launch ( anything ( ) ) ) . thenCall ( ( ) => deferred . resolve ( ) ) ;
102
+ // when(browserService.launch(anything())).thenCall(() => deferred.resolve());
103
+ browserLaunchStub . callsFake ( ( ) => deferred . resolve ( ) ) ;
97
104
98
105
const session = createSession ( ) ;
99
106
const prompter = await promptFactory . createDebugAdapterTracker ( session ) ;
@@ -102,22 +109,26 @@ suite('Debugging - Outdated Debugger Prompt tests.', () => {
102
109
prompter ! . onDidSendMessage ! ( ptvsdOutputEvent ) ;
103
110
await deferred . promise ;
104
111
105
- verify ( browserService . launch ( anything ( ) ) ) . once ( ) ;
112
+ // verify(browserService.launch(anything())).once();
113
+ sinon . assert . calledOnce ( browserLaunchStub ) ;
114
+
106
115
// First call should show info once
107
- verify ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . once ( ) ;
116
+ // verify(appShell.showInformationMessage(anything(), anything())).once();
117
+ sinon . assert . calledOnce ( showInformationMessageStub ) ;
108
118
109
119
prompter ! . onDidSendMessage ! ( ptvsdOutputEvent ) ;
110
120
// The second call does not go through the same path. So we just give enough time for the
111
121
// operation to complete.
112
122
await sleep ( 1 ) ;
113
123
114
- verify ( browserService . launch ( anyString ( ) ) ) . once ( ) ;
124
+ // verify(browserService.launch(anyString())).once();
115
125
// Second time it should not be called, so overall count is one.
116
- verify ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . once ( ) ;
126
+ // verify(appShell.showInformationMessage(anything(), anything())).once();
117
127
} ) ;
118
128
119
129
test ( "Don't show prompt attaching to debugpy" , async ( ) => {
120
- when ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( undefined ) ) ;
130
+ // when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(undefined));
131
+ showInformationMessageStub . returns ( Promise . resolve ( undefined ) ) ;
121
132
122
133
const session = createSession ( ) ;
123
134
const prompter = await promptFactory . createDebugAdapterTracker ( session ) ;
@@ -127,7 +138,7 @@ suite('Debugging - Outdated Debugger Prompt tests.', () => {
127
138
// Can't use deferred promise here
128
139
await sleep ( 1 ) ;
129
140
130
- verify ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . never ( ) ;
141
+ // verify(appShell.showInformationMessage(anything(), anything())).never();
131
142
} ) ;
132
143
133
144
const someRequest : DebugProtocol . RunInTerminalRequest = {
@@ -155,7 +166,8 @@ suite('Debugging - Outdated Debugger Prompt tests.', () => {
155
166
156
167
[ someRequest , someEvent , someOutputEvent ] . forEach ( ( message ) => {
157
168
test ( `Don't show prompt when non-telemetry events are seen: ${ JSON . stringify ( message ) } ` , async ( ) => {
158
- when ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( undefined ) ) ;
169
+ // when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(undefined));
170
+ showInformationMessageStub . returns ( Promise . resolve ( undefined ) ) ;
159
171
160
172
const session = createSession ( ) ;
161
173
const prompter = await promptFactory . createDebugAdapterTracker ( session ) ;
@@ -165,7 +177,7 @@ suite('Debugging - Outdated Debugger Prompt tests.', () => {
165
177
// Can't use deferred promise here
166
178
await sleep ( 1 ) ;
167
179
168
- verify ( appShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . never ( ) ;
180
+ // verify(appShell.showInformationMessage(anything(), anything())).never();
169
181
} ) ;
170
182
} ) ;
171
183
} ) ;
0 commit comments