forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathoutdatedDebuggerPrompt.unit.test.ts
More file actions
173 lines (144 loc) · 6.68 KB
/
outdatedDebuggerPrompt.unit.test.ts
File metadata and controls
173 lines (144 loc) · 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as assert from 'assert';
import { anyString, anything, instance, mock, verify, when } from 'ts-mockito';
import { DebugSession, WorkspaceFolder } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { ApplicationShell } from '../../../../client/common/application/applicationShell';
import { IApplicationShell } from '../../../../client/common/application/types';
import { ConfigurationService } from '../../../../client/common/configuration/service';
import { BrowserService } from '../../../../client/common/net/browser';
import { IBrowserService, IPythonSettings } from '../../../../client/common/types';
import { createDeferred, sleep } from '../../../../client/common/utils/async';
import { Common } from '../../../../client/common/utils/localize';
import { OutdatedDebuggerPromptFactory } from '../../../../client/debugger/extension/adapter/outdatedDebuggerPrompt';
import { clearTelemetryReporter } from '../../../../client/telemetry';
// tslint:disable-next-line: max-func-body-length
suite('Debugging - Outdated Debugger Prompt tests.', () => {
let promptFactory: OutdatedDebuggerPromptFactory;
let appShell: IApplicationShell;
let browserService: IBrowserService;
const ptvsdOutputEvent: DebugProtocol.OutputEvent = {
seq: 1,
type: 'event',
event: 'output',
body: { category: 'telemetry', output: 'ptvsd', data: { packageVersion: '4.3.2' } }
};
const debugpyOutputEvent: DebugProtocol.OutputEvent = {
seq: 1,
type: 'event',
event: 'output',
body: { category: 'telemetry', output: 'debugpy', data: { packageVersion: '1.0.0' } }
};
setup(() => {
const configurationService = mock(ConfigurationService);
when(configurationService.getSettings(undefined)).thenReturn(({
experiments: { enabled: true }
// tslint:disable-next-line: no-any
} as any) as IPythonSettings);
appShell = mock(ApplicationShell);
browserService = mock(BrowserService);
promptFactory = new OutdatedDebuggerPromptFactory(instance(appShell), instance(browserService));
});
teardown(() => {
clearTelemetryReporter();
});
function createSession(workspaceFolder?: WorkspaceFolder): DebugSession {
return {
configuration: {
name: '',
request: 'launch',
type: 'python'
},
id: 'test1',
name: 'python',
type: 'python',
workspaceFolder,
customRequest: () => Promise.resolve(),
getDebugProtocolBreakpoint: () => Promise.resolve({})
};
}
test('Show prompt when attaching to ptvsd, more info is NOT clicked', async () => {
when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(undefined));
const session = createSession();
const prompter = await promptFactory.createDebugAdapterTracker(session);
if (prompter) {
prompter.onDidSendMessage!(ptvsdOutputEvent);
}
verify(browserService.launch(anyString())).never();
// First call should show info once
verify(appShell.showInformationMessage(anything(), anything())).once();
assert(prompter);
prompter!.onDidSendMessage!(ptvsdOutputEvent);
// Can't use deferred promise here
await sleep(1);
verify(browserService.launch(anyString())).never();
// Second time it should not be called, so overall count is one.
verify(appShell.showInformationMessage(anything(), anything())).once();
});
test('Show prompt when attaching to ptvsd, more info is clicked', async () => {
when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(Common.moreInfo()));
const deferred = createDeferred();
when(browserService.launch(anything())).thenCall(() => deferred.resolve());
const session = createSession();
const prompter = await promptFactory.createDebugAdapterTracker(session);
assert(prompter);
prompter!.onDidSendMessage!(ptvsdOutputEvent);
await deferred.promise;
verify(browserService.launch(anything())).once();
// First call should show info once
verify(appShell.showInformationMessage(anything(), anything())).once();
prompter!.onDidSendMessage!(ptvsdOutputEvent);
// The second call does not go through the same path. So we just give enough time for the
// operation to complete.
await sleep(1);
verify(browserService.launch(anyString())).once();
// Second time it should not be called, so overall count is one.
verify(appShell.showInformationMessage(anything(), anything())).once();
});
test("Don't show prompt attaching to debugpy", async () => {
when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(undefined));
const session = createSession();
const prompter = await promptFactory.createDebugAdapterTracker(session);
assert(prompter);
prompter!.onDidSendMessage!(debugpyOutputEvent);
// Can't use deferred promise here
await sleep(1);
verify(appShell.showInformationMessage(anything(), anything())).never();
});
const someRequest: DebugProtocol.RunInTerminalRequest = {
seq: 1,
type: 'request',
command: 'runInTerminal',
arguments: {
cwd: '',
args: ['']
}
};
const someEvent: DebugProtocol.ContinuedEvent = {
seq: 1,
type: 'event',
event: 'continued',
body: { threadId: 1, allThreadsContinued: true }
};
// Notice that this is stdout, not telemetry event.
const someOutputEvent: DebugProtocol.OutputEvent = {
seq: 1,
type: 'event',
event: 'output',
body: { category: 'stdout', output: 'ptvsd' }
};
[someRequest, someEvent, someOutputEvent].forEach((message) => {
test(`Don't show prompt when non-telemetry events are seen: ${JSON.stringify(message)}`, async () => {
when(appShell.showInformationMessage(anything(), anything())).thenReturn(Promise.resolve(undefined));
const session = createSession();
const prompter = await promptFactory.createDebugAdapterTracker(session);
assert(prompter);
prompter!.onDidSendMessage!(message);
// Can't use deferred promise here
await sleep(1);
verify(appShell.showInformationMessage(anything(), anything())).never();
});
});
});