Test Detection
The core package includes test framework detection and file scanning capabilities.
Supported Frameworks
- Jest:
*.test.js,*.test.ts,*.spec.js,*.spec.ts,__tests__/directories - Vitest: Same patterns as Jest
- Mocha:
*.test.js,*.spec.js,test/directories
Detection Methods
1. Configuration Files
The detector looks for framework configuration files:
jest.config.js,jest.config.ts,jest.config.jsonvitest.config.ts,vitest.config.js.mocharc.js,.mocharc.json,mocha.opts
2. Package.json Dependencies
Checks package.json for framework dependencies:
jestin dependencies or devDependenciesvitestin dependencies or devDependenciesmochain dependencies or devDependencies
3. Test Scripts
Analyzes test scripts in package.json:
- Scripts containing "jest", "vitest", or "mocha"
- Test command patterns
4. File Patterns
Scans for test files matching patterns:
*.test.js,*.test.ts*.spec.js,*.spec.ts- Files in
__tests__/directories - Files in
test/directories
Usage
Test detection is typically used through the scanner service:
import { scanProject } from '@projax/core';
const result = scanProject(projectId);
// Returns: { project, testsFound, tests }
Scanner Service
The scanner service provides:
scanProject(projectId: number): Scan a single projectscanAllProjects(): Scan all projects
Both functions:
- Detect test frameworks
- Find test files
- Update database with findings
- Return scan results
Framework Detection
The detector identifies frameworks in this order:
- Configuration files
- Package.json dependencies
- Test script patterns
- File patterns (fallback)
Related Documentation
- API Reference - Scanner functions
- CLI Scan Command - Using scan from CLI