Skip to content

Commit df41996

Browse files
committed
debug: unit tests
1 parent 19c07c0 commit df41996

5 files changed

Lines changed: 109 additions & 13 deletions

File tree

src/vs/workbench/contrib/debug/browser/baseDebugView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface IVariableTemplateData {
4242
}
4343

4444
export function renderViewTree(container: HTMLElement): HTMLElement {
45-
const treeContainer = document.createElement('div');
45+
const treeContainer = $('.');
4646
dom.addClass(treeContainer, 'debug-view-content');
4747
container.appendChild(treeContainer);
4848
return treeContainer;

src/vs/workbench/contrib/debug/common/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export interface IBreakpointsChangeEvent {
441441
added?: Array<IBreakpoint | IFunctionBreakpoint | IDataBreakpoint>;
442442
removed?: Array<IBreakpoint | IFunctionBreakpoint | IDataBreakpoint>;
443443
changed?: Array<IBreakpoint | IFunctionBreakpoint | IDataBreakpoint>;
444-
sessionOnly?: boolean;
444+
sessionOnly: boolean;
445445
}
446446

447447
// Debug configuration interfaces

src/vs/workbench/contrib/debug/common/debugModel.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,15 +1010,15 @@ export class DebugModel implements IDebugModel {
10101010
this.sortAndDeDup();
10111011

10121012
if (fireEvent) {
1013-
this._onDidChangeBreakpoints.fire({ added: newBreakpoints });
1013+
this._onDidChangeBreakpoints.fire({ added: newBreakpoints, sessionOnly: false });
10141014
}
10151015

10161016
return newBreakpoints;
10171017
}
10181018

10191019
removeBreakpoints(toRemove: IBreakpoint[]): void {
10201020
this.breakpoints = this.breakpoints.filter(bp => !toRemove.some(toRemove => toRemove.getId() === bp.getId()));
1021-
this._onDidChangeBreakpoints.fire({ removed: toRemove });
1021+
this._onDidChangeBreakpoints.fire({ removed: toRemove, sessionOnly: false });
10221022
}
10231023

10241024
updateBreakpoints(data: Map<string, IBreakpointUpdateData>): void {
@@ -1031,7 +1031,7 @@ export class DebugModel implements IDebugModel {
10311031
}
10321032
});
10331033
this.sortAndDeDup();
1034-
this._onDidChangeBreakpoints.fire({ changed: updated });
1034+
this._onDidChangeBreakpoints.fire({ changed: updated, sessionOnly: false });
10351035
}
10361036

10371037
setBreakpointSessionData(sessionId: string, capabilites: DebugProtocol.Capabilities, data: Map<string, DebugProtocol.Breakpoint> | undefined): void {
@@ -1100,7 +1100,7 @@ export class DebugModel implements IDebugModel {
11001100
this.breakpointsActivated = true;
11011101
}
11021102

1103-
this._onDidChangeBreakpoints.fire({ changed: changed });
1103+
this._onDidChangeBreakpoints.fire({ changed: changed, sessionOnly: false });
11041104
}
11051105
}
11061106

@@ -1129,13 +1129,13 @@ export class DebugModel implements IDebugModel {
11291129
this.breakpointsActivated = true;
11301130
}
11311131

1132-
this._onDidChangeBreakpoints.fire({ changed: changed });
1132+
this._onDidChangeBreakpoints.fire({ changed: changed, sessionOnly: false });
11331133
}
11341134

11351135
addFunctionBreakpoint(functionName: string, id?: string): IFunctionBreakpoint {
11361136
const newFunctionBreakpoint = new FunctionBreakpoint(functionName, true, undefined, undefined, undefined, id);
11371137
this.functionBreakpoints.push(newFunctionBreakpoint);
1138-
this._onDidChangeBreakpoints.fire({ added: [newFunctionBreakpoint] });
1138+
this._onDidChangeBreakpoints.fire({ added: [newFunctionBreakpoint], sessionOnly: false });
11391139

11401140
return newFunctionBreakpoint;
11411141
}
@@ -1144,7 +1144,7 @@ export class DebugModel implements IDebugModel {
11441144
const functionBreakpoint = this.functionBreakpoints.filter(fbp => fbp.getId() === id).pop();
11451145
if (functionBreakpoint) {
11461146
functionBreakpoint.name = name;
1147-
this._onDidChangeBreakpoints.fire({ changed: [functionBreakpoint] });
1147+
this._onDidChangeBreakpoints.fire({ changed: [functionBreakpoint], sessionOnly: false });
11481148
}
11491149
}
11501150

@@ -1157,13 +1157,13 @@ export class DebugModel implements IDebugModel {
11571157
removed = this.functionBreakpoints;
11581158
this.functionBreakpoints = [];
11591159
}
1160-
this._onDidChangeBreakpoints.fire({ removed });
1160+
this._onDidChangeBreakpoints.fire({ removed, sessionOnly: false });
11611161
}
11621162

11631163
addDataBreakpoint(label: string, dataId: string, canPersist: boolean, accessTypes: DebugProtocol.DataBreakpointAccessType[] | undefined): void {
11641164
const newDataBreakpoint = new DataBreakpoint(label, dataId, canPersist, true, undefined, undefined, undefined, accessTypes);
11651165
this.dataBreakopints.push(newDataBreakpoint);
1166-
this._onDidChangeBreakpoints.fire({ added: [newDataBreakpoint] });
1166+
this._onDidChangeBreakpoints.fire({ added: [newDataBreakpoint], sessionOnly: false });
11671167
}
11681168

11691169
removeDataBreakpoints(id?: string): void {
@@ -1175,7 +1175,7 @@ export class DebugModel implements IDebugModel {
11751175
removed = this.dataBreakopints;
11761176
this.dataBreakopints = [];
11771177
}
1178-
this._onDidChangeBreakpoints.fire({ removed });
1178+
this._onDidChangeBreakpoints.fire({ removed, sessionOnly: false });
11791179
}
11801180

11811181
getWatchExpressions(): Expression[] {

src/vs/workbench/contrib/debug/test/browser/baseDebugView.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7-
import { replaceWhitespace, renderExpressionValue, renderVariable } from 'vs/workbench/contrib/debug/browser/baseDebugView';
7+
import { replaceWhitespace, renderExpressionValue, renderVariable, renderViewTree } from 'vs/workbench/contrib/debug/browser/baseDebugView';
88
import * as dom from 'vs/base/browser/dom';
99
import { Expression, Variable, Scope, StackFrame, Thread } from 'vs/workbench/contrib/debug/common/debugModel';
1010
import { MockSession } from 'vs/workbench/contrib/debug/test/common/mockDebug';
@@ -32,6 +32,16 @@ suite('Debug - Base Debug View', () => {
3232
assert.equal(replaceWhitespace('hey \r\t\n\t\t\n there'), 'hey \\r\\t\\n\\t\\t\\n there');
3333
});
3434

35+
test('render view tree', () => {
36+
const container = $('.container');
37+
const treeContainer = renderViewTree(container);
38+
39+
assert.equal(treeContainer.className, 'debug-view-content');
40+
assert.equal(container.childElementCount, 1);
41+
assert.equal(container.firstChild, treeContainer);
42+
assert.equal(treeContainer instanceof HTMLDivElement, true);
43+
});
44+
3545
test('render expression value', () => {
3646
let container = $('.container');
3747
renderExpressionValue('render \n me', container, { showHover: true, preserveWhitespace: true });

src/vs/workbench/contrib/debug/test/browser/debugModel.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { IBreakpointUpdateData, IDebugSessionOptions } from 'vs/workbench/contri
1616
import { NullOpenerService } from 'vs/platform/opener/common/opener';
1717
import { RawDebugSession } from 'vs/workbench/contrib/debug/browser/rawDebugSession';
1818
import { timeout } from 'vs/base/common/async';
19+
import { dispose } from 'vs/base/common/lifecycle';
1920

2021
function createMockSession(model: DebugModel, name = 'mockSession', options?: IDebugSessionOptions): DebugSession {
2122
return new DebugSession({ resolved: { name, type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, options, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!);
@@ -34,16 +35,40 @@ suite('Debug - Model', () => {
3435

3536
test('breakpoints simple', () => {
3637
const modelUri = uri.file('/myfolder/myfile.js');
38+
let eventCount = 0;
39+
40+
let toDispose = model.onDidChangeBreakpoints(e => {
41+
eventCount++;
42+
assert.equal(e?.added?.length, 2);
43+
assert.equal(e?.sessionOnly, false);
44+
assert.equal(e?.removed, undefined);
45+
assert.equal(e?.changed, undefined);
46+
47+
dispose(toDispose);
48+
});
3749
model.addBreakpoints(modelUri, [{ lineNumber: 5, enabled: true }, { lineNumber: 10, enabled: false }]);
50+
assert.equal(eventCount, 1);
3851
assert.equal(model.areBreakpointsActivated(), true);
3952
assert.equal(model.getBreakpoints().length, 2);
4053

54+
toDispose = model.onDidChangeBreakpoints(e => {
55+
eventCount++;
56+
assert.equal(e?.added, undefined);
57+
assert.equal(e?.sessionOnly, false);
58+
assert.equal(e?.removed?.length, 2);
59+
assert.equal(e?.changed, undefined);
60+
61+
dispose(toDispose);
62+
});
63+
4164
model.removeBreakpoints(model.getBreakpoints());
65+
assert.equal(eventCount, 2);
4266
assert.equal(model.getBreakpoints().length, 0);
4367
});
4468

4569
test('breakpoints toggling', () => {
4670
const modelUri = uri.file('/myfolder/myfile.js');
71+
4772
model.addBreakpoints(modelUri, [{ lineNumber: 5, enabled: true }, { lineNumber: 10, enabled: false }]);
4873
model.addBreakpoints(modelUri, [{ lineNumber: 12, enabled: true, condition: 'fake condition' }]);
4974
assert.equal(model.getBreakpoints().length, 3);
@@ -66,16 +91,33 @@ suite('Debug - Model', () => {
6691
model.addBreakpoints(modelUri2, [{ lineNumber: 1, enabled: true }, { lineNumber: 2, enabled: true }, { lineNumber: 3, enabled: false }]);
6792

6893
assert.equal(model.getBreakpoints().length, 5);
94+
assert.equal(model.getBreakpoints({ uri: modelUri1 }).length, 2);
95+
assert.equal(model.getBreakpoints({ uri: modelUri2 }).length, 3);
96+
assert.equal(model.getBreakpoints({ lineNumber: 5 }).length, 1);
97+
assert.equal(model.getBreakpoints({ column: 5 }).length, 0);
98+
99+
69100
const bp = model.getBreakpoints()[0];
70101
const update = new Map<string, IBreakpointUpdateData>();
71102
update.set(bp.getId(), { lineNumber: 100 });
103+
let eventFired = false;
104+
model.onDidChangeBreakpoints(e => {
105+
eventFired = true;
106+
assert.equal(e?.added, undefined);
107+
assert.equal(e?.removed, undefined);
108+
assert.equal(e?.changed?.length, 1);
109+
});
72110
model.updateBreakpoints(update);
111+
assert.equal(eventFired, true);
73112
assert.equal(bp.lineNumber, 100);
74113

114+
assert.equal(model.getBreakpoints({ enabledOnly: true }).length, 3);
75115
model.enableOrDisableAllBreakpoints(false);
76116
model.getBreakpoints().forEach(bp => {
77117
assert.equal(bp.enabled, false);
78118
});
119+
assert.equal(model.getBreakpoints({ enabledOnly: true }).length, 0);
120+
79121
model.setEnablement(bp, true);
80122
assert.equal(bp.enabled, true);
81123

@@ -150,6 +192,50 @@ suite('Debug - Model', () => {
150192
assert.equal(breakpoints[0].supported, true);
151193
});
152194

195+
test('exception breakpoints', () => {
196+
let eventCount = 0;
197+
model.onDidChangeBreakpoints(() => eventCount++);
198+
model.setExceptionBreakpoints([{ filter: 'uncaught', label: 'UNCAUGHT', default: true }]);
199+
assert.equal(eventCount, 1);
200+
let exceptionBreakpoints = model.getExceptionBreakpoints();
201+
assert.equal(exceptionBreakpoints.length, 1);
202+
assert.equal(exceptionBreakpoints[0].filter, 'uncaught');
203+
assert.equal(exceptionBreakpoints[0].enabled, true);
204+
205+
model.setExceptionBreakpoints([{ filter: 'uncaught', label: 'UNCAUGHT' }, { filter: 'caught', label: 'CAUGHT' }]);
206+
assert.equal(eventCount, 2);
207+
exceptionBreakpoints = model.getExceptionBreakpoints();
208+
assert.equal(exceptionBreakpoints.length, 2);
209+
assert.equal(exceptionBreakpoints[0].filter, 'uncaught');
210+
assert.equal(exceptionBreakpoints[0].enabled, true);
211+
assert.equal(exceptionBreakpoints[1].filter, 'caught');
212+
assert.equal(exceptionBreakpoints[1].label, 'CAUGHT');
213+
assert.equal(exceptionBreakpoints[1].enabled, false);
214+
});
215+
216+
test('data breakpoints', () => {
217+
let eventCount = 0;
218+
model.onDidChangeBreakpoints(() => eventCount++);
219+
220+
model.addDataBreakpoint('label', 'id', true, ['read']);
221+
model.addDataBreakpoint('second', 'secondId', false, ['readWrite']);
222+
const dataBreakpoints = model.getDataBreakpoints();
223+
assert.equal(dataBreakpoints[0].canPersist, true);
224+
assert.equal(dataBreakpoints[0].dataId, 'id');
225+
assert.equal(dataBreakpoints[1].canPersist, false);
226+
assert.equal(dataBreakpoints[1].description, 'second');
227+
228+
assert.equal(eventCount, 2);
229+
230+
model.removeDataBreakpoints(dataBreakpoints[0].getId());
231+
assert.equal(eventCount, 3);
232+
assert.equal(model.getDataBreakpoints().length, 1);
233+
234+
model.removeDataBreakpoints();
235+
assert.equal(model.getDataBreakpoints().length, 0);
236+
assert.equal(eventCount, 4);
237+
});
238+
153239
// Threads
154240

155241
test('threads simple', () => {

0 commit comments

Comments
 (0)