UNPKG

proxy-auto-ts

Version:

A comprehensive TypeScript library for automatic proxy management with validation, rotation, and intelligent selection

78 lines โ€ข 3.35 kB
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