kill-signal.js
This file
Path
test/terminate/kill-signal.js
142 lines · 5.2 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import {once} from 'node:events';Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 3why, one step back3import {constants} from 'node:os';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 4why, one step back4import {setImmediate} from 'node:timers/promises';TweaksSindre Sorhusbefore adoption698a1b8
lines 5–6why, one step back5import test from 'node:test';6import {assertThrows, assertRejects} from '../helpers/assert.js';Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 7why, one step back7import {execa, execaSync} from '../../index.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 8–11why, one step back8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';910setFixtureDirectory();11TweaksSindre Sorhusbefore adoption698a1b8
lines 12–15why, one step back12const testKillSignal = async killSignal => {13 const {isTerminated, signal} = await assertRejects(execa('forever.js', {killSignal, timeout: 1}));14 assert.equal(isTerminated, true);15 assert.equal(signal, 'SIGINT');Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 16–17why, one step back16};17TweaksSindre Sorhusbefore adoption698a1b8
lines 18–19why, one step back18test('Can use killSignal: "SIGINT"', () => testKillSignal('SIGINT'));19test('Can use killSignal: 2', () => testKillSignal(constants.signals.SIGINT));Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 20why, one step back20TweaksSindre Sorhusbefore adoption698a1b8
lines 21–22why, one step back21const testKillSignalSync = killSignal => {22 const {isTerminated, signal} = assertThrows(() => {Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 23–24why, one step back23 execaSync('forever.js', {killSignal, timeout: 1});24 });TweaksSindre Sorhusbefore adoption698a1b8
lines 25–26why, one step back25 assert.equal(isTerminated, true);26 assert.equal(signal, 'SIGINT');Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 27–28why, one step back27};28TweaksSindre Sorhusbefore adoption698a1b8
lines 29–30why, one step back29test('Can use killSignal: "SIGINT", sync', () => testKillSignalSync('SIGINT'));30test('Can use killSignal: 2, sync', () => testKillSignalSync(constants.signals.SIGINT));Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 31why, one step back31TweaksSindre Sorhusbefore adoption698a1b8
line 32why, one step back32test('Can call .kill("SIGTERM")', async () => {Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 33–34why, one step back33 const subprocess = execa('forever.js');34 subprocess.kill('SIGTERM');TweaksSindre Sorhusbefore adoption698a1b8
lines 35–37why, one step back35 const {isTerminated, signal} = await assertRejects(subprocess);36 assert.equal(isTerminated, true);37 assert.equal(signal, 'SIGTERM');Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 38–39why, one step back38});39TweaksSindre Sorhusbefore adoption698a1b8
line 40why, one step back40test('Can call .kill(15)', async () => {Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 41–42why, one step back41 const subprocess = execa('forever.js');42 subprocess.kill(constants.signals.SIGTERM);TweaksSindre Sorhusbefore adoption698a1b8
lines 43–45why, one step back43 const {isTerminated, signal} = await assertRejects(subprocess);44 assert.equal(isTerminated, true);45 assert.equal(signal, 'SIGTERM');Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 46–47why, one step back46});47TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48test('Can call .kill(0)', async () => {Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 49why, one step back49 const subprocess = execa('forever.js');TweaksSindre Sorhusbefore adoption698a1b8
line 50why, one step back50 assert.ok(subprocess.kill(0));Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 51why, one step back51 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
lines 52–53why, one step back52 await assertRejects(subprocess);53 assert.ok(!subprocess.kill(0));Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
lines 54–55why, one step back54});55TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56test('Can call `.kill()` multiple times', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 57–60why, one step back57 const subprocess = execa('forever.js');58 subprocess.kill();59 subprocess.kill();60TweaksSindre Sorhusbefore adoption698a1b8
lines 61–65why, one step back61 const {exitCode, isTerminated, signal, code} = await assertRejects(subprocess);62 assert.equal(exitCode, undefined);63 assert.equal(isTerminated, true);64 assert.equal(signal, 'SIGTERM');65 assert.equal(code, undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 66–67why, one step back66});67TweaksSindre Sorhusbefore adoption698a1b8
line 68why, one step back68test('execa() returns a promise with kill()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 69why, one step back69 const subprocess = execa('noop.js', ['foo']);TweaksSindre Sorhusbefore adoption698a1b8
line 70why, one step back70 assert.equal(typeof subprocess.kill, 'function');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 71–73why, one step back71 await subprocess;72});73TweaksSindre Sorhusbefore adoption698a1b8
line 74why, one step back74const testInvalidKillArgument = async (killArgument, secondKillArgument) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 75why, one step back75 const subprocess = execa('empty.js');TweaksSindre Sorhusbefore adoption698a1b8
line 76why, one step back76 const message = secondKillArgument === undefined || secondKillArgument instanceof Error100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 77–78why, one step back77 ? /error instance or a signal name/78 : /second argument is optional/;TweaksSindre Sorhusbefore adoption698a1b8
line 79why, one step back79 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 80–84why, one step back80 subprocess.kill(killArgument, secondKillArgument);81 }, {message});82 await subprocess;83};84TweaksSindre Sorhusbefore adoption698a1b8
lines 85–89why, one step back85test('Cannot call .kill(errorObject)', () => testInvalidKillArgument({name: '', message: '', stack: ''}));86test('Cannot call .kill(errorArray)', () => testInvalidKillArgument([new Error('test')]));87test('Cannot call .kill(undefined, true)', () => testInvalidKillArgument(undefined, true));88test('Cannot call .kill("SIGTERM", true)', () => testInvalidKillArgument('SIGTERM', true));89test('Cannot call .kill(true, error)', () => testInvalidKillArgument(true, new Error('test')));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 90why, one step back90TweaksSindre Sorhusbefore adoption698a1b8
line 91why, one step back91test('subprocess errors are handled before spawn', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 92–93why, one step back92 const subprocess = execa('forever.js');93 const cause = new Error('test');Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 94why, one step back94 subprocess.nodeChildProcess.emit('error', cause);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 95why, one step back95 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
lines 96–100why, one step back96 const error = await assertRejects(subprocess);97 assert.equal(error.cause, cause);98 assert.equal(error.exitCode, undefined);99 assert.equal(error.signal, undefined);100 assert.equal(error.isTerminated, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 101–102why, one step back101});102TweaksSindre Sorhusbefore adoption698a1b8
line 103why, one step back103test('subprocess errors are handled after spawn', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 104why, one step back104 const subprocess = execa('forever.js');Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 105why, one step back105 await once(subprocess.nodeChildProcess, 'spawn');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 106why, one step back106 const cause = new Error('test');Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 107why, one step back107 subprocess.nodeChildProcess.emit('error', cause);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 108why, one step back108 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
lines 109–113why, one step back109 const error = await assertRejects(subprocess);110 assert.equal(error.cause, cause);111 assert.equal(error.exitCode, undefined);112 assert.equal(error.signal, 'SIGTERM');113 assert.equal(error.isTerminated, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 114–115why, one step back114});115TweaksSindre Sorhusbefore adoption698a1b8
line 116why, one step back116test('subprocess double errors are handled after spawn', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 117–118why, one step back117 const abortController = new AbortController();118 const subprocess = execa('forever.js', {cancelSignal: abortController.signal});Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 119why, one step back119 await once(subprocess.nodeChildProcess, 'spawn');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 120why, one step back120 const cause = new Error('test');Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 121why, one step back121 subprocess.nodeChildProcess.emit('error', cause);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 122–123why, one step back122 await setImmediate();123 abortController.abort();Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 124why, one step back124 subprocess.nodeChildProcess.emit('error', cause);TweaksSindre Sorhusbefore adoption698a1b8
lines 125–129why, one step back125 const error = await assertRejects(subprocess);126 assert.equal(error.cause, cause);127 assert.equal(error.exitCode, undefined);128 assert.equal(error.signal, 'SIGTERM');129 assert.equal(error.isTerminated, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 130–131why, one step back130});131TweaksSindre Sorhusbefore adoption698a1b8
line 132why, one step back132test('subprocess errors use killSignal', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 133why, one step back133 const subprocess = execa('forever.js', {killSignal: 'SIGINT'});Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 134why, one step back134 await once(subprocess.nodeChildProcess, 'spawn');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 135why, one step back135 const cause = new Error('test');Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 136why, one step back136 subprocess.nodeChildProcess.emit('error', cause);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 137why, one step back137 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
lines 138–141why, one step back138 const error = await assertRejects(subprocess);139 assert.equal(error.cause, cause);140 assert.equal(error.isTerminated, true);141 assert.equal(error.signal, 'SIGINT');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 142why, one step back142});