Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process signals #11

Open
mkg0 opened this issue Aug 26, 2020 · 4 comments
Open

process signals #11

mkg0 opened this issue Aug 26, 2020 · 4 comments

Comments

@mkg0
Copy link

mkg0 commented Aug 26, 2020

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.

@EpicEric
Copy link
Owner

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.

@mkg0
Copy link
Author

mkg0 commented Sep 1, 2020

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

@CMCDragonkai
Copy link

So there's no mockProcessOn right now right? That's just an example.

@mkg0
Copy link
Author

mkg0 commented Dec 2, 2021

yes @CMCDragonkai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants