From 3ca7b385543069a71c9b4de98528234da4f7a6eb Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 27 Oct 2024 22:26:00 +0000 Subject: [PATCH] Run CI tests on Node 23 --- .github/workflows/main.yml | 4 ++-- test/convert/duplex.js | 23 ++++++++++++++++------- test/convert/readable.js | 19 +++++++++++++------ test/fixtures/graceful-ref.js | 3 +-- test/helpers/node-version.js | 3 +++ test/terminate/kill-signal.js | 4 ++-- 6 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 test/helpers/node-version.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f25cd87a75..42286bf001 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: node-version: - - 22 + - 23 - 18 os: - ubuntu @@ -31,7 +31,7 @@ jobs: with: args: --cache --verbose --no-progress --include-fragments --exclude packagephobia --exclude /pull/ --exclude linkedin --exclude file:///test --exclude invalid.com '*.md' 'docs/*.md' '.github/**/*.md' '*.json' '*.js' 'lib/**/*.js' 'test/**/*.js' '*.ts' 'test-d/**/*.ts' fail: true - if: ${{ matrix.os == 'ubuntu' && matrix.node-version == 22 }} + if: ${{ matrix.os == 'ubuntu' && matrix.node-version == 23 }} - run: npm run lint - run: npm run type - run: npm run unit diff --git a/test/convert/duplex.js b/test/convert/duplex.js index dd71ce371a..d8ad6ef62e 100644 --- a/test/convert/duplex.js +++ b/test/convert/duplex.js @@ -23,6 +23,7 @@ import { getReadWriteSubprocess, } from '../helpers/convert.js'; import {foobarString} from '../helpers/input.js'; +import {majorNodeVersion} from '../helpers/node-version.js'; import {prematureClose, fullStdio, fullReadableStdio} from '../helpers/stdio.js'; import {defaultHighWaterMark} from '../helpers/stream.js'; @@ -148,13 +149,21 @@ test('.duplex() can pipe to errored stream with Stream.pipeline()', async t => { const cause = new Error('test'); outputStream.destroy(cause); - await assertPromiseError(t, pipeline(inputStream, stream, outputStream), cause); - await t.throwsAsync(finishedStream(stream)); - - await assertStreamError(t, inputStream, cause); - const error = await assertStreamError(t, stream, cause); - await assertStreamReadError(t, outputStream, cause); - await assertSubprocessError(t, subprocess, {cause: error}); + // Node 23 does not allow calling `stream.pipeline()` with an already errored stream + if (majorNodeVersion >= 23) { + outputStream.on('error', () => {}); + stream.on('error', () => {}); + await t.throwsAsync(pipeline(stream, outputStream), {code: 'ERR_STREAM_UNABLE_TO_PIPE'}); + stream.end(); + } else { + await assertPromiseError(t, pipeline(inputStream, stream, outputStream), cause); + await t.throwsAsync(finishedStream(stream)); + + await assertStreamError(t, inputStream, cause); + const error = await assertStreamError(t, stream, cause); + await assertStreamReadError(t, outputStream, cause); + await assertSubprocessError(t, subprocess, {cause: error}); + } }); test('.duplex() can be piped to errored stream with Stream.pipeline()', async t => { diff --git a/test/convert/readable.js b/test/convert/readable.js index 3b9454cb46..f73a8f9e0c 100644 --- a/test/convert/readable.js +++ b/test/convert/readable.js @@ -29,6 +29,7 @@ import { } from '../helpers/convert.js'; import {foobarString, foobarBuffer, foobarObject} from '../helpers/input.js'; import {simpleFull} from '../helpers/lines.js'; +import {majorNodeVersion} from '../helpers/node-version.js'; import {prematureClose, fullStdio} from '../helpers/stdio.js'; import {outputObjectGenerator, getOutputsAsyncGenerator} from '../helpers/generator.js'; import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js'; @@ -231,12 +232,18 @@ test('.readable() can pipe to errored stream with Stream.pipeline()', async t => const cause = new Error('test'); outputStream.destroy(cause); - await assertPromiseError(t, pipeline(stream, outputStream), cause); - await t.throwsAsync(finishedStream(stream)); - - const error = await assertStreamError(t, stream, cause); - await assertStreamReadError(t, outputStream, cause); - await assertSubprocessError(t, subprocess, {cause: error}); + // Node 23 does not allow calling `stream.pipeline()` with an already errored stream + if (majorNodeVersion >= 23) { + outputStream.on('error', () => {}); + await t.throwsAsync(pipeline(stream, outputStream), {code: 'ERR_STREAM_UNABLE_TO_PIPE'}); + } else { + await assertPromiseError(t, pipeline(stream, outputStream), cause); + await t.throwsAsync(finishedStream(stream)); + + const error = await assertStreamError(t, stream, cause); + await assertStreamReadError(t, outputStream, cause); + await assertSubprocessError(t, subprocess, {cause: error}); + } }); test('.readable() can be used with Stream.compose()', async t => { diff --git a/test/fixtures/graceful-ref.js b/test/fixtures/graceful-ref.js index ae28fba5c3..216b257fde 100755 --- a/test/fixtures/graceful-ref.js +++ b/test/fixtures/graceful-ref.js @@ -1,6 +1,5 @@ #!/usr/bin/env node -import {once} from 'node:events'; import {getCancelSignal} from 'execa'; const cancelSignal = await getCancelSignal(); -once(cancelSignal, 'abort'); +cancelSignal.addEventListener('abort', () => {}); diff --git a/test/helpers/node-version.js b/test/helpers/node-version.js new file mode 100644 index 0000000000..bbe49ab3c9 --- /dev/null +++ b/test/helpers/node-version.js @@ -0,0 +1,3 @@ +import {version} from 'node:process'; + +export const majorNodeVersion = Number(version.split('.')[0].slice(1)); diff --git a/test/terminate/kill-signal.js b/test/terminate/kill-signal.js index c3647d6dd6..1930ac9be1 100644 --- a/test/terminate/kill-signal.js +++ b/test/terminate/kill-signal.js @@ -1,15 +1,15 @@ import {once} from 'node:events'; -import {platform, version} from 'node:process'; +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 majorNodeVersion = Number(version.split('.')[0].slice(1)); const testKillSignal = async (t, killSignal) => { const {isTerminated, signal} = await t.throwsAsync(execa('forever.js', {killSignal, timeout: 1}));