From 1bc03b9f83b21b16dbba506bf458c69fe2ff75d2 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Mon, 7 Oct 2024 19:09:39 +1100 Subject: [PATCH] Account for different Node.js version default stream high water mark values. Also, enable testing Node.js v22 in CI. --- .github/workflows/ci.yml | 2 +- changelog.md | 3 ++- processRequest.mjs | 3 ++- processRequest.test.mjs | 11 +++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cf0d95..dc46b8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - node: ["18", "20"] + node: ["18", "20", "22"] steps: - uses: actions/checkout@v3 - name: Setup Node.js v${{ matrix.node }} diff --git a/changelog.md b/changelog.md index 9c744d0..65d13ed 100644 --- a/changelog.md +++ b/changelog.md @@ -36,10 +36,11 @@ - Updated the `package.json` field `repository` to conform to new npm requirements. - Updated GitHub Actions CI config: - - Updated the tested Node.js versions to v18, v20. + - Updated the tested Node.js versions to v18, v20, v22. - Migrated to the ESLint v9 CLI and “flat” config. - Integrated a new dev dependency [`eslint-plugin-jsdoc`](https://npm.im/eslint-plugin-jsdoc) and revised types. - Removed the Node.js CLI option `--unhandled-rejections=throw` in the package script `tests` as it’s now the default for all supported Node.js versions. +- Avoid hardcoding a default value in the type `FileUploadCreateReadStreamOptions` property `highWaterMark` description and use the function `getDefaultHighWaterMark` from `node:stream` in tests. - Omit unused catch bindings in the function `processRequest`. - Corrected the JSDoc type `FileUploadCreateReadStreamOptions` in the module `processRequest.mjs`. - Avoid using `return` in the middleware. diff --git a/processRequest.mjs b/processRequest.mjs index 8fb2d2c..fa376b7 100644 --- a/processRequest.mjs +++ b/processRequest.mjs @@ -396,7 +396,8 @@ export default function processRequest( * `base64url`, or `hex`. Defaults to `utf8`. * @property {ReadStreamOptions["highWaterMark"]} [highWaterMark] Maximum number * of bytes to store in the internal buffer before ceasing to read from the - * underlying resource. Defaults to `16384`. + * underlying resource. Defaults to the Node.js default high water mark for + * non object mode streams. */ /** diff --git a/processRequest.test.mjs b/processRequest.test.mjs index b2ec18a..59b62ff 100644 --- a/processRequest.test.mjs +++ b/processRequest.test.mjs @@ -11,6 +11,7 @@ import { throws, } from "node:assert"; import { createServer } from "node:http"; +import { getDefaultHighWaterMark } from "node:stream"; import { text } from "node:stream/consumers"; import { describe, it } from "node:test"; @@ -85,7 +86,10 @@ describe( ok(stream instanceof ReadStream); strictEqual(stream.readableEncoding, null); - strictEqual(stream.readableHighWaterMark, 16384); + strictEqual( + stream.readableHighWaterMark, + getDefaultHighWaterMark(false), + ); strictEqual(await text(stream), "a"); } catch (error) { serverError = error; @@ -143,7 +147,10 @@ describe( ok(stream instanceof ReadStream); strictEqual(stream.readableEncoding, null); - strictEqual(stream.readableHighWaterMark, 16384); + strictEqual( + stream.readableHighWaterMark, + getDefaultHighWaterMark(false), + ); strictEqual(await text(stream), "a"); } catch (error) { serverError = error;