Skip to content

Commit b0606d6

Browse files
committed
adding a couple more tests and changing location of icons
1 parent 72a72fb commit b0606d6

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
{
5353
"id": "cmsis-debugger",
5454
"title": "Trace and Live View",
55-
"icon": "images/trace-and-live-dark.svg"
55+
"icon": "media/trace-and-live-dark.svg"
5656
}
5757
]
5858
},
@@ -61,7 +61,7 @@
6161
{
6262
"id": "cmsis-debugger.liveWatch",
6363
"name": "Live Watch",
64-
"icon": "images/live-watch-dark.svg"
64+
"icon": "media/trace-and-live-light.svg"
6565
}
6666
]
6767
},

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,22 @@ describe('LiveWatchTreeDataProvider', () => {
210210
await (liveWatchTreeDataProvider as any).refresh(node);
211211
expect(node.value.result).toBe('new-value');
212212
});
213+
214+
it('refresh without argument evaluates each root and fires tree change once', async () => {
215+
const nodeA = makeNode('node-A', { result: 'value-A', variablesReference: 0 }, 1);
216+
const nodeB = makeNode('node-B', { result: 'value-B', variablesReference: 0 }, 2);
217+
(liveWatchTreeDataProvider as any).roots = [nodeA, nodeB];
218+
const evalMock = jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate')
219+
.mockImplementation(async (expr: unknown) => ({ result: String(expr) + '-updated', variablesReference: 0 }));
220+
const fireSpy = jest.spyOn((liveWatchTreeDataProvider as any)._onDidChangeTreeData, 'fire');
221+
await (liveWatchTreeDataProvider as any).refresh();
222+
expect(evalMock).toHaveBeenCalledTimes(2);
223+
expect(nodeA.value.result).toBe('node-A-updated');
224+
expect(nodeB.value.result).toBe('node-B-updated');
225+
expect(fireSpy).toHaveBeenCalledTimes(1);
226+
// fire called with undefined (no specific node) per implementation
227+
expect(fireSpy.mock.calls[0][0]).toBeUndefined();
228+
});
213229
});
214230

215231
describe('command registration', () => {
@@ -309,5 +325,35 @@ describe('LiveWatchTreeDataProvider', () => {
309325
expect(refreshSpy).toHaveBeenCalled();
310326
});
311327
});
328+
329+
describe('evaluate', () => {
330+
it('returns No active session when none set', async () => {
331+
const result = await (liveWatchTreeDataProvider as any).evaluate('myExpression');
332+
expect(result.result).toBe('No active session');
333+
expect(result.variablesReference).toBe(0);
334+
});
335+
336+
it('maps string result into LiveWatchValue', async () => {
337+
// mock active session with evaluateGlobalExpression returning a string
338+
(liveWatchTreeDataProvider as any)._activeSession = {
339+
evaluateGlobalExpression: jest.fn().mockResolvedValue('string-value'),
340+
session: {}
341+
};
342+
const evalResult = await (liveWatchTreeDataProvider as any).evaluate('myExpression');
343+
expect(evalResult.result).toBe('string-value');
344+
expect(evalResult.variablesReference).toBe(0);
345+
});
346+
347+
it('maps object result into LiveWatchValue', async () => {
348+
const responseObj = { result: 'value', variablesReference: 1234 };
349+
(liveWatchTreeDataProvider as any)._activeSession = {
350+
evaluateGlobalExpression: jest.fn().mockResolvedValue(responseObj),
351+
session: {}
352+
};
353+
const evalResult = await (liveWatchTreeDataProvider as any).evaluate('myExpression');
354+
expect(evalResult.result).toBe('value');
355+
expect(evalResult.variablesReference).toBe(1234);
356+
});
357+
});
312358
});
313359
/* eslint-enable @typescript-eslint/no-explicit-any */

0 commit comments

Comments
 (0)