command.executableSubcommand.signals.test.js
This file
Path
tests/command.executableSubcommand.signals.test.js
58 lines · 2.0 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
The walk stopped after 200 commits: lines older than 40e67bc point at it.
Add example for "global" options (#1708)John Geebefore adoption40e67bc
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 example for "global" options (#1708)John Geebefore adoption40e67bc
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 example for "global" options (#1708)John Geebefore adoption40e67bc
lines 7–8why, one step back7// "Windows does not support sending signals"8// https://nodejs.org/api/process.html#process_signal_eventsReformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 9–10why, one step back9const describeOrSkipOnWindows =10 process.platform === 'win32' ? describe.skip : describe;Add example for "global" options (#1708)John Geebefore adoption40e67bc
line 11why, one step back11Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 12why, one step back12describeOrSkipOnWindows('signals', () => {Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 13–17why, one step back13 test.each(['SIGINT', 'SIGHUP', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'])(14 'when program sent %s then executableSubcommand sent signal too',15 (signal, done) => {16 // Spawn program. The listen subcommand waits for a signal and writes the name of the signal to stdout.17 const proc = childProcess.spawn(pmPath, ['listen'], {});Add example for "global" options (#1708)John Geebefore adoption40e67bc
line 18why, one step back18Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 19–33why, one step back19 let processOutput = '';20 proc.stdout.on('data', (data) => {21 if (processOutput.length === 0) {22 // Send signal to program.23 proc.kill(`${signal}`);24 }25 processOutput += data.toString();26 });27 proc.on('close', (code) => {28 // Check the child subcommand received the signal too.29 expect(processOutput).toBe(`Listening for signal...${signal}`);30 done();31 });32 },33 );Add example for "global" options (#1708)John Geebefore adoption40e67bc
line 34why, one step back34Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 35–38why, one step back35 test('when executable subcommand sent signal then program exit code is non-zero', () => {36 const { status } = childProcess.spawnSync(pmPath, ['terminate'], {});37 expect(status).toBeGreaterThan(0);38 });Add example for "global" options (#1708)John Geebefore adoption40e67bc
line 39why, one step back39Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 40why, one step back40 test('when command has exitOverride and executable subcommand sent signal then exit code is non-zero', () => {Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 41–45why, one step back41 const { status } = childProcess.spawnSync(42 pmPath,43 ['exit-override', 'terminate'],44 {},45 );Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 46why, one step back46 expect(status).toBeGreaterThan(0);Add example for "global" options (#1708)John Geebefore adoption40e67bc
line 47why, one step back47 });Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 48–50why, one step back4849 // Not a signal test, but closely related code so adding here.50 test('when command has exitOverride and executable subcommand fails then program exit code is subcommand exit code', () => {Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 51–55why, one step back51 const { status } = childProcess.spawnSync(52 pmPath,53 ['exit-override', 'fail'],54 {},55 );Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 56–58why, one step back56 expect(status).toEqual(42);57 });58});