command.executableSubcommand.signals.test.js
This file
Path
tests/command.executableSubcommand.signals.test.js
46 lines · 1.9 KiB · JavaScript
Last changed by
Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
History of this fileTake it
The walk stopped after 200 commits: lines older than c20284d point at it.
Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d
lines 1–3why, one step back1const childProcess = require('child_process');2const path = require('path');3Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 4why, one step back4const pmPath = path.join(__dirname, 'fixtures', 'pm');Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d
line 5why, one step back5Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 6why, one step back6// Disabling some tests on Windows as:Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d
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;10Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
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'], {});Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d
line 15why, one step back15Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
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 });Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d
line 30why, one step back30Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
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 });Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d
line 35why, one step back35Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
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);Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d
line 39why, one step back39 });Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
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});