command.executableSubcommand.signals.test.js
This file
Path
tests/command.executableSubcommand.signals.test.js
46 lines · 1.9 KiB · JavaScript
Last changed by
Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
History of this fileTake it
The walk stopped after 200 commits: lines older than 20cef03 point at it.
Update supported details for 7.x (#1419)John Geebefore adoption20cef03
lines 1–3why, one step back1const childProcess = require('child_process');2const path = require('path');3Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
line 4why, one step back4const pmPath = path.join(__dirname, 'fixtures', 'pm');Update supported details for 7.x (#1419)John Geebefore adoption20cef03
line 5why, one step back5Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
line 6why, one step back6// Disabling some tests on Windows as:Update supported details for 7.x (#1419)John Geebefore adoption20cef03
lines 7–10why, one step back7// "Windows does not support sending signals"8// https://nodejs.org/api/process.html#process_signal_events9const describeOrSkipOnWindows = (process.platform === 'win32') ? describe.skip : describe;10Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
lines 11–14why, one step back11describeOrSkipOnWindows('signals', () => {12 test.each(['SIGINT', 'SIGHUP', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'])('when program sent %s then executableSubcommand sent signal too', (signal, done) => {13 // Spawn program. The listen subcommand waits for a signal and writes the name of the signal to stdout.14 const proc = childProcess.spawn(pmPath, ['listen'], {});Update supported details for 7.x (#1419)John Geebefore adoption20cef03
line 15why, one step back15Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
lines 16–29why, one step back16 let processOutput = '';17 proc.stdout.on('data', (data) => {18 if (processOutput.length === 0) {19 // Send signal to program.20 proc.kill(`${signal}`);21 }22 processOutput += data.toString();23 });24 proc.on('close', (code) => {25 // Check the child subcommand received the signal too.26 expect(processOutput).toBe(`Listening for signal...${signal}`);27 done();28 });29 });Update supported details for 7.x (#1419)John Geebefore adoption20cef03
line 30why, one step back30Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
lines 31–34why, one step back31 test('when executable subcommand sent signal then program exit code is non-zero', () => {32 const { status } = childProcess.spawnSync(pmPath, ['terminate'], {});33 expect(status).toBeGreaterThan(0);34 });Update supported details for 7.x (#1419)John Geebefore adoption20cef03
line 35why, one step back35Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
lines 36–38why, one step back36 test('when command has exitOverride and executable subcommand sent signal then exit code is non-zero', () => {37 const { status } = childProcess.spawnSync(pmPath, ['exit-override', 'terminate'], {});38 expect(status).toBeGreaterThan(0);Update supported details for 7.x (#1419)John Geebefore adoption20cef03
line 39why, one step back39 });Exit with non-zero code when subprocess terminated by signal (#2023)John Geebefore adoption5aaca0d
lines 40–46why, one step back4041 // Not a signal test, but closely related code so adding here.42 test('when command has exitOverride and executable subcommand fails then program exit code is subcommand exit code', () => {43 const { status } = childProcess.spawnSync(pmPath, ['exit-override', 'fail'], {});44 expect(status).toEqual(42);45 });46});