* Detect patterns from code - FRAMEWORK-AGNOSTIC * Framework-specific patterns should be detected by framework analyzers
(content: string, filePath: string)
| 550 | * Framework-specific patterns should be detected by framework analyzers |
| 551 | */ |
| 552 | detectFromCode(content: string, filePath: string): void { |
| 553 | // Test file detection |
| 554 | if (filePath.includes('.spec.') || filePath.includes('.test.') || filePath.includes('/e2e/')) { |
| 555 | const detected = this.detectTestFramework(content, filePath); |
| 556 | |
| 557 | if (detected.e2e) { |
| 558 | this.track('e2eFramework', detected.e2e); |
| 559 | } |
| 560 | |
| 561 | if (detected.unit) { |
| 562 | this.track('unitTestFramework', detected.unit); |
| 563 | } |
| 564 | |
| 565 | // Keep testingFramework aligned with unit tests only. |
| 566 | // e2e trends are tracked separately via e2eFramework. |
| 567 | if (detected.unit && detected.unit !== 'Generic Test') { |
| 568 | this.track('testingFramework', detected.unit); |
| 569 | } |
| 570 | |
| 571 | // Track mocking style (secondary pattern) |
| 572 | if (content.includes('jest.mock(') || content.includes('jest.fn(')) { |
| 573 | this.track('testMocking', 'Jest mocks'); |
| 574 | } else if (content.includes('.spyOn(')) { |
| 575 | this.track('testMocking', 'Spy-based mocking'); |
| 576 | } else if (content.includes('vi.mock(') || content.includes('vi.fn(')) { |
| 577 | this.track('testMocking', 'Vitest mocks'); |
| 578 | } |
| 579 | |
| 580 | // Track testing utilities |
| 581 | if (content.includes('MockComponent') || content.includes('ng-mocks')) { |
| 582 | this.track('testUtility', 'ng-mocks'); |
| 583 | } else if (content.includes('msw') && content.includes('setupServer')) { |
| 584 | this.track('testUtility', 'MSW'); |
| 585 | } else if (content.includes('@testing-library')) { |
| 586 | this.track('testUtility', 'Testing Library'); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // Generic state patterns (framework-agnostic) |
| 591 | if (/BehaviorSubject|ReplaySubject|Subject|Observable/.test(content)) { |
| 592 | this.track('stateManagement', 'RxJS'); |
| 593 | } |
| 594 | if (content.includes('createStore') || content.includes('configureStore')) { |
| 595 | this.track('stateManagement', 'Redux-style store'); |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | /** |
no test coverage detected