@@ -29,26 +29,10 @@ import { Resolver } from '../../resolver';
2929import { ScvdEvalContext } from '../../scvd-eval-context' ;
3030import { StatementEngine } from '../../statement-engine/statement-engine' ;
3131import { ScvdGuiTree } from '../../scvd-gui-tree' ;
32- import type { GDBTargetDebugSession , GDBTargetDebugTracker } from '../../../../debug-session' ;
32+ import { GDBTargetDebugSession , GDBTargetDebugTracker } from '../../../../debug-session' ;
3333import { componentViewerLogger } from '../../../../logger' ;
34-
35- jest . mock ( 'vscode' , ( ) => ( {
36- workspace : {
37- fs : {
38- readFile : jest . fn ( ) ,
39- } ,
40- } ,
41- window : {
42- createOutputChannel : jest . fn ( ( ) => ( {
43- appendLine : jest . fn ( ) ,
44- trace : jest . fn ( ) ,
45- debug : jest . fn ( ) ,
46- info : jest . fn ( ) ,
47- warn : jest . fn ( ) ,
48- error : jest . fn ( ) ,
49- } ) ) ,
50- } ,
51- } ) ) ;
34+ import { debugSessionFactory } from '../../../../__test__/vscode.factory' ;
35+ import { gdbTargetConfiguration } from '../../../../debug-configuration/debug-configuration.factory' ;
5236
5337jest . mock ( 'xml2js' , ( ) => ( {
5438 parseStringPromise : jest . fn ( ) ,
@@ -75,8 +59,15 @@ jest.mock('../../scvd-gui-tree', () => ({
7559} ) ) ;
7660
7761describe ( 'ComponentViewerInstance' , ( ) => {
62+ let debugSession : GDBTargetDebugSession ;
63+ let debugTracker : GDBTargetDebugTracker ;
64+ let instance : ComponentViewerInstance ;
65+
7866 beforeEach ( ( ) => {
7967 jest . clearAllMocks ( ) ;
68+ debugSession = new GDBTargetDebugSession ( debugSessionFactory ( gdbTargetConfiguration ( ) , 'test-session-id' ) ) ;
69+ debugTracker = new GDBTargetDebugTracker ( ) ;
70+ instance = new ComponentViewerInstance ( ) ;
8071 } ) ;
8172
8273 it ( 'reads a model, initializes the engine, and updates' , async ( ) => {
@@ -130,9 +121,6 @@ describe('ComponentViewerInstance', () => {
130121 setGuiName,
131122 } ) ) ;
132123
133- const instance = new ComponentViewerInstance ( ) ;
134- const debugSession = { } as unknown as GDBTargetDebugSession ;
135- const debugTracker = { } as unknown as GDBTargetDebugTracker ;
136124 await instance . readModel ( URI . file ( '/tmp/example.scvd' ) , debugSession , debugTracker ) ;
137125
138126 expect ( readXml ) . toHaveBeenCalled ( ) ;
@@ -160,7 +148,6 @@ describe('ComponentViewerInstance', () => {
160148
161149 it ( 'skips update and executeStatements when dependencies are missing' , async ( ) => {
162150 const consoleLog = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
163- const instance = new ComponentViewerInstance ( ) ;
164151
165152 expect ( instance . getGuiTree ( ) ) . toBeUndefined ( ) ;
166153 await instance . update ( ) ;
@@ -177,8 +164,7 @@ describe('ComponentViewerInstance', () => {
177164 readFileMock . mockResolvedValue ( Buffer . from ( '<root/>' ) ) ;
178165 parseStringMock . mockRejectedValue ( new Error ( 'parse failed' ) ) ;
179166
180- const instance = new ComponentViewerInstance ( ) ;
181- await instance . readModel ( URI . file ( '/tmp/invalid.scvd' ) , { } as unknown as GDBTargetDebugSession , { } as unknown as GDBTargetDebugTracker ) ;
167+ await instance . readModel ( URI . file ( '/tmp/invalid.scvd' ) , debugSession , debugTracker ) ;
182168
183169 expect ( consoleError ) . toHaveBeenCalled ( ) ;
184170 consoleError . mockRestore ( ) ;
@@ -199,12 +185,11 @@ describe('ComponentViewerInstance', () => {
199185 calculateTypedefs : jest . fn ( ) ,
200186 } ) ) ;
201187
202- const instance = new ComponentViewerInstance ( ) ;
203188 const modelGetter = jest
204189 . spyOn ( instance as unknown as { model : ScvdComponentViewer | undefined } , 'model' , 'get' )
205190 . mockReturnValue ( undefined ) ;
206191
207- await instance . readModel ( URI . file ( '/tmp/model.scvd' ) , { } as unknown as GDBTargetDebugSession , { } as unknown as GDBTargetDebugTracker ) ;
192+ await instance . readModel ( URI . file ( '/tmp/model.scvd' ) , debugSession , debugTracker ) ;
208193
209194 expect ( consoleError ) . toHaveBeenCalledWith ( 'Failed to create SCVD model' ) ;
210195
@@ -233,8 +218,7 @@ describe('ComponentViewerInstance', () => {
233218 getExecutionContext : jest . fn ( ) . mockReturnValue ( undefined ) ,
234219 } ) ) ;
235220
236- const instance = new ComponentViewerInstance ( ) ;
237- await instance . readModel ( URI . file ( '/tmp/no-exec.scvd' ) , { } as unknown as GDBTargetDebugSession , { } as unknown as GDBTargetDebugTracker ) ;
221+ await instance . readModel ( URI . file ( '/tmp/no-exec.scvd' ) , debugSession , debugTracker ) ;
238222
239223 expect ( consoleError ) . toHaveBeenCalledWith ( 'Failed to get execution context from SCVD EvalContext' ) ;
240224 consoleError . mockRestore ( ) ;
@@ -245,7 +229,6 @@ describe('ComponentViewerInstance', () => {
245229 const consoleError = jest . spyOn ( componentViewerLogger , 'error' ) . mockImplementation ( ( ) => { } ) ;
246230
247231 readFileMock . mockRejectedValue ( new Error ( 'read failed' ) ) ;
248- const instance = new ComponentViewerInstance ( ) ;
249232 const instanceWithReader = instance as unknown as { readFileToBuffer : ( filePath : URI ) => Promise < Buffer > } ;
250233 await expect ( instanceWithReader . readFileToBuffer ( URI . file ( '/tmp/missing' ) ) ) . rejects . toThrow ( 'read failed' ) ;
251234
@@ -254,7 +237,6 @@ describe('ComponentViewerInstance', () => {
254237 } ) ;
255238
256239 it ( 'injects line numbers and reports stats twice' , ( ) => {
257- const instance = new ComponentViewerInstance ( ) ;
258240 const injectLineNumbers = ( instance as unknown as { injectLineNumbers : ( xml : string ) => string } ) . injectLineNumbers ;
259241 const tagged = injectLineNumbers ( '<root>\n<child/>\n</root>' ) ;
260242
@@ -306,13 +288,11 @@ describe('ComponentViewerInstance', () => {
306288 } ) ;
307289
308290 it ( 'cancelExecution is a no-op when the context is not initialised' , ( ) => {
309- const instance = new ComponentViewerInstance ( ) ;
310291 expect ( ( ) => instance . cancelExecution ( 'test' ) ) . not . toThrow ( ) ;
311292 } ) ;
312293
313294 it ( 'cancelExecution delegates to scvdEvalContext cancellation' , ( ) => {
314295 const cancelMock = jest . fn ( ) ;
315- const instance = new ComponentViewerInstance ( ) ;
316296 ( instance as unknown as { _scvdEvalContext : { cancellation : { cancel : jest . Mock } } | undefined } ) . _scvdEvalContext = {
317297 cancellation : { cancel : cancelMock } ,
318298 } ;
0 commit comments