Skip to content

Commit 3e6b6fa

Browse files
committed
test(coverage): cmd-cargo both-null exit/signal branch
1 parent 6dc97a2 commit 3e6b6fa

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

packages/cli/test/unit/commands/cargo/cmd-cargo.test.mts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,56 @@ describe('cmd-cargo', () => {
182182
})
183183

184184
describe('exit handling', () => {
185+
it('skips exit/kill when both code and signal are null', async () => {
186+
const mockChildProcess = new EventEmitter()
187+
const mockSpawnPromise = Promise.resolve({
188+
code: null,
189+
signal: null,
190+
stderr: Buffer.from(''),
191+
stdout: Buffer.from(''),
192+
})
193+
;(mockSpawnPromise as any).process = mockChildProcess
194+
195+
mockSpawnSfwDlx.mockResolvedValue({
196+
spawnPromise: mockSpawnPromise,
197+
})
198+
199+
mockFilterFlags.mockReturnValue(['build'])
200+
201+
const mockExit = vi
202+
.spyOn(process, 'exit')
203+
.mockImplementation((() => {}) as any)
204+
mockExit.mockClear()
205+
const mockKill = vi
206+
.spyOn(process, 'kill')
207+
.mockImplementation((() => {}) as any)
208+
mockKill.mockClear()
209+
210+
cmdCargo.run(['build'], importMeta, context)
211+
212+
// Wait for handler registration.
213+
await new Promise(resolve => {
214+
setImmediate(resolve)
215+
})
216+
const exitCallsBefore = mockExit.mock.calls.length
217+
const killCallsBefore = mockKill.mock.calls.length
218+
219+
// Emit exit with both code and signal as null.
220+
mockChildProcess.emit('exit', null, null)
221+
222+
// Wait for event handler.
223+
await new Promise(resolve => {
224+
setImmediate(resolve)
225+
})
226+
227+
// Neither exit nor kill call count should increase.
228+
expect(mockExit.mock.calls.length).toBe(exitCallsBefore)
229+
expect(mockKill.mock.calls.length).toBe(killCallsBefore)
230+
231+
mockExit.mockRestore()
232+
mockKill.mockRestore()
233+
})
234+
185235
it('should set default exit code to 1 before child process exits', async () => {
186236
const mockChildProcess = new EventEmitter()
187237
const mockSpawnPromise = Promise.resolve({

0 commit comments

Comments
 (0)