command.executableSubcommand.signals.test.js
This file
Path
tests/command.executableSubcommand.signals.test.js
39 lines · 1.7 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 0504945 point at it.
Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
lines 1–39why, 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// 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;1011// Note: the previous (sinon) test had custom code for SIGUSR1, revisit 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".1617describeOrSkipOnWindows.each([['SIGINT'], ['SIGHUP'], ['SIGTERM'], ['SIGUSR1'], ['SIGUSR2']])(18 'test signal handling in executableSubcommand', (value) => {19 // Slightly tricky test, stick with callback and disable lint warning.20 // eslint-disable-next-line jest/no-done-callback21 test(`when command killed with ${value} then executableSubcommand receives ${value}`, (done) => {22 const pmPath = path.join(__dirname, './fixtures/pm');2324 // The child process writes to stdout.25 const proc = childProcess.spawn(pmPath, ['listen'], {});2627 let processOutput = '';28 proc.stdout.on('data', (data) => {29 if (processOutput.length === 0) {30 proc.kill(`${value}`);31 }32 processOutput += data.toString();33 });34 proc.on('close', (code) => {35 expect(processOutput).toBe(`Listening for signal...${value}`);36 done();37 });38 });39 });