From e5b1cd95a58f188d128cf7f38f5519eaeef925ba Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Wed, 12 Mar 2025 22:56:40 +0900 Subject: [PATCH 1/3] chore(test): properly fix ipv6 addresses --- karma.conf.cjs | 1 + package-lock.json | 15 ++++++++------- package.json | 2 +- test/integration.js | 7 +++++-- test/net-polyfill.js | 1 + 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 test/net-polyfill.js diff --git a/karma.conf.cjs b/karma.conf.cjs index 17959fa4..f17d626f 100644 --- a/karma.conf.cjs +++ b/karma.conf.cjs @@ -71,6 +71,7 @@ module.exports = (config) => { entries: { 'node:http': 'test/http-polyfill.js', 'node:process': 'test/process-polyfill.js', + 'node:net': 'test/net-polyfill.js', }, }), require('@rollup/plugin-node-resolve').default({ // eslint-disable-line global-require diff --git a/package-lock.json b/package-lock.json index 40d266d7..7eec7204 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,7 @@ "puppeteer": "^24.3.0", "rollup": "^4.34.9", "rollup-plugin-istanbul": "^5.0.0", - "superagent": "^10.1.1", + "superagent": "^10.2.0", "superagent-prefix": "^0.0.2", "typescript": "^5.8.2" }, @@ -7148,10 +7148,11 @@ } }, "node_modules/superagent": { - "version": "10.1.1", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-10.1.1.tgz", - "integrity": "sha512-9pIwrHrOj3uAnqg9gDlW7EA2xv+N5au/dSM0kM22HTqmUu8jBxNT+8uA7tA3UoCnmiqzpSbu8rasIUZvbyamMQ==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-10.2.0.tgz", + "integrity": "sha512-IKeoGox6oG9zyDeizaezkJ2/aK0wc5la9st7WsAKyrAkfJ56W3whVbVtF68k6wuc87/y9T85NyON5FLz7Mrzzw==", "dev": true, + "license": "MIT", "dependencies": { "component-emitter": "^1.3.0", "cookiejar": "^2.1.4", @@ -12917,9 +12918,9 @@ "dev": true }, "superagent": { - "version": "10.1.1", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-10.1.1.tgz", - "integrity": "sha512-9pIwrHrOj3uAnqg9gDlW7EA2xv+N5au/dSM0kM22HTqmUu8jBxNT+8uA7tA3UoCnmiqzpSbu8rasIUZvbyamMQ==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-10.2.0.tgz", + "integrity": "sha512-IKeoGox6oG9zyDeizaezkJ2/aK0wc5la9st7WsAKyrAkfJ56W3whVbVtF68k6wuc87/y9T85NyON5FLz7Mrzzw==", "dev": true, "requires": { "component-emitter": "^1.3.0", diff --git a/package.json b/package.json index fc4b8d77..20d540e1 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "puppeteer": "^24.3.0", "rollup": "^4.34.9", "rollup-plugin-istanbul": "^5.0.0", - "superagent": "^10.1.1", + "superagent": "^10.2.0", "superagent-prefix": "^0.0.2", "typescript": "^5.8.2" } diff --git a/test/integration.js b/test/integration.js index aaeab4eb..70cb9ef9 100644 --- a/test/integration.js +++ b/test/integration.js @@ -1,5 +1,6 @@ import { createServer } from 'node:http'; import { env } from 'node:process'; +import { isIP } from 'node:net'; import { expect, use } from 'chai'; import request from 'superagent'; import prefix from 'superagent-prefix'; @@ -11,6 +12,8 @@ use(superagent()); const BASEURL = env.HTTPBIN_BASEURL ?? 'https://httpbin.org'; +const normalizeAddress = (url) => (isIP(url) === 6 ? `[${url}]` : url); + describe('superagent', () => { const isNode = typeof process === 'object'; // eslint-disable-next-line unicorn/prefer-global-this @@ -131,7 +134,7 @@ describe('superagent', () => { const { address, port } = server.address(); request - .get(`http://${address.replace('::', 'localhost')}:${port}/`) + .get(`http://${normalizeAddress(address)}:${port}/`) .set('X-API-Key', 'test2') .end((err, res) => { expect(res).to.have.status(200); @@ -151,7 +154,7 @@ describe('superagent', () => { server.listen(0, () => { const { address, port } = server.address(); - const agent = request.agent().use(prefix(`http://${address.replace('::', 'localhost')}:${port}`)); + const agent = request.agent().use(prefix(`http://${normalizeAddress(address)}:${port}`)); agent .get('/') diff --git a/test/net-polyfill.js b/test/net-polyfill.js new file mode 100644 index 00000000..103ca431 --- /dev/null +++ b/test/net-polyfill.js @@ -0,0 +1 @@ +export const isIP = undefined; // eslint-disable-line import/prefer-default-export From 8e1a2615230c7243b166383a6c45c754e40e1059 Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Wed, 12 Mar 2025 23:17:59 +0900 Subject: [PATCH 2/3] simplify --- karma.conf.cjs | 1 - test/integration.js | 10 +++------- test/net-polyfill.js | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 test/net-polyfill.js diff --git a/karma.conf.cjs b/karma.conf.cjs index f17d626f..17959fa4 100644 --- a/karma.conf.cjs +++ b/karma.conf.cjs @@ -71,7 +71,6 @@ module.exports = (config) => { entries: { 'node:http': 'test/http-polyfill.js', 'node:process': 'test/process-polyfill.js', - 'node:net': 'test/net-polyfill.js', }, }), require('@rollup/plugin-node-resolve').default({ // eslint-disable-line global-require diff --git a/test/integration.js b/test/integration.js index 70cb9ef9..27026b4e 100644 --- a/test/integration.js +++ b/test/integration.js @@ -1,6 +1,5 @@ import { createServer } from 'node:http'; import { env } from 'node:process'; -import { isIP } from 'node:net'; import { expect, use } from 'chai'; import request from 'superagent'; import prefix from 'superagent-prefix'; @@ -12,7 +11,7 @@ use(superagent()); const BASEURL = env.HTTPBIN_BASEURL ?? 'https://httpbin.org'; -const normalizeAddress = (url) => (isIP(url) === 6 ? `[${url}]` : url); +const normalizeAddress = ({ address, family, port }) => `http://${(family === 'IPv6' ? `[${address}]` : address)}:${port}/`; describe('superagent', () => { const isNode = typeof process === 'object'; @@ -131,10 +130,8 @@ describe('superagent', () => { }); server.listen(0, () => { - const { address, port } = server.address(); - request - .get(`http://${normalizeAddress(address)}:${port}/`) + .get(normalizeAddress(server.address())) .set('X-API-Key', 'test2') .end((err, res) => { expect(res).to.have.status(200); @@ -153,8 +150,7 @@ describe('superagent', () => { }); server.listen(0, () => { - const { address, port } = server.address(); - const agent = request.agent().use(prefix(`http://${normalizeAddress(address)}:${port}`)); + const agent = request.agent().use(prefix(normalizeAddress(server.address()))); agent .get('/') diff --git a/test/net-polyfill.js b/test/net-polyfill.js deleted file mode 100644 index 103ca431..00000000 --- a/test/net-polyfill.js +++ /dev/null @@ -1 +0,0 @@ -export const isIP = undefined; // eslint-disable-line import/prefer-default-export From dcc926f4249ea6ddcb1e95698a4ec6f1db9b1f1c Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Wed, 12 Mar 2025 23:30:47 +0900 Subject: [PATCH 3/3] fix superagent@9 --- .github/workflows/test.yml | 1 + test/integration.js | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 145dae40..41ed05b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,6 +57,7 @@ jobs: run: npm run cover env: HTTPBIN_BASEURL: http://localhost + SUPERAGENT_VERSION: ${{ matrix.superagent-version }} - name: Install lcov uses: awalsh128/cache-apt-pkgs-action@latest diff --git a/test/integration.js b/test/integration.js index 27026b4e..8bd47ab6 100644 --- a/test/integration.js +++ b/test/integration.js @@ -9,9 +9,17 @@ import superagent from 'chai-superagent'; use(superagent()); +// https://github.com/ladjs/superagent/pull/1805 +// https://github.com/ladjs/superagent/pull/1829 +const { SUPERAGENT_VERSION } = env; const BASEURL = env.HTTPBIN_BASEURL ?? 'https://httpbin.org'; -const normalizeAddress = ({ address, family, port }) => `http://${(family === 'IPv6' ? `[${address}]` : address)}:${port}/`; +const normalizeAddress = ({ address, family, port }) => `http://${(SUPERAGENT_VERSION === '9' + ? address.replace('::', 'localhost') + : (family === 'IPv6' + ? `[${address}]` + : address + ))}:${port}/`; describe('superagent', () => { const isNode = typeof process === 'object';