Skip to content

Commit bf2b5b1

Browse files
authored
test: add node 16 (#562)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for testing against Node.js version 16 in the CI workflow. - Introduced a mechanism for specifying setup files in the test configuration. - **Bug Fixes** - Corrected typos in test descriptions for clarity and accuracy. - Updated error handling logic in tests to accommodate Node.js version checks. - **Tests** - Enhanced test suite with conditional skips based on Node.js version for various test cases. - Maintained overall structure and assertions in tests to ensure expected behavior across different scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 86f9d09 commit bf2b5b1

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
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, 23'
15+
version: '16, 18.19.0, 18, 20, 22, 23'
1616
secrets:
1717
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

test/HttpClient.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('HttpClient.test.ts', () => {
117117
assert(httpClient.getDispatcherPoolStats()[_url.substring(0, _url.length - 1)].connected > 1);
118118
});
119119

120-
it('should not exit after other side closed error', async () => {
120+
it.skipIf(process.version.startsWith('v16.'))('should not exit after other side closed error', async () => {
121121
const pem = selfsigned.generate();
122122
const server = createSecureServer({
123123
key: pem.private,
@@ -273,7 +273,7 @@ describe('HttpClient.test.ts', () => {
273273
assert(lookupCallCounter < 10, `${lookupCallCounter} should smaller than 10`);
274274
});
275275

276-
it('should work with custom lookup on HTTPS protol', async () => {
276+
it('should work with custom lookup on HTTPS protocol', async () => {
277277
let lookupCallCounter = 0;
278278
const httpclient = new HttpClient({
279279
// mock lookup delay
@@ -467,7 +467,7 @@ describe('HttpClient.test.ts', () => {
467467
return true;
468468
},
469469
lookup(_hostname, _options, callback) {
470-
if (process.version.startsWith('v18')) {
470+
if (process.version.startsWith('v18.') || process.version.startsWith('v16.')) {
471471
return callback(null, '127.0.0.1', 4);
472472
}
473473
return callback(null, [{

test/options.compressed.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('options.compressed.test.ts', () => {
166166
assert.match(response.data, /export async function startServer/);
167167
});
168168

169-
it('should throw error when gzip content invaild', async () => {
169+
it('should throw error when gzip content invalid', async () => {
170170
await assert.rejects(async () => {
171171
await urllib.request(`${_url}error-gzip`, {
172172
dataType: 'text',
@@ -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 (process.version !== 'v18.19.0') {
196+
if (process.version !== 'v18.19.0' && !process.version.startsWith('v16.')) {
197197
assert.equal(err.code, 'ERR__ERROR_FORMAT_PADDING_1');
198198
} else {
199199
assert.equal(err.code, 'ERR_PADDING_1');

test/options.writeStream.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ describe('options.writeStream.test.ts', () => {
100100
assert.equal(writeStreamClosed, true);
101101
});
102102

103-
// writeStream only work with error handle on Node.js >= 18
103+
// writeStream only work with error handle on Node.js >= 18, skip on Node.js 16
104104
// bugfix: https://github.com/node-modules/urllib/issues/459
105-
it('should throw request error when writeStream error', async () => {
105+
it.skipIf(process.version.startsWith('v16.'))('should throw request error when writeStream error', async () => {
106106
const tmpfile = join(__dirname, 'not-exists-dir', 'foo.txt');
107107
const writeStream = createWriteStream(tmpfile);
108108
let writeStreamError = false;

test/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { patchForNode16 } from '../src/utils.js';
2+
patchForNode16();

vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ export default defineConfig({
1212
],
1313
},
1414
pool: 'threads',
15+
setupFiles: [
16+
'test/setup.ts'
17+
],
1518
},
1619
});

0 commit comments

Comments
 (0)