From 0d5c68143d780e631cdaf09081822fc87d7cb3ba Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Wed, 8 Apr 2020 16:08:03 +0300 Subject: [PATCH] fix(server): don't crash on setupExitSignals(undefined) (#2507) --- lib/utils/setupExitSignals.js | 2 +- test/server/utils/setupExitSignals.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils/setupExitSignals.js b/lib/utils/setupExitSignals.js index 105b2b4273..03bb9bdd3c 100644 --- a/lib/utils/setupExitSignals.js +++ b/lib/utils/setupExitSignals.js @@ -5,7 +5,7 @@ const signals = ['SIGINT', 'SIGTERM']; function setupExitSignals(serverData) { signals.forEach((signal) => { process.on(signal, () => { - if (serverData.server) { + if (serverData && serverData.server) { serverData.server.close(() => { // eslint-disable-next-line no-process-exit process.exit(); diff --git a/test/server/utils/setupExitSignals.test.js b/test/server/utils/setupExitSignals.test.js index 0f6f835591..8c40b49429 100644 --- a/test/server/utils/setupExitSignals.test.js +++ b/test/server/utils/setupExitSignals.test.js @@ -25,6 +25,16 @@ describe('setupExitSignals', () => { }); signals.forEach((signal) => { + it(`should exit process (${signal}, serverData never defined`, (done) => { + // eslint-disable-next-line no-undefined + setupExitSignals(undefined); + process.emit(signal); + setTimeout(() => { + expect(exitSpy.mock.calls.length).toEqual(1); + done(); + }, 1000); + }); + it(`should exit process (${signal}, server never defined)`, (done) => { setupExitSignals({ server: null,