proxy-auto-ts
Version:
A comprehensive TypeScript library for automatic proxy management with validation, rotation, and intelligent selection
78 lines โข 3.35 kB
JavaScript
import { ProxyManager } from "./lib.js";
// Comprehensive test utility
async function comprehensiveTest() {
console.log("๐งช Comprehensive Proxy Test");
const proxyManager = new ProxyManager({
timeout: 8000,
validationTimeout: 5000
});
await proxyManager.initialize();
console.log(`๐ Loaded ${await proxyManager.getProxyCount()} proxies`);
try {
// Test 1: Basic IP check with limited retries
console.log(`\n๐ Test 1: Basic IP check...`);
const result = await proxyManager.fetchWithProxy("https://httpbin.org/ip", 3);
console.log(`โ
Working proxy found: ${result.proxy}`);
console.log(`๐ Your IP: ${JSON.stringify(result.data)}`);
console.log(`โฑ๏ธ Latency: ${result.latency}ms`);
// Test 2: Find best proxy with limited testing
console.log(`\n๐ Test 2: Finding best proxy...`);
const bestProxy = await proxyManager.findBestProxy("https://httpbin.org/ip", 5);
console.log(`๐ Best proxy: ${bestProxy.proxy} (${bestProxy.latency}ms)`);
// Test 3: Test specific website
console.log(`\n๐ Test 3: Testing specific website...`);
try {
const targetResult = await proxyManager.fetchWithSpecificProxy("https://httpbin.org/json", bestProxy.proxy);
console.log(`โ
Target website accessible!`);
console.log(`๐ Content length: ${JSON.stringify(targetResult.data).length} characters`);
}
catch (error) {
console.log(`โ ๏ธ Target website blocked: ${error.message}`);
console.log(`But proxy works for other sites!`);
}
// Test 4: Library statistics
console.log(`\n๐ Test 4: Library statistics...`);
const stats = await proxyManager.getStats();
console.log(`๐ Total proxies: ${stats.totalProxies}`);
console.log(`๐ Proxy list path: ${stats.proxyListPath}`);
console.log(`โ๏ธ Timeout: ${stats.config.timeout}ms`);
console.log(`\n๐ All tests completed successfully!`);
}
catch (error) {
console.error(`โ Test failed: ${error.message}`);
process.exit(1);
}
}
// Quick test utility
async function quickTest() {
console.log("๐ Quick Proxy Test");
const proxyManager = new ProxyManager();
try {
// Test with simple IP check
const result = await proxyManager.fetchWithProxy("https://httpbin.org/ip", 3);
console.log(`โ
Working proxy found: ${result.proxy}`);
console.log(`๐ Your IP: ${JSON.stringify(result.data)}`);
console.log(`โฑ๏ธ Latency: ${result.latency}ms`);
}
catch (error) {
console.error(`โ No working proxies found: ${error.message}`);
}
}
// Run if called directly
const isMainModule = import.meta.url === `file://${process.argv[1]}` ||
import.meta.url.endsWith('/test.ts') ||
process.argv[1]?.endsWith('test.ts');
if (isMainModule) {
// Run comprehensive test by default
comprehensiveTest()
.then(() => {
console.log(`\nโ
Tests completed successfully!`);
process.exit(0);
})
.catch((error) => {
console.error(`\nโ Tests failed:`, error.message);
process.exit(1);
});
}
export { quickTest, comprehensiveTest };
//# sourceMappingURL=test.js.map