Skip to content

Commit

Permalink
Run tests on Node.js 22 (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored May 5, 2024
1 parent 97c0a0b commit 113a7fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
node-version:
- 20
- 22
- 18
os:
- ubuntu
Expand Down
23 changes: 20 additions & 3 deletions test/terminate/kill-signal.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import {once} from 'node:events';
import {platform, version} from 'node:process';
import {setImmediate} from 'node:timers/promises';
import test from 'ava';
import {execa} from '../../index.js';
import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

setFixtureDirectory();

const isWindows = platform === 'win32';
const majorNodeVersion = Number(version.split('.')[0].slice(1));

test('Can call `.kill()` multiple times', async t => {
const subprocess = execa('forever.js');
subprocess.kill();
subprocess.kill();

const {isTerminated, signal} = await t.throwsAsync(subprocess);
t.true(isTerminated);
t.is(signal, 'SIGTERM');
const {exitCode, isTerminated, signal, code} = await t.throwsAsync(subprocess);

// 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 113a7fe

Please sign in to comment.