command.executableSubcommand.signals.test.js
This file
Path
tests/command.executableSubcommand.signals.test.js
62 lines · 2.2 KiB · JavaScript
Last changed by
Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
History of this fileTake it
The walk stopped after 200 commits: lines older than b2842dc point at it.
update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 1–2why, one step back1const childProcess = require('child_process');2const path = require('path');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 3–4why, one step back3const { test, describe } = require('node:test');4const assert = require('node:assert/strict');update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 5why, one step back5Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 6why, one step back6const pmPath = path.join(__dirname, 'fixtures', 'pm');update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 7why, one step back7Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 8why, one step back8// Disabling some tests on Windows as:update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 9–10why, one step back9// "Windows does not support sending signals"10// https://nodejs.org/api/process.html#process_signal_eventsReformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 11–12why, one step back11const describeOrSkipOnWindows =12 process.platform === 'win32' ? describe.skip : describe;update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 13why, one step back13Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 14why, one step back14describeOrSkipOnWindows('signals', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 15–20why, one step back15 describe('signal forwarding tests', () => {16 const signals = ['SIGINT', 'SIGHUP', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'];17 for (const signal of signals) {18 test(`when program sent ${signal} then executableSubcommand sent signal too`, (t, done) => {19 // Spawn program. The listen subcommand waits for a signal and writes the name of the signal to stdout.20 const proc = childProcess.spawn(pmPath, ['listen'], {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 21why, one step back21Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 22–34why, one step back22 let processOutput = '';23 proc.stdout.on('data', (data) => {24 if (processOutput.length === 0) {25 // Send signal to program.26 proc.kill(`${signal}`);27 }28 processOutput += data.toString();29 });30 proc.on('close', (code) => {31 // Check the child subcommand received the signal too.32 assert.equal(processOutput, `Listening for signal...${signal}`);33 done();34 });Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 35why, one step back35 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 36–37why, one step back36 }37 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 38why, one step back38Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 39–40why, one step back39 test('when executable subcommand sent signal then program exit code is non-zero', () => {40 const { status } = childProcess.spawnSync(pmPath, ['terminate'], {});Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 41why, one step back41 assert.equal(status > 0, true);Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 42why, one step back42 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 43why, one step back43Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 44why, one step back44 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 45–49why, one step back45 const { status } = childProcess.spawnSync(46 pmPath,47 ['exit-override', 'terminate'],48 {},49 );Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 50why, one step back50 assert.equal(status > 0, true);update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 51why, one step back51 });Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 52–54why, one step back5253 // Not a signal test, but closely related code so adding here.54 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 55–59why, one step back55 const { status } = childProcess.spawnSync(56 pmPath,57 ['exit-override', 'fail'],58 {},59 );Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 60why, one step back60 assert.equal(status, 42);Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 61–62why, one step back61 });62});