-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsDebugClient.ts
67 lines (59 loc) · 2.67 KB
/
nsDebugClient.ts
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
import * as assert from 'assert';
import {DebugProtocol} from 'vscode-debugprotocol';
import {DebugClient} from 'vscode-debugadapter-testsupport';
export class NsDebugClient extends DebugClient {
private _timeout: number = 90000;
public getTimeout(): number {
return this._timeout;
}
public setTimeout(timeout: number) {
this._timeout = timeout;
}
// The method adds the following enhancements to its base implementation
// 1. It has no hardcoded value for the timeout
// 2. It removes the event listener after it is no needed anymore
public waitForEvent(eventType: string, timeout?: number): Promise<DebugProtocol.Event> {
timeout = timeout || this._timeout;
return new Promise<DebugProtocol.Event>((resolve, reject) => {
let eventListener: (event: DebugProtocol.Event) => any = (event) => {
resolve(event);
this.removeListener(eventType, eventListener);
};
this.on(eventType, eventListener);
if (timeout) {
setTimeout(() => {
reject(new Error("no event '" + eventType + "' received after " + timeout + " ms"));
}, timeout);
}
});
}
public onNextTime(event: string): Promise<DebugProtocol.Event> {
return this.waitForEvent(event);
}
public onNthTime(n: number, event: string): Promise<DebugProtocol.Event> {
return n == 1 ?
this.onNextTime(event) :
this.onNextTime(event).then(e => this.onNthTime(--n, event));
}
public assertSetBreakpoints(path: string, breakpoints: { line: number, condition?: string }[]): Promise<void> {
return this.setBreakpointsRequest({
lines: breakpoints.map(b => b.line),
breakpoints: breakpoints,
source: { path: path }
})
.then(response => {
response.body.breakpoints.forEach((bp, i, a) => {
assert.equal(bp.verified, true, 'breakpoint verification mismatch: verified');
assert.equal(bp.line, breakpoints[i].line, 'breakpoint verification mismatch: line');
//assert.equal(bp.column, breakpointColumn, 'breakpoint verification mismatch: column');
});
return Promise.resolve();
});
}
public assertNthStoppedLocation(n: number, reason: string, expected: { path?: string; line?: number; column?: number; })
: Promise<DebugProtocol.StackTraceResponse> {
return n == 1 ?
this.assertStoppedLocation(reason, expected) :
this.onNextTime('stopped').then(e => this.assertNthStoppedLocation(--n, reason, expected));
}
}