* Detect test framework from content using config-driven matching * Returns detected framework with confidence based on priority scoring
(content: string, _filePath: string)
| 497 | * Returns detected framework with confidence based on priority scoring |
| 498 | */ |
| 499 | private detectTestFramework(content: string, _filePath: string): { unit?: string; e2e?: string } { |
| 500 | const results: { type: 'unit' | 'e2e'; name: string; priority: number }[] = []; |
| 501 | |
| 502 | for (const config of this.testFrameworkConfigs) { |
| 503 | const matched = config.indicators.some((indicator) => content.includes(indicator)); |
| 504 | if (matched) { |
| 505 | results.push({ type: config.type, name: config.name, priority: config.priority }); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | if (results.length === 0) return {}; |
| 510 | |
| 511 | // Find highest priority match for each type |
| 512 | const unitMatches = results |
| 513 | .filter((r) => r.type === 'unit') |
| 514 | .sort((a, b) => b.priority - a.priority); |
| 515 | const e2eMatches = results |
| 516 | .filter((r) => r.type === 'e2e') |
| 517 | .sort((a, b) => b.priority - a.priority); |
| 518 | |
| 519 | const detected: { unit?: string; e2e?: string } = {}; |
| 520 | |
| 521 | // For unit tests, apply special logic for TestBed disambiguation |
| 522 | if (unitMatches.length > 0) { |
| 523 | const topUnit = unitMatches[0]; |
| 524 | |
| 525 | // If only TestBed or Generic Test was found, try to disambiguate |
| 526 | if (topUnit.name === 'Angular TestBed' || topUnit.name === 'Generic Test') { |
| 527 | if (content.includes('jest')) { |
| 528 | detected.unit = 'Jest'; |
| 529 | } else if (content.includes('jasmine')) { |
| 530 | detected.unit = 'Jasmine'; |
| 531 | } else if (content.includes('vitest')) { |
| 532 | detected.unit = 'Vitest'; |
| 533 | } else { |
| 534 | detected.unit = topUnit.name; |
| 535 | } |
| 536 | } else { |
| 537 | detected.unit = topUnit.name; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | if (e2eMatches.length > 0) { |
| 542 | detected.e2e = e2eMatches[0].name; |
| 543 | } |
| 544 | |
| 545 | return detected; |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Detect patterns from code - FRAMEWORK-AGNOSTIC |