()
| 488 | * Main test runner function |
| 489 | */ |
| 490 | export async function testSearchCode() { |
| 491 | console.log(`${colors.blue}Starting search functionality tests...${colors.reset}`); |
| 492 | |
| 493 | let originalConfig; |
| 494 | |
| 495 | try { |
| 496 | // Setup |
| 497 | originalConfig = await setup(); |
| 498 | |
| 499 | // Run all tests |
| 500 | await testBasicSearch(); |
| 501 | await testCaseSensitiveSearch(); |
| 502 | await testCaseInsensitiveSearch(); |
| 503 | await testFilePatternFiltering(); |
| 504 | await testMaxResults(); |
| 505 | await testContextLines(); |
| 506 | await testIncludeHidden(); |
| 507 | await testTimeout(); |
| 508 | await testNoMatches(); |
| 509 | await testInvalidPath(); |
| 510 | await testInvalidArguments(); |
| 511 | await testFileSearch(); |
| 512 | |
| 513 | console.log(`${colors.green}✅ All search functionality tests passed!${colors.reset}`); |
| 514 | return true; |
| 515 | |
| 516 | } catch (error) { |
| 517 | console.error(`${colors.red}❌ Test failed: ${error.message}${colors.reset}`); |
| 518 | console.error(error.stack); |
| 519 | throw error; |
| 520 | } finally { |
| 521 | // Cleanup |
| 522 | if (originalConfig) { |
| 523 | await teardown(originalConfig); |
| 524 | } |
| 525 | |
| 526 | // Force cleanup of search manager to ensure process can exit |
| 527 | try { |
| 528 | const { searchManager, stopSearchManagerCleanup } = await import('../dist/search-manager.js'); |
| 529 | |
| 530 | // Terminate all active sessions |
| 531 | const activeSessions = searchManager.listSearchSessions(); |
| 532 | for (const session of activeSessions) { |
| 533 | searchManager.terminateSearch(session.id); |
| 534 | } |
| 535 | |
| 536 | // Stop the cleanup interval |
| 537 | stopSearchManagerCleanup(); |
| 538 | |
| 539 | // Clear the sessions map |
| 540 | searchManager.sessions?.clear?.(); |
| 541 | } catch (e) { |
| 542 | // Ignore import errors |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | // Export for use in run-all-tests.js |
no test coverage detected