@@ -94,6 +94,11 @@ vi.mock('../src/inference.js', () => ({
9494
9595vi . mock ( '@actions/core' , ( ) => core )
9696
97+ // Mock process.exit to prevent it from actually exiting during tests
98+ const mockProcessExit = vi . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => {
99+ throw new Error ( 'process.exit called' )
100+ } )
101+
97102// The module being tested should be imported dynamically. This ensures that the
98103// mocks are used in place of any actual dependencies.
99104const { run} = await import ( '../src/main.js' )
@@ -102,6 +107,7 @@ describe('main.ts', () => {
102107 // Reset all mocks before each test
103108 beforeEach ( ( ) => {
104109 vi . clearAllMocks ( )
110+ mockProcessExit . mockClear ( )
105111
106112 // Remove any existing GITHUB_TOKEN
107113 delete process . env . GITHUB_TOKEN
@@ -129,9 +135,11 @@ describe('main.ts', () => {
129135 'prompt-file' : '' ,
130136 } )
131137
132- await run ( )
138+ // Expect the run function to throw due to process.exit being mocked
139+ await expect ( run ( ) ) . rejects . toThrow ( 'process.exit called' )
133140
134- expect ( core . setFailed ) . toHaveBeenNthCalledWith ( 1 , 'Neither prompt-file nor prompt was set' )
141+ expect ( core . setFailed ) . toHaveBeenCalledWith ( 'Neither prompt-file nor prompt was set' )
142+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 )
135143 } )
136144
137145 it ( 'uses simple inference when MCP is disabled' , async ( ) => {
@@ -251,8 +259,10 @@ describe('main.ts', () => {
251259 'prompt-file' : promptFile ,
252260 } )
253261
254- await run ( )
262+ // Expect the run function to throw due to process.exit being mocked
263+ await expect ( run ( ) ) . rejects . toThrow ( 'process.exit called' )
255264
256265 expect ( core . setFailed ) . toHaveBeenCalledWith ( `File for prompt-file was not found: ${ promptFile } ` )
266+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 )
257267 } )
258268} )
0 commit comments