| import { fetchGithubReadme } from '../engines/github/github.js'; |
|
|
| |
| |
| |
|
|
| interface TestCase { |
| url: string; |
| description: string; |
| shouldSucceed: boolean; |
| } |
|
|
| const testCases: TestCase[] = [ |
| { |
| url: 'https://github.com/imsyy/SPlayer/blob/dev/README.md', |
| description: 'GitHub URL with branch and file path', |
| shouldSucceed: true |
| }, |
| { |
| url: 'https://github.com/Aas-ee/open-webSearch?tab=readme-ov-file', |
| description: 'GitHub URL with query parameters', |
| shouldSucceed: true |
| }, |
| { |
| url: 'https://github.com/facebook/react', |
| description: 'Simple GitHub repository URL', |
| shouldSucceed: true |
| }, |
| { |
| url: 'git@github.com:microsoft/vscode.git', |
| description: 'SSH Git URL format', |
| shouldSucceed: true |
| }, |
| { |
| url: 'https://github.com/invalid/nonexistent-repo', |
| description: 'Non-existent repository (should fail gracefully)', |
| shouldSucceed: false |
| }, |
| { |
| url: 'invalid-url', |
| description: 'Invalid URL format (should fail gracefully)', |
| shouldSucceed: false |
| }, |
| { |
| url: 'https://github.com/torvalds/linux', |
| description: 'Large repository (Linux kernel)', |
| shouldSucceed: true |
| }, |
| { |
| url: 'https://www.github.com/nodejs/node.git', |
| description: 'URL with www prefix and .git suffix', |
| shouldSucceed: true |
| } |
| ]; |
|
|
| |
| |
| |
| async function runTestCase(testCase: TestCase): Promise<void> { |
| console.log(`\nπ§ͺ Testing: ${testCase.description}`); |
| console.log(`π URL: ${testCase.url}`); |
|
|
| try { |
| const startTime = Date.now(); |
| const result = await fetchGithubReadme(testCase.url); |
| const duration = Date.now() - startTime; |
|
|
| if (result && testCase.shouldSucceed) { |
| console.log(`β
SUCCESS (${duration}ms) - README fetched (${result.length} characters)`); |
| console.log(`π Preview: ${result.substring(0, 100).replace(/\n/g, ' ')}...`); |
| } else if (!result && !testCase.shouldSucceed) { |
| console.log(`β
SUCCESS (${duration}ms) - Failed as expected`); |
| } else if (result && !testCase.shouldSucceed) { |
| console.log(`β οΈ UNEXPECTED SUCCESS (${duration}ms) - Expected to fail but got result`); |
| } else { |
| console.log(`β UNEXPECTED FAILURE (${duration}ms) - Expected success but failed`); |
| } |
| } catch (error) { |
| if (testCase.shouldSucceed) { |
| console.log(`β ERROR - Unexpected exception:`, error); |
| } else { |
| console.log(`β
SUCCESS - Failed as expected with exception`); |
| } |
| } |
| } |
|
|
| |
| |
| |
| async function runAllTests(): Promise<void> { |
| console.log('π Starting GitHub README Fetcher Test Suite'); |
| console.log('=' .repeat(60)); |
|
|
| let successCount = 0; |
| let failureCount = 0; |
| const startTime = Date.now(); |
|
|
| for (const testCase of testCases) { |
| try { |
| await runTestCase(testCase); |
| successCount++; |
| } catch (error) { |
| console.log(`β Test case failed with exception:`, error); |
| failureCount++; |
| } |
|
|
| |
| await new Promise(resolve => setTimeout(resolve, 1000)); |
| } |
|
|
| const totalTime = Date.now() - startTime; |
|
|
| console.log('\n' + '=' .repeat(60)); |
| console.log('π Test Results Summary:'); |
| console.log(`β
Successful tests: ${successCount}`); |
| console.log(`β Failed tests: ${failureCount}`); |
| console.log(`β±οΈ Total time: ${totalTime}ms`); |
| console.log(`π Success rate: ${((successCount / testCases.length) * 100).toFixed(1)}%`); |
|
|
| if (failureCount === 0) { |
| console.log('π All tests completed successfully!'); |
| } else { |
| console.log('β οΈ Some tests failed. Please review the results above.'); |
| } |
| } |
|
|
| |
| |
| |
| async function runPerformanceTest(): Promise<void> { |
| console.log('\nπββοΈ Running Performance Test...'); |
|
|
| const testUrl = 'https://github.com/facebook/react'; |
| const concurrentRequests = 5; |
|
|
| const startTime = Date.now(); |
|
|
| const promises = Array(concurrentRequests).fill(null).map(async (_, index) => { |
| console.log(`π Starting concurrent request ${index + 1}`); |
| return fetchGithubReadme(testUrl); |
| }); |
|
|
| try { |
| const results = await Promise.all(promises); |
| const endTime = Date.now(); |
|
|
| const successfulResults = results.filter(result => result !== null); |
|
|
| console.log(`β‘ Performance Test Results:`); |
| console.log(`π Concurrent requests: ${concurrentRequests}`); |
| console.log(`β
Successful requests: ${successfulResults.length}`); |
| console.log(`β±οΈ Total time: ${endTime - startTime}ms`); |
| console.log(`π Average time per request: ${((endTime - startTime) / concurrentRequests).toFixed(1)}ms`); |
|
|
| } catch (error) { |
| console.log(`β Performance test failed:`, error); |
| } |
| } |
|
|
| |
| |
| |
| async function main(): Promise<void> { |
| try { |
| await runAllTests(); |
| await runPerformanceTest(); |
| } catch (error) { |
| console.error('β Test suite failed:', error); |
| process.exit(1); |
| } |
| } |
|
|
|
|
| main().catch(console.error); |
|
|
|
|
|
|