Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions impit-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/express": "^5.0.0",
"@types/node": "^22.13.1",
"express": "^5.0.0",
"socksv5": "^0.0.6",
"socks-server-lib": "^0.0.3",
"tough-cookie": "^6.0.0",
"vitest": "^3.0.5"
},
Expand All @@ -49,13 +49,13 @@
"packageManager": "yarn@4.9.4",
"description": "Impit for JavaScript",
"optionalDependencies": {
"impit-darwin-x64": "0.5.4",
"impit-darwin-arm64": "0.5.4",
"impit-win32-x64-msvc": "0.5.4",
"impit-win32-arm64-msvc": "0.5.4",
"impit-darwin-x64": "0.5.4",
"impit-linux-arm64-gnu": "0.5.4",
"impit-linux-arm64-musl": "0.5.4",
"impit-linux-x64-gnu": "0.5.4",
"impit-linux-x64-musl": "0.5.4",
"impit-linux-arm64-gnu": "0.5.4",
"impit-linux-arm64-musl": "0.5.4"
"impit-win32-arm64-msvc": "0.5.4",
"impit-win32-x64-msvc": "0.5.4"
}
}
31 changes: 11 additions & 20 deletions impit-node/test/basics.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test, describe, expect, beforeAll, afterAll } from 'vitest';

import { HttpMethod, Impit, Browser } from '../index.wrapper.js';
import { Server } from 'http';
import type { Server } from 'net';
import { routes, runServer } from './mock.server.js';

import { CookieJar } from 'tough-cookie';
import socks from 'socksv5';
import { runSocksServer } from 'socks-server-lib';

function getHttpBinUrl(path: string, https?: boolean): string {
https ??= true;
Expand All @@ -28,28 +28,16 @@ async function getServer() {
return localServer;
}

async function startSocksServer() {
return new Promise<Server>((resolve, reject) => {
const srv = (socks as any).createServer((info, accept, deny) => accept());
srv.listen(7625, 'localhost', () => {
resolve(srv);
});
srv.on('error', (err: Error) => {
reject(err);
});
srv.useAuth(socks.auth.None());
});
}

let socksServer: Server | null = null;
let socksConnectionCount = 0;
beforeAll(async () => {
// Warms up the httpbin instance, so that the first tests don't timeout.
// Has a longer timeout itself (5s vs 30s) to avoid flakiness.
await fetch(getHttpBinUrl('/get'));
// Start the local server
await getServer();

socksServer = await startSocksServer();
socksServer = await runSocksServer({ host: 'localhost', port: 7625, onData: () => { socksConnectionCount++; }});
}, 30e3);

afterAll(async () => {
Expand All @@ -60,7 +48,8 @@ afterAll(async () => {
}),
Promise.race([
new Promise<void>(res => {
socksServer?.close(() => res())
socksServer?.on('close', () => res());
socksServer?.close();
}),
new Promise<void>(res => {
setTimeout(() => {
Expand All @@ -69,6 +58,8 @@ afterAll(async () => {
})
]),
]);

expect(socksConnectionCount).toBe(6);
});

describe.each([
Expand Down Expand Up @@ -139,17 +130,17 @@ describe.each([
]);
});

test('supports socks proxy', async (t) => {
test.each([['socks4'], ['socks5']])('supports %s proxy', async (proxyType) => {
const impit = new Impit({
browser,
proxyUrl: 'socks5://localhost:7625',
proxyUrl: `${proxyType}://localhost:7625`,
});

const response = await impit.fetch(
getHttpBinUrl('/get'),
);

t.expect(response.status).toBe(200);
expect(response.status).toBe(200);
const json = await response.json();
expect(json).toHaveProperty('url');
expect(json).toHaveProperty('headers');
Expand Down
Loading
Loading