Skip to content

Commit 5e7e098

Browse files
authored
test: run test on Node.js 23 (#543)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for Node.js version 23 in the CI pipeline. - **Documentation** - Enhanced documentation for the `urllib` package with new sections, examples, and detailed explanations of the `request` method and its options. - Expanded `API Doc` and `Response Object` sections for better clarity. - Included advanced use case examples and updated benchmarks for performance metrics across Node.js versions. - **Tests** - Improved test coverage for the `HttpClient` class, focusing on connection statistics and client options validation. - Enhanced error handling and assertions in `writeStream` tests, reflecting updates for Node.js version 23 and improving robustness. - Refined error handling logic in `options.compressed` tests, ensuring accurate decompression error codes. - Adjusted timeout values in `options.timeout` tests to align with updated expectations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ef17c34 commit 5e7e098

File tree

10 files changed

+17
-14
lines changed

10 files changed

+17
-14
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
1313
with:
1414
os: 'ubuntu-latest, macos-latest, windows-latest'
15-
version: '18.19.0, 18, 20, 22'
15+
version: '18.19.0, 18, 20, 22, 23'
1616
secrets:
1717
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@ Node.js v22.3.0
345345

346346
[MIT](LICENSE)
347347

348-
<!-- GITCONTRIBUTOR_START -->
349-
350348
## Contributors
351349

352350
[![Contributors](https://contrib.rocks/image?repo=node-modules/urllib)](https://github.com/node-modules/urllib/graphs/contributors)

examples/search_github.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ urllib.request('https://api.github.com/legacy/user/search/location:china', {
88
timeout: 10000,
99
}).then(response => {
1010
console.log(response);
11+
console.log(response.data);
1112
});
1213

1314
// var https = require('https');

examples/timing.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function request(index) {
1616
}
1717
const res = await httpClient.request(url + '?index=' + index, {
1818
// data: { wd: 'nodejs' },
19-
dataType: 'json',
19+
// dataType: 'json',
2020
});
2121
console.log('---------------------------');
2222
console.log('No#%d: %s, content size: %d, requestUrls: %o, socket: %o, rt: %o',

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@
9191
"exports": {
9292
".": {
9393
"import": {
94-
"source": "./src/index.ts",
9594
"types": "./dist/esm/index.d.ts",
9695
"default": "./dist/esm/index.js"
9796
},
9897
"require": {
99-
"source": "./src/index.ts",
10098
"types": "./dist/commonjs/index.d.ts",
10199
"default": "./dist/commonjs/index.js"
102100
}
@@ -108,5 +106,6 @@
108106
"src"
109107
],
110108
"types": "./dist/commonjs/index.d.ts",
111-
"main": "./dist/commonjs/index.js"
109+
"main": "./dist/commonjs/index.js",
110+
"module": "./dist/esm/index.js"
112111
}

src/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class FetchFactory {
163163
[symbols.kEnableRequestTiming]: !!(init.timing ?? true),
164164
[symbols.kRequestTiming]: timing,
165165
// [symbols.kRequestOriginalOpaque]: originalOpaque,
166-
};
166+
} as FetchOpaque;
167167
const reqMeta: RequestMeta = {
168168
requestId,
169169
url: request.url,

test/HttpClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('HttpClient.test.ts', () => {
110110
httpClient.request(_url),
111111
]);
112112
console.log(httpClient.getDispatcherPoolStats());
113-
assert.equal(httpClient.getDispatcherPoolStats()['https://registry.npmmirror.com'].connected, 1);
113+
assert.equal(httpClient.getDispatcherPoolStats()['https://registry.npmmirror.com'].connected, 4);
114114
assert(httpClient.getDispatcherPoolStats()[_url.substring(0, _url.length - 1)].connected > 1);
115115
});
116116
});

test/options.compressed.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createWriteStream, createReadStream } from 'node:fs';
33
import { describe, it, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
44
import urllib from '../src/index.js';
55
import { startServer } from './fixtures/server.js';
6-
import { readableToString, createTempfile, nodeMajorVersion } from './utils.js';
6+
import { readableToString, createTempfile } from './utils.js';
77

88
describe('options.compressed.test.ts', () => {
99
let close: any;
@@ -193,7 +193,7 @@ describe('options.compressed.test.ts', () => {
193193
// console.error(err);
194194
assert.equal(err.name, 'UnzipError');
195195
assert.equal(err.message, 'Decompression failed');
196-
if (nodeMajorVersion() >= 20) {
196+
if (process.version !== 'v18.19.0') {
197197
assert.equal(err.code, 'ERR__ERROR_FORMAT_PADDING_1');
198198
} else {
199199
assert.equal(err.code, 'ERR_PADDING_1');

test/options.timeout.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('options.timeout.test.ts', () => {
5757

5858
it('should timeout 500ms throw error', async () => {
5959
await assert.rejects(async () => {
60-
const response = await urllib.request(`${_url}mock-bytes?timeout=1000`, {
60+
const response = await urllib.request(`${_url}mock-bytes?timeout=1500`, {
6161
timeout: [ 400, 500 ],
6262
});
6363
console.log(response.status, response.headers, response.data);

test/options.writeStream.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ describe('options.writeStream.test.ts', () => {
117117
// only Node.js >= 18 has stream.emitError
118118
if (err.message !== 'writeStream is destroyed') {
119119
assert.equal(err.name, 'Error');
120-
assert.equal(err.code, 'ENOENT');
121-
assert.match(err.message, /no such file or directory/);
120+
assert.match(err.code, /^ENOENT|ERR_STREAM_UNABLE_TO_PIPE$/);
121+
if (err.code === 'ERR_STREAM_UNABLE_TO_PIPE') {
122+
// change to ERR_STREAM_UNABLE_TO_PIPE on Node.js >= 23
123+
assert.equal(err.message, 'Cannot pipe to a closed or destroyed stream');
124+
} else {
125+
assert.match(err.message, /no such file or directory/);
126+
}
122127
}
123128
return true;
124129
});

0 commit comments

Comments
 (0)