Test impact analysis engine - maps source code dependencies to test files, detects which tests are affected by a git diff, and produces a minimal test execution plan. Run only what matters.
- Dependency Graph Builder - Parse imports/requires to build source-to-test mapping
- Git Diff Analysis - Parse changed files from any git diff (PR, commit, branch comparison)
- Transitive Impact - Follow the dependency chain to find all affected tests
- Execution Plan - Output minimal test paths for Jest, Playwright, or any runner
- Reduction Metrics - Calculate percentage of tests saved vs. running everything
- Circular Import Safety - Handles circular dependencies without infinite loops
+---------------+ +-----------------+ +----------------------+ +----------------+
| Git Diff |---->| Changed Files |---->| Dependency Graph |---->| Affected |
| (input) | | (parsed) | | Lookup (BFS) | | Tests |
+---------------+ +-----------------+ +----------------------+ +--------+-------+
|
v
+----------------+
| Execution |
| Plan |
+----------------+
Flow:
- Parse git diff output (--name-status format) to extract changed files
- Look up each changed file in the dependency graph
- Traverse importedBy edges (BFS) to find all transitive dependents
- Filter results to only test files
- Produce a minimal execution plan with reduction metrics
import { buildDependencyGraph, FileContent } from './graph';
import { parseDiffOutput } from './diff';
import { analyzeImpact } from './impact';
// 1. Parse your git diff
const diffOutput = 'M\tsrc/utils/helpers.ts\nA\tsrc/services/new-service.ts';
const diff = parseDiffOutput(diffOutput);
// 2. Build dependency graph from your source files
const files: FileContent[] = [
{ filePath: 'src/utils/helpers.ts', content: '...' },
{ filePath: 'src/services/user.ts', content: "import { x } from '../utils/helpers';" },
{ filePath: 'tests/user.test.ts', content: "import { svc } from '../src/services/user';" },
];
const graph = buildDependencyGraph(files);
// 3. Analyze impact
const allTests = ['tests/user.test.ts', 'tests/other.test.ts'];
const result = analyzeImpact(diff.all, graph, allTests);
console.log(result);
// {
// changedFiles: ['src/utils/helpers.ts', 'src/services/new-service.ts'],
// affectedTests: ['tests/user.test.ts'],
// totalTests: 2,
// impactedTests: 1,
// reductionPercent: 50,
// executionPlan: ['--testPathPattern="tests/user.test.ts"']
// }The dependency graph builder parses TypeScript/JavaScript files for import relationships:
Supported patterns:
- ES Modules:
import { x } from './module' - CommonJS:
const x = require('./module') - Re-exports:
export { x } from './module'
How it works:
- Regex-based parsing extracts import paths from each file
- Relative paths are resolved to normalized file paths
- Bidirectional edges are created (imports and importedBy)
- The graph supports BFS traversal for transitive dependency lookup
Parses the output of git diff --name-status:
Input:
M src/services/auth.ts
A src/services/oauth.ts
D src/legacy/old-auth.ts
R100 src/utils/old.ts src/utils/new.ts
Output:
{
"added": ["src/services/oauth.ts", "src/utils/new.ts"],
"modified": ["src/services/auth.ts"],
"deleted": ["src/legacy/old-auth.ts"],
"all": ["src/services/oauth.ts", "src/utils/new.ts", "src/services/auth.ts", "src/legacy/old-auth.ts"]
}Given a codebase with 200 test files, here is a typical scenario:
Changed Files: 3 (src/auth/token.ts, src/auth/validate.ts, src/utils/crypto.ts)
Total Tests: 200
Affected Tests: 12
Reduction: 94%
Execution Plan:
--testPathPattern="tests/auth/token.test.ts"
--testPathPattern="tests/auth/validate.test.ts"
--testPathPattern="tests/auth/integration.test.ts"
... (9 more)
Instead of running all 200 tests, you run only 12 - saving 94% of CI time.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health | Service health check |
{
"status": "healthy",
"service": "test-impact-analyzer",
"version": "1.0.0",
"uptime": 123.456,
"timestamp": "2026-01-15T10:30:00.000Z"
}| Variable | Default | Description |
|---|---|---|
| PORT | 3007 | Server port |
| NODE_ENV | development | Environment (development/production) |
| LOG_LEVEL | info | Winston log level |
The GitHub Actions pipeline runs on every push and PR to main, master, and develop:
- Lint and Type Check - ESLint + TypeScript compiler validation
- Unit Tests - Jest with coverage reporting
- Docker Build - Multi-stage build + health check verification
# Build the image
docker build -t test-impact-analyzer .
# Run the container
docker run -p 3007:3007 test-impact-analyzer
# Or use docker-compose
docker-compose upDarrius Jones
- GitHub: @Djones-qa
- LinkedIn: darrius-jones-28226b350
MIT - 2026 Darrius Jones
See LICENSE for details.