Skip to content

Commit

Permalink
fix(server): don't crash on setupExitSignals(undefined) (#2507)
Browse files Browse the repository at this point in the history
  • Loading branch information
cben authored Apr 8, 2020
1 parent c436058 commit 0d5c681
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/setupExitSignals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions test/server/utils/setupExitSignals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0d5c681

Please sign in to comment.