Skip to content

Commit 83fc814

Browse files
committed
Changing tests in accordance with new data model for live watch, adding custom icons to view container
1 parent cc5d0a4 commit 83fc814

File tree

5 files changed

+160
-25
lines changed

5 files changed

+160
-25
lines changed

images/trace-and-live-dark.svg

Lines changed: 61 additions & 0 deletions
Loading

images/trace-and-live-light.svg

Lines changed: 58 additions & 0 deletions
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
{
5353
"id": "cmsis-debugger",
5454
"title": "CMSIS Debug",
55-
"icon": "$(rocket)"
55+
"icon": {"light": "images/trace-and-live-light.svg", "dark": "images/trace-and-live-dark.svg"}
5656
}
5757
]
5858
},

src/views/live-watch/live-watch.test.ts

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* eslint-disable @typescript-eslint/no-explicit-any */
1818
import * as vscode from 'vscode';
1919
import { debugSessionFactory, extensionContextFactory } from '../../__test__/vscode.factory';
20-
import { LiveWatchTreeDataProvider } from './live-watch';
20+
import { EvaluateNodeResponse, LiveWatchTreeDataProvider } from './live-watch';
2121
import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session';
2222
import { gdbTargetConfiguration } from '../../debug-configuration/debug-configuration.factory';
2323
import { GDBTargetConfiguration } from '../../debug-configuration';
@@ -33,8 +33,8 @@ describe('LiveWatchTreeDataProvider', () => {
3333
let debugConfig: GDBTargetConfiguration;
3434

3535
// Helper: create a dummy node
36-
function makeNode(expression = 'x', value = '1', id = 1) {
37-
return { id, expression, value, parent: undefined };
36+
function makeNode(expression = 'x', value: EvaluateNodeResponse = { result: '1', variablesReference: 0 }, id = 1) {
37+
return { id, expression, value, parent: undefined, children: [] };
3838
}
3939

4040
beforeEach(() => {
@@ -129,24 +129,39 @@ describe('LiveWatchTreeDataProvider', () => {
129129

130130
describe('tree data methods', () => {
131131
it('getChildren returns roots when no element is passed', async () => {
132-
(liveWatchTreeDataProvider as any).roots = [makeNode('node-1', '1', 1), makeNode('node-2', '2', 2)];
132+
(liveWatchTreeDataProvider as any).roots = [makeNode('node-1', { result: '1', variablesReference: 0 }, 1), makeNode('node-2', { result: '2', variablesReference: 0 }, 2)];
133133
const children = await liveWatchTreeDataProvider.getChildren();
134134
expect(children.length).toBe(2);
135135
expect(children[0].expression).toBe('node-1');
136136
expect(children[1].expression).toBe('node-2');
137137
});
138138

139139
it('getChildren returns children of element', async () => {
140-
const childNode = makeNode('childNode', '2', 2);
141-
const parent = { ...makeNode('parentNode', '1', 1), children: [childNode] };
140+
const parent = makeNode('parentNode', { result: '1', variablesReference: 123 }, 1);
142141
(liveWatchTreeDataProvider as any).roots = [parent];
142+
// Mock active session with customRequest returning one variable
143+
(liveWatchTreeDataProvider as any)._activeSession = {
144+
session: {
145+
customRequest: jest.fn().mockResolvedValue({
146+
variables: [
147+
{ name: 'childNode', value: '2', variablesReference: 0 }
148+
]
149+
})
150+
},
151+
evaluateGlobalExpression: jest.fn()
152+
};
143153
const children = await liveWatchTreeDataProvider.getChildren(parent);
154+
expect((liveWatchTreeDataProvider as any)._activeSession.session.customRequest).toHaveBeenCalledWith('variables', { variablesReference: parent.value.variablesReference });
144155
expect(children.length).toBe(1);
145156
expect(children[0].expression).toBe('childNode');
157+
expect(children[0].value.result).toBe('2');
158+
expect(children[0].value.variablesReference).toBe(0);
159+
// Ensure dynamic children not persisted on parent
160+
expect(parent.children.length).toBe(0);
146161
});
147162

148163
it('getTreeItem returns correct TreeItem', () => {
149-
const node = makeNode('expression', 'value', 1);
164+
const node = makeNode('expression', { result: 'value', variablesReference: 1 }, 1);
150165
const item = liveWatchTreeDataProvider.getTreeItem(node);
151166
expect(item.label).toBe('expression = ');
152167
expect(item.description).toBe('value');
@@ -156,28 +171,29 @@ describe('LiveWatchTreeDataProvider', () => {
156171

157172
describe('node management', () => {
158173
it('add creates a new root node', async () => {
159-
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue('1234');
160-
await (liveWatchTreeDataProvider as any).add('expression');
174+
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: '1234', variablesReference: 0 });
175+
// adapt method name addToRoots (changed implementation)
176+
await (liveWatchTreeDataProvider as any).addToRoots('expression');
161177
expect((liveWatchTreeDataProvider as any).roots.length).toBe(1);
162178
expect((liveWatchTreeDataProvider as any).roots[0].expression).toBe('expression');
163-
expect((liveWatchTreeDataProvider as any).roots[0].value).toBe('1234');
179+
expect((liveWatchTreeDataProvider as any).roots[0].value.result).toBe('1234');
164180
});
165181

166182
it('clear removes all nodes', async () => {
167-
(liveWatchTreeDataProvider as any).roots = [makeNode('expression', '1', 1)];
183+
(liveWatchTreeDataProvider as any).roots = [makeNode('expression', { result: '1', variablesReference: 0 })];
168184
await (liveWatchTreeDataProvider as any).clear();
169185
expect((liveWatchTreeDataProvider as any).roots.length).toBe(0);
170186
});
171187

172188
it('delete removes a node by id', async () => {
173-
(liveWatchTreeDataProvider as any).roots = [makeNode('node-1', '1', 1), makeNode('node-2', '2', 2)];
189+
(liveWatchTreeDataProvider as any).roots = [makeNode('node-1', { result: '1', variablesReference: 0 }, 1), makeNode('node-2', { result: '2', variablesReference: 0 }, 2)];
174190
await (liveWatchTreeDataProvider as any).delete({ id: 1 });
175191
expect((liveWatchTreeDataProvider as any).roots.length).toBe(1);
176192
expect((liveWatchTreeDataProvider as any).roots[0].id).toBe(2);
177193
});
178194

179195
it('rename updates node expression', async () => {
180-
const node = makeNode('node-1', '1', 1);
196+
const node = makeNode('node-1', { result: '1', variablesReference: 0 }, 1);
181197
(liveWatchTreeDataProvider as any).roots = [node];
182198
await (liveWatchTreeDataProvider as any).rename(node, 'node-1-renamed');
183199
expect(node.expression).toBe('node-1-renamed');
@@ -186,19 +202,19 @@ describe('LiveWatchTreeDataProvider', () => {
186202

187203
describe('refresh', () => {
188204
it('refresh updates all root node values', async () => {
189-
const node = makeNode('expression', 'old-value', 1);
205+
const node = makeNode('expression', { result: 'old-value', variablesReference: 1 }, 1);
190206
(liveWatchTreeDataProvider as any).roots = [node];
191-
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue('new-value');
207+
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: 'new-value', variablesReference: 0 });
192208
await (liveWatchTreeDataProvider as any).refresh();
193-
expect(node.value).toBe('new-value');
209+
expect(node.value.result).toBe('new-value');
194210
});
195211

196212
it('refresh(node) updates only that node', async () => {
197-
const node = makeNode('expression', 'old-value', 1);
213+
const node = makeNode('expression', { result: 'old-value', variablesReference: 1 }, 1);
198214
(liveWatchTreeDataProvider as any).roots = [node];
199-
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue('new-value');
215+
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: 'new-value', variablesReference: 0 });
200216
await (liveWatchTreeDataProvider as any).refresh(node);
201-
expect(node.value).toBe('new-value');
217+
expect(node.value.result).toBe('new-value');
202218
});
203219
});
204220

@@ -248,7 +264,7 @@ describe('LiveWatchTreeDataProvider', () => {
248264
});
249265

250266
it('deleteAll command clears roots', async () => {
251-
(liveWatchTreeDataProvider as any).roots = [makeNode('nodeA','1',1), makeNode('nodeB','2',2)];
267+
(liveWatchTreeDataProvider as any).roots = [makeNode('nodeA', { result: '1', variablesReference: 0 }, 1), makeNode('nodeB', { result: '2', variablesReference: 0 }, 2)];
252268
const clearSpy = jest.spyOn(liveWatchTreeDataProvider as any, 'clear');
253269
liveWatchTreeDataProvider.activate(tracker);
254270
const handler = getRegisteredHandler('cmsis-debugger.liveWatch.deleteAll');
@@ -258,7 +274,7 @@ describe('LiveWatchTreeDataProvider', () => {
258274
});
259275

260276
it('delete command removes provided node', async () => {
261-
(liveWatchTreeDataProvider as any).roots = [makeNode('nodeA','1',1), makeNode('nodeB','2',2)];
277+
(liveWatchTreeDataProvider as any).roots = [makeNode('nodeA', { result: '1', variablesReference: 0 }, 1), makeNode('nodeB', { result: '2', variablesReference: 0 }, 2)];
262278
const deleteSpy = jest.spyOn(liveWatchTreeDataProvider as any, 'delete');
263279
liveWatchTreeDataProvider.activate(tracker);
264280
const handler = getRegisteredHandler('cmsis-debugger.liveWatch.delete');
@@ -269,7 +285,7 @@ describe('LiveWatchTreeDataProvider', () => {
269285
});
270286

271287
it('modify command renames a node when expression provided', async () => {
272-
const node = makeNode('oldExpression','1',1);
288+
const node = makeNode('oldExpression',{ result: '1', variablesReference: 0 },1);
273289
(liveWatchTreeDataProvider as any).roots = [node];
274290
(vscode.window as any).showInputBox = jest.fn().mockResolvedValue('newExpression');
275291
const renameSpy = jest.spyOn(liveWatchTreeDataProvider as any, 'rename');
@@ -281,7 +297,7 @@ describe('LiveWatchTreeDataProvider', () => {
281297
});
282298

283299
it('modify command does nothing when expression undefined', async () => {
284-
const node = makeNode('oldExpression','1',1);
300+
const node = makeNode('oldExpression', { result: '1', variablesReference: 0 }, 1);
285301
(liveWatchTreeDataProvider as any).roots = [node];
286302
(vscode.window as any).showInputBox = jest.fn().mockResolvedValue(undefined);
287303
const renameSpy = jest.spyOn(liveWatchTreeDataProvider as any, 'rename');

src/views/live-watch/live-watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface LiveWatchNode {
2525
value: EvaluateNodeResponse
2626
}
2727

28-
interface EvaluateNodeResponse {
28+
export interface EvaluateNodeResponse {
2929
result: string;
3030
variablesReference: number;
3131
}

0 commit comments

Comments
 (0)