command.executableSubcommand.signals.test.js
This file
Path
tests/command.executableSubcommand.signals.test.js
32 lines · 1.3 KiB · JavaScript
Last changed by
Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
History of this fileTake it
Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 1–32why, one step back1const childProcess = require('child_process');2const path = require('path');34// Test that a signal sent to the parent process is received by the executable subcommand process (which is listening)56// Note: the previous (sinon) test had custom code for SIGUSR1, revist if required:7// As described at https://nodejs.org/api/process.html#process_signal_events8// this signal will start a debugger and thus the process might output an9// additional error message:10// "Failed to open socket on port 5858, waiting 1000 ms before retrying".1112describe.each([['SIGINT'], ['SIGHUP'], ['SIGTERM'], ['SIGUSR1'], ['SIGUSR2']])(13 'test signal handling in executableSubcommand', (value) => {14 test(`when command killed with ${value} then executableSubcommand receieves ${value}`, (done) => {15 const pmPath = path.join(__dirname, './fixtures/pm');1617 // The child process writes to stdout.18 var proc = childProcess.spawn(pmPath, ['listen'], {});1920 let processOutput = '';21 proc.stdout.on('data', (data) => {22 if (processOutput.length === 0) {23 proc.kill(`${value}`);24 }25 processOutput += data.toString();26 });27 proc.on('close', (code) => {28 expect(processOutput).toBe(`Listening for signal...${value}`);29 done();30 });31 });32 });