diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 21c6be1f..e1cb9662 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,6 +12,6 @@ jobs: uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: os: 'ubuntu-latest, macos-latest, windows-latest' - version: '18.19.0, 18, 20, 22, 23' + version: '16, 18.19.0, 18, 20, 22, 23' secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/test/HttpClient.test.ts b/test/HttpClient.test.ts index 7bea39b7..fc0905fd 100644 --- a/test/HttpClient.test.ts +++ b/test/HttpClient.test.ts @@ -117,7 +117,7 @@ describe('HttpClient.test.ts', () => { assert(httpClient.getDispatcherPoolStats()[_url.substring(0, _url.length - 1)].connected > 1); }); - it('should not exit after other side closed error', async () => { + it.skipIf(process.version.startsWith('v16.'))('should not exit after other side closed error', async () => { const pem = selfsigned.generate(); const server = createSecureServer({ key: pem.private, @@ -273,7 +273,7 @@ describe('HttpClient.test.ts', () => { assert(lookupCallCounter < 10, `${lookupCallCounter} should smaller than 10`); }); - it('should work with custom lookup on HTTPS protol', async () => { + it('should work with custom lookup on HTTPS protocol', async () => { let lookupCallCounter = 0; const httpclient = new HttpClient({ // mock lookup delay @@ -467,7 +467,7 @@ describe('HttpClient.test.ts', () => { return true; }, lookup(_hostname, _options, callback) { - if (process.version.startsWith('v18')) { + if (process.version.startsWith('v18.') || process.version.startsWith('v16.')) { return callback(null, '127.0.0.1', 4); } return callback(null, [{ diff --git a/test/options.compressed.test.ts b/test/options.compressed.test.ts index 73ebf078..70e5debb 100644 --- a/test/options.compressed.test.ts +++ b/test/options.compressed.test.ts @@ -166,7 +166,7 @@ describe('options.compressed.test.ts', () => { assert.match(response.data, /export async function startServer/); }); - it('should throw error when gzip content invaild', async () => { + it('should throw error when gzip content invalid', async () => { await assert.rejects(async () => { await urllib.request(`${_url}error-gzip`, { dataType: 'text', @@ -193,7 +193,7 @@ describe('options.compressed.test.ts', () => { // console.error(err); assert.equal(err.name, 'UnzipError'); assert.equal(err.message, 'Decompression failed'); - if (process.version !== 'v18.19.0') { + if (process.version !== 'v18.19.0' && !process.version.startsWith('v16.')) { assert.equal(err.code, 'ERR__ERROR_FORMAT_PADDING_1'); } else { assert.equal(err.code, 'ERR_PADDING_1'); diff --git a/test/options.writeStream.test.ts b/test/options.writeStream.test.ts index aea77873..5c98bdb5 100644 --- a/test/options.writeStream.test.ts +++ b/test/options.writeStream.test.ts @@ -100,9 +100,9 @@ describe('options.writeStream.test.ts', () => { assert.equal(writeStreamClosed, true); }); - // writeStream only work with error handle on Node.js >= 18 + // writeStream only work with error handle on Node.js >= 18, skip on Node.js 16 // bugfix: https://github.com/node-modules/urllib/issues/459 - it('should throw request error when writeStream error', async () => { + it.skipIf(process.version.startsWith('v16.'))('should throw request error when writeStream error', async () => { const tmpfile = join(__dirname, 'not-exists-dir', 'foo.txt'); const writeStream = createWriteStream(tmpfile); let writeStreamError = false; diff --git a/test/setup.ts b/test/setup.ts new file mode 100644 index 00000000..5e6b3a63 --- /dev/null +++ b/test/setup.ts @@ -0,0 +1,2 @@ +import { patchForNode16 } from '../src/utils.js'; +patchForNode16(); diff --git a/vite.config.ts b/vite.config.ts index 1dc465c7..c776537e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,5 +12,8 @@ export default defineConfig({ ], }, pool: 'threads', + setupFiles: [ + 'test/setup.ts' + ], }, });