@@ -94,6 +94,11 @@ vi.mock('../src/inference.js', () => ({
94
94
95
95
vi . mock ( '@actions/core' , ( ) => core )
96
96
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
+
97
102
// The module being tested should be imported dynamically. This ensures that the
98
103
// mocks are used in place of any actual dependencies.
99
104
const { run} = await import ( '../src/main.js' )
@@ -102,6 +107,7 @@ describe('main.ts', () => {
102
107
// Reset all mocks before each test
103
108
beforeEach ( ( ) => {
104
109
vi . clearAllMocks ( )
110
+ mockProcessExit . mockClear ( )
105
111
106
112
// Remove any existing GITHUB_TOKEN
107
113
delete process . env . GITHUB_TOKEN
@@ -129,9 +135,11 @@ describe('main.ts', () => {
129
135
'prompt-file' : '' ,
130
136
} )
131
137
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' )
133
140
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 )
135
143
} )
136
144
137
145
it ( 'uses simple inference when MCP is disabled' , async ( ) => {
@@ -251,8 +259,10 @@ describe('main.ts', () => {
251
259
'prompt-file' : promptFile ,
252
260
} )
253
261
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' )
255
264
256
265
expect ( core . setFailed ) . toHaveBeenCalledWith ( `File for prompt-file was not found: ${ promptFile } ` )
266
+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 )
257
267
} )
258
268
} )
0 commit comments