fix: Plugin error when sending on disconnected IPC channel (#21011)

* fix: Plugin error when sending on disconnected IPC channel

* Add unit test for new no send behaviour

Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
This commit is contained in:
Tom Udding
2022-04-13 18:51:27 +02:00
committed by GitHub
parent 476f2ad12b
commit 57dbc170e6
2 changed files with 9 additions and 1 deletions

View File

@@ -25,7 +25,7 @@ module.exports = {
return {
send (event, ...args) {
if (aProcess.killed) {
if (aProcess.killed || !aProcess.connected) {
return
}

View File

@@ -10,6 +10,7 @@ describe('lib/plugins/util', () => {
this.theProcess = {
send: sinon.spy(),
on: sinon.stub(),
connected: true,
}
this.ipc = util.wrapIpc(this.theProcess)
@@ -31,6 +32,13 @@ describe('lib/plugins/util', () => {
expect(this.theProcess.send).not.to.be.called
})
it('#send does not send if process has been disconnected', function () {
this.theProcess.connected = false
this.ipc.send('event-name')
expect(this.theProcess.send).not.to.be.called
})
it('#on listens for process messages that match event', function () {
const handler = sinon.spy()