Skip to content

Commit

Permalink
simplify connection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Aug 29, 2023
1 parent 21b4877 commit fe5e4a1
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions packages/socks-proxy-agent/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,25 @@ describe('SocksProxyAgent', () => {
});

it('should connect over ipv6 socket', async () => {
httpServer.once('request', function (req, res) {
res.end(JSON.stringify(req.headers));
});
httpServer.once('request', (req, res) => res.end());

const res = await req(new URL('/foo', httpServerUrl), {
agent: new SocksProxyAgent(socksServerUrl, {
socketOptions: { family: 6 },
}),
headers: { foo: 'bar' },
agent: new SocksProxyAgent(socksServerUrl, { socketOptions: { family: 6 } }),
});
const body = await json(res);
assert.equal('bar', body.foo);
assert(res);
});

it('should refuse connection over ipv4 socket', async () => {
let err: Error | undefined;
try {
await req(new URL('/foo', httpServerUrl), {
agent: new SocksProxyAgent(socksServerUrl, {
socketOptions: { family: 4 },
}),
agent: new SocksProxyAgent(socksServerUrl, { socketOptions: { family: 4 } }),
});
} catch (_err) {
err = _err as Error;
}
assert(err);
assert.equal(
err.message,
`connect ECONNREFUSED 127.0.0.1:${socksServerUrl.port}`
);
assert.equal(err.message, `connect ECONNREFUSED 127.0.0.1:${socksServerUrl.port}`);
});
});

Expand Down

0 comments on commit fe5e4a1

Please sign in to comment.