Skip to content

Commit

Permalink
test: add node 16
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 11, 2024
1 parent 86f9d09 commit be8cb09
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
6 changes: 3 additions & 3 deletions test/HttpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, [{
Expand Down
4 changes: 2 additions & 2 deletions test/options.compressed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/options.writeStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { patchForNode16 } from '../src/utils.js';
patchForNode16();
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ export default defineConfig({
],
},
pool: 'threads',
setupFiles: [
'test/setup.ts'
],
},
});

0 comments on commit be8cb09

Please sign in to comment.