process signals
Thanks for creating this module!
It would be awesome to have a mock for process.on with signal simulation.
Sadly I don't have enough time right now but here is the issue.
Hi!
Could you give an example of your request? I'm not entirely sure if you intend to mock the event listener, event emission, or something else.
Alright! 🙂 Then here is my scenario. Below code subscribe to kill signals
process.on('SIGTERM', async () => {
// gracefulShutdown
})
process.on('SIGINT', async () => {
// gracefulShutdown
})
And you can trigger a signal with kill
process.kill(process.pid, 'SIGINT');
The problem is program determinate when you test the signal even tho you mock the process exit. Would be nice to mock process.on and process.kill and simulate these signals pleasantly.
Here is a simple test example.
const mockProcess = require('jest-mock-process');
const mockedProcessOn = mockProcess.mockProcessOn();
registerSignalHandlers(app) // function to test
mockedProcessOn.sendSignal(process.pid, 'SIGINT')
expect(gracefulShutdown).toHaveBeenCalled();
mockedProcessOn.restoreMock()
// for another scenario
expect(mockedProcessOn).toHaveBeenCalledWith('Kill them all!');
https://nodejs.org/api/process.html#process_process_kill_pid_signal
So there's no mockProcessOn right now right? That's just an example.
yes @CMCDragonkai