Skip to content
Myr

command.executableSubcommand.signals.test.js

This file

Path

tests/command.executableSubcommand.signals.test.js

37 lines · 1.5 KiB · JavaScript

Last changed by

Replace use of var with const and let (#1161)John Geebefore adoption3e5b05e

History of this file

Take it

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 1–3why, one step back
1const childProcess = require('child_process');
2const path = require('path');3

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 4why, one step back
4// Test that a signal sent to the parent process is received by the executable subcommand process (which is listening).

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

line 5why, one step back
5

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

lines 6–10why, one step back
6// Disabling tests on Windows as:
7// "Windows does not support sending signals"8// https://nodejs.org/api/process.html#process_signal_events9const describeOrSkipOnWindows = (process.platform === 'win32') ? describe.skip : describe;10

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 11–16why, one step back
11// Note: the previous (sinon) test had custom code for SIGUSR1, revist if required:
12// As described at https://nodejs.org/api/process.html#process_signal_events13// this signal will start a debugger and thus the process might output an14// additional error message:15// "Failed to open socket on port 5858, waiting 1000 ms before retrying".16

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 17why, one step back
17describeOrSkipOnWindows.each([['SIGINT'], ['SIGHUP'], ['SIGTERM'], ['SIGUSR1'], ['SIGUSR2']])(

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 18–22why, one step back
18 'test signal handling in executableSubcommand', (value) => {
19 test(`when command killed with ${value} then executableSubcommand receieves ${value}`, (done) => {20 const pmPath = path.join(__dirname, './fixtures/pm');2122 // The child process writes to stdout.

Replace use of var with const and let (#1161)John Geebefore adoption3e5b05e

line 23why, one step back
23 const proc = childProcess.spawn(pmPath, ['listen'], {});

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 24–37why, one step back
24
25 let processOutput = '';26 proc.stdout.on('data', (data) => {27 if (processOutput.length === 0) {28 proc.kill(`${value}`);29 }30 processOutput += data.toString();31 });32 proc.on('close', (code) => {33 expect(processOutput).toBe(`Listening for signal...${value}`);34 done();35 });36 });37 });