Skip to content

Commit

Permalink
Fix tests in Node 22
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Oct 27, 2024
1 parent 5331bef commit b58f093
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions test/terminate/kill-signal.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {once} from 'node:events';
import {platform} from 'node:process';
import {constants} from 'node:os';
import {setImmediate} from 'node:timers/promises';
import test from 'ava';
import {execa, execaSync} from '../../index.js';
import {setFixtureDirectory} from '../helpers/fixtures-directory.js';
import {majorNodeVersion} from '../helpers/node-version.js';

setFixtureDirectory();

const isWindows = platform === 'win32';

const testKillSignal = async (t, killSignal) => {
const {isTerminated, signal} = await t.throwsAsync(execa('forever.js', {killSignal, timeout: 1}));
t.true(isTerminated);
Expand Down Expand Up @@ -57,10 +61,20 @@ test('Can call `.kill()` multiple times', async t => {
subprocess.kill();

const {exitCode, isTerminated, signal, code} = await t.throwsAsync(subprocess);
t.is(exitCode, undefined);
t.true(isTerminated);
t.is(signal, 'SIGTERM');
t.is(code, undefined);
// On Windows, calling `subprocess.kill()` twice emits an `error` event on the subprocess.
// This does not happen when passing an `error` argument, nor when passing a non-terminating signal.
// There is no easy way to make this cross-platform, so we document the difference here.
if (isWindows && majorNodeVersion === 22) {
t.is(exitCode, undefined);
t.false(isTerminated);
t.is(signal, undefined);
t.is(code, 'EPERM');
} else {
t.is(exitCode, undefined);
t.true(isTerminated);
t.is(signal, 'SIGTERM');
t.is(code, undefined);
}
});

test('execa() returns a promise with kill()', async t => {
Expand Down

0 comments on commit b58f093

Please sign in to comment.