File: signal-handler.js

package info (click to toggle)
node-yarnpkg 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 92,980 kB
  • sloc: sh: 323; makefile: 19
file content (28 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* @flow */

import handleSignals from '../../src/util/signal-handler.js';

(process: any).on = jest.fn();
(process: any).exit = jest.fn();

beforeEach(() => {
  process.on.mockClear();
  process.exit.mockClear();
});

afterAll(() => {
  process.on.mockRestore();
  process.exit.mockRestore();
});

it('should attach a handler for SIGTERM event', () => {
  handleSignals();
  expect(process.on.mock.calls[0][0]).toBe('SIGTERM');
});

it('attached SIGTERM handler should exit with status code 1 when invoked', () => {
  handleSignals();
  const sigtermHandler = process.on.mock.calls[0][1];
  sigtermHandler();
  expect(process.exit.mock.calls).toEqual([[1]]);
});