-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Override "process.send" with a mock #5904
Conversation
When creating a mock object for `process`, `process.send` is just referenced from the parent context, which means that a test has access to the real IPC channel established by `jest-worker`, thus breaking the sandbox. As per the Node definition, `process.send` is not defined if the Node process hasn't started off a `fork` call; but this shouldn't be an issue because `send` has always been exposed and no one complained so far 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Maybe test this somehow?
- It's a company holiday today, don't work too much.
@@ -90,6 +90,7 @@ export default function() { | |||
} | |||
|
|||
newProcess.env = createProcessEnv(); | |||
newProcess.send = () => {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other functions on it while we're here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've thought about it and I don't think so. Maybe newProcess.exit
, but I thougth it was better to let it exit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be cool to log a "process.exit()
called from test" or something, potentially with a stack. Rarely on purpose, is it?
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
When creating a mock object for
process
,process.send
is just referenced from the parent context, which means that a test has access to the real IPC channel established byjest-worker
, thus breaking the sandbox.As per the Node definition,
process.send
is not defined if the Node process hasn't started off afork
call; but this shouldn't be an issue, becausesend
has always been exposed and no one complained so far 🙃This should also fix #5891.